author | stefank |
Thu, 22 Feb 2018 18:36:07 +0100 | |
changeset 49047 | 8f004146e407 |
parent 47216 | 71c04702a3d5 |
child 49392 | 2956d0ece7a9 |
permissions | -rw-r--r-- |
46384
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
1 |
/* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
4 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
8 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
13 |
* accompanied this code). |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
14 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
18 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
21 |
* questions. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
22 |
* |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
23 |
*/ |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
24 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
25 |
#ifndef SHARE_VM_GC_CONCURRENTGCPHASEMANAGER_HPP |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
26 |
#define SHARE_VM_GC_CONCURRENTGCPHASEMANAGER_HPP |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
27 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
29 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
30 |
// Manage concurrent phase information, to support WhiteBox testing. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
31 |
// Managers are stack allocated. Managers may be nested, to support |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
32 |
// nested subphases. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
33 |
class ConcurrentGCPhaseManager : public StackObj { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
34 |
public: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
35 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
36 |
// Special phase ids used by all GC's that use this facility. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
37 |
static const int UNCONSTRAINED_PHASE = 0; // Unconstrained or no request. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
38 |
static const int IDLE_PHASE = 1; // Concurrent processing is idle. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
39 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
40 |
// Stack of phase managers. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
41 |
class Stack VALUE_OBJ_CLASS_SPEC { |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
42 |
friend class ConcurrentGCPhaseManager; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
43 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
44 |
public: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
45 |
// Create an empty stack of phase managers. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
46 |
Stack(); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
47 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
48 |
private: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
49 |
int _requested_phase; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
50 |
ConcurrentGCPhaseManager* _top; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
51 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
52 |
// Non-copyable - never defined. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
53 |
Stack(const Stack&); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
54 |
Stack& operator=(const Stack&); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
55 |
}; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
56 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
57 |
// Construct and push a new manager on the stack, activating phase. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
58 |
// Notifies callers in wait_for_phase of the phase change. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
59 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
60 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
61 |
// - Calling thread must be a ConcurrentGC thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
62 |
// - phase != UNCONSTRAINED_PHASE |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
63 |
// - stack != NULL |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
64 |
// - other managers on stack must all be active. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
65 |
ConcurrentGCPhaseManager(int phase, Stack* stack); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
66 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
67 |
// Pop this manager off the stack, deactivating phase. Before |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
68 |
// changing phases, if is_requested() is true, wait until the |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
69 |
// request is changed. After changing phases, notifies callers of |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
70 |
// wait_for_phase of the phase change. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
71 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
72 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
73 |
// - Calling thread must be a ConcurrentGC thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
74 |
// - this must be the current top of the manager stack |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
75 |
~ConcurrentGCPhaseManager(); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
76 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
77 |
// Returns true if this phase is active and is currently requested. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
78 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
79 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
80 |
// - Calling thread must be a ConcurrentGC thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
81 |
// - this must be the current top of manager stack |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
82 |
bool is_requested() const; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
83 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
84 |
// Wait until is_requested() is false. Returns true if waited. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
85 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
86 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
87 |
// - Calling thread must be a ConcurrentGC thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
88 |
// - this must be the current top of manager stack |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
89 |
bool wait_when_requested() const; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
90 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
91 |
// Directly step from one phase to another, without needing to pop a |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
92 |
// manager from the stack and allocate a new one. Before changing |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
93 |
// phases, if is_requested() is true and force is false, wait until |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
94 |
// the request is changed. After changing phases, notifies callers |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
95 |
// of wait_for_phase of the phase change. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
96 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
97 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
98 |
// - Calling thread must be a ConcurrentGC thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
99 |
// - phase != UNCONSTRAINED_PHASE |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
100 |
// - this must be the current top of manager stack |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
101 |
void set_phase(int phase, bool force); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
102 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
103 |
// Deactivate the manager. An inactive manager no longer blocks |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
104 |
// transitions out of the associated phase when that phase has been |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
105 |
// requested. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
106 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
107 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
108 |
// - Calling thread must be a ConcurrentGC thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
109 |
// - this must be the current top of manager stack |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
110 |
void deactivate(); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
111 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
112 |
// Used to implement CollectorPolicy::request_concurrent_phase(). |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
113 |
// Updates request to the new phase, and notifies threads blocked on |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
114 |
// the old request of the change. Returns true if the phase is |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
115 |
// UNCONSTRAINED_PHASE. Otherwise, waits until an active phase is |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
116 |
// the requested phase (returning true) or IDLE_PHASE (returning |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
117 |
// false if not also the requested phase). |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
118 |
// |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
119 |
// Preconditions: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
120 |
// - Calling thread must be a Java thread |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
121 |
// - stack must be non-NULL |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
122 |
static bool wait_for_phase(int phase, Stack* stack); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
123 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
124 |
private: |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
125 |
int _phase; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
126 |
bool _active; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
127 |
ConcurrentGCPhaseManager* _prev; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
128 |
Stack* _stack; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
129 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
130 |
// Non-copyable - never defined. |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
131 |
ConcurrentGCPhaseManager(const ConcurrentGCPhaseManager&); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
132 |
ConcurrentGCPhaseManager& operator=(const ConcurrentGCPhaseManager&); |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
133 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
134 |
bool wait_when_requested_impl() const; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
135 |
}; |
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
136 |
|
dacebddcdea0
8169517: WhiteBox should provide concurrent GC phase control
kbarrett
parents:
diff
changeset
|
137 |
#endif // include guard |