author | brutisso |
Tue, 31 Mar 2015 11:27:20 +0200 | |
changeset 29804 | dcb9861190d2 |
parent 29802 | d485440c958a |
child 30147 | af9a41999c6e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29804
dcb9861190d2
8076237: Remove unused _collector_policy field in SharedHeap
brutisso
parents:
29802
diff
changeset
|
2 |
* Copyright (c) 2000, 2015, 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:
4458
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4458
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:
4458
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_MEMORY_SHAREDHEAP_HPP |
26 |
#define SHARE_VM_MEMORY_SHAREDHEAP_HPP |
|
27 |
||
28 |
#include "gc_interface/collectedHeap.hpp" |
|
29 |
#include "memory/generation.hpp" |
|
30 |
||
1 | 31 |
// A "SharedHeap" is an implementation of a java heap for HotSpot. This |
32 |
// is an abstract class: there may be many different kinds of heaps. This |
|
33 |
// class defines the functions that a heap must implement, and contains |
|
34 |
// infrastructure common to all heaps. |
|
35 |
||
36 |
class Generation; |
|
37 |
class BarrierSet; |
|
38 |
class GenRemSet; |
|
39 |
class Space; |
|
40 |
class SpaceClosure; |
|
41 |
class OopClosure; |
|
42 |
class OopsInGenClosure; |
|
43 |
class ObjectClosure; |
|
44 |
class SubTasksDone; |
|
45 |
class WorkGang; |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
46 |
class FlexibleWorkGang; |
1 | 47 |
class CollectorPolicy; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11396
diff
changeset
|
48 |
class KlassClosure; |
1 | 49 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
50 |
// Note on use of FlexibleWorkGang's for GC. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
51 |
// There are three places where task completion is determined. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
52 |
// In |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
53 |
// 1) ParallelTaskTerminator::offer_termination() where _n_threads |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
54 |
// must be set to the correct value so that count of workers that |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
55 |
// have offered termination will exactly match the number |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
56 |
// working on the task. Tasks such as those derived from GCTask |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
57 |
// use ParallelTaskTerminator's. Tasks that want load balancing |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
58 |
// by work stealing use this method to gauge completion. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
59 |
// 2) SubTasksDone has a variable _n_threads that is used in |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
60 |
// all_tasks_completed() to determine completion. all_tasks_complete() |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
61 |
// counts the number of tasks that have been done and then reset |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
62 |
// the SubTasksDone so that it can be used again. When the number of |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
63 |
// tasks is set to the number of GC workers, then _n_threads must |
29693
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
64 |
// be set to the number of active GC workers. G1RootProcessor and |
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
65 |
// GenCollectedHeap have SubTasksDone. |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
66 |
// 3) SequentialSubTasksDone has an _n_threads that is used in |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
67 |
// a way similar to SubTasksDone and has the same dependency on the |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
68 |
// number of active GC workers. CompactibleFreeListSpace and Space |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
69 |
// have SequentialSubTasksDone's. |
29693
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
70 |
// |
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
71 |
// Examples of using SubTasksDone and SequentialSubTasksDone: |
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
72 |
// G1RootProcessor and GenCollectedHeap::process_roots() use |
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
73 |
// SubTasksDone* _process_strong_tasks to claim tasks for workers |
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
74 |
// |
fac175f7a466
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
28217
diff
changeset
|
75 |
// GenCollectedHeap::gen_process_roots() calls |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11396
diff
changeset
|
76 |
// rem_set()->younger_refs_iterate() |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
77 |
// to scan the card table and which eventually calls down into |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
78 |
// CardTableModRefBS::par_non_clean_card_iterate_work(). This method |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
79 |
// uses SequentialSubTasksDone* _pst to claim tasks. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
80 |
// Both SubTasksDone and SequentialSubTasksDone call their method |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
81 |
// all_tasks_completed() to count the number of GC workers that have |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
82 |
// finished their work. That logic is "when all the workers are |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
83 |
// finished the tasks are finished". |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
84 |
// |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
85 |
// The pattern that appears in the code is to set _n_threads |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
86 |
// to a value > 1 before a task that you would like executed in parallel |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
87 |
// and then to set it to 0 after that task has completed. A value of |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
88 |
// 0 is a "special" value in set_n_threads() which translates to |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
89 |
// setting _n_threads to 1. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
90 |
// |
22551 | 91 |
// Some code uses _n_termination to decide if work should be done in |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
92 |
// parallel. The notorious possibly_parallel_oops_do() in threads.cpp |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
93 |
// is an example of such code. Look for variable "is_par" for other |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
94 |
// examples. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
95 |
// |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
96 |
// The active_workers is not reset to 0 after a parallel phase. It's |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
97 |
// value may be used in later phases and in one instance at least |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
98 |
// (the parallel remark) it has to be used (the parallel remark depends |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
99 |
// on the partitioning done in the previous parallel scavenge). |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
100 |
|
1 | 101 |
class SharedHeap : public CollectedHeap { |
102 |
friend class VMStructs; |
|
103 |
||
1374 | 104 |
friend class VM_GC_Operation; |
105 |
friend class VM_CGC_Operation; |
|
106 |
||
1 | 107 |
protected: |
108 |
// There should be only a single instance of "SharedHeap" in a program. |
|
109 |
// This is enforced with the protected constructor below, which will also |
|
110 |
// set the static pointer "_sh" to that instance. |
|
111 |
static SharedHeap* _sh; |
|
112 |
||
113 |
// If we're doing parallel GC, use this gang of threads. |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
114 |
FlexibleWorkGang* _workers; |
1 | 115 |
|
116 |
// Full initialization is done in a concrete subtype's "initialize" |
|
117 |
// function. |
|
29804
dcb9861190d2
8076237: Remove unused _collector_policy field in SharedHeap
brutisso
parents:
29802
diff
changeset
|
118 |
SharedHeap(); |
1 | 119 |
|
1374 | 120 |
// Returns true if the calling thread holds the heap lock, |
121 |
// or the calling thread is a par gc thread and the heap_lock is held |
|
122 |
// by the vm thread doing a gc operation. |
|
123 |
bool heap_lock_held_for_gc(); |
|
124 |
// True if the heap_lock is held by the a non-gc thread invoking a gc |
|
125 |
// operation. |
|
126 |
bool _thread_holds_heap_lock_for_gc; |
|
127 |
||
1 | 128 |
public: |
129 |
static SharedHeap* heap() { return _sh; } |
|
130 |
||
131 |
void set_barrier_set(BarrierSet* bs); |
|
132 |
||
133 |
// Does operations required after initialization has been done. |
|
134 |
virtual void post_initialize(); |
|
135 |
||
136 |
// Initialization of ("weak") reference processing support |
|
137 |
virtual void ref_processing_init(); |
|
138 |
||
139 |
// Iteration functions. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
11396
diff
changeset
|
140 |
void oop_iterate(ExtendedOopClosure* cl) = 0; |
1 | 141 |
|
142 |
// Iterate over all spaces in use in the heap, in an undefined order. |
|
143 |
virtual void space_iterate(SpaceClosure* cl) = 0; |
|
144 |
||
145 |
// A SharedHeap will contain some number of spaces. This finds the |
|
146 |
// space whose reserved area contains the given address, or else returns |
|
147 |
// NULL. |
|
148 |
virtual Space* space_containing(const void* addr) const = 0; |
|
149 |
||
150 |
bool no_gc_in_progress() { return !is_gc_active(); } |
|
151 |
||
29802
d485440c958a
8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents:
29795
diff
changeset
|
152 |
// Note, the below comment needs to be updated to reflect the changes |
d485440c958a
8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents:
29795
diff
changeset
|
153 |
// introduced by JDK-8076225. This should be done as part of JDK-8076289. |
d485440c958a
8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents:
29795
diff
changeset
|
154 |
// |
d485440c958a
8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents:
29795
diff
changeset
|
155 |
//Some collectors will perform "process_strong_roots" in parallel. |
1 | 156 |
// Such a call will involve claiming some fine-grained tasks, such as |
157 |
// scanning of threads. To make this process simpler, we provide the |
|
158 |
// "strong_roots_parity()" method. Collectors that start parallel tasks |
|
159 |
// whose threads invoke "process_strong_roots" must |
|
160 |
// call "change_strong_roots_parity" in sequential code starting such a |
|
161 |
// task. (This also means that a parallel thread may only call |
|
162 |
// process_strong_roots once.) |
|
163 |
// |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
164 |
// For calls to process_roots by sequential code, the parity is |
1 | 165 |
// updated automatically. |
166 |
// |
|
167 |
// The idea is that objects representing fine-grained tasks, such as |
|
168 |
// threads, will contain a "parity" field. A task will is claimed in the |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
169 |
// current "process_roots" call only if its parity field is the |
1 | 170 |
// same as the "strong_roots_parity"; task claiming is accomplished by |
171 |
// updating the parity field to the strong_roots_parity with a CAS. |
|
172 |
// |
|
173 |
// If the client meats this spec, then strong_roots_parity() will have |
|
174 |
// the following properties: |
|
175 |
// a) to return a different value than was returned before the last |
|
176 |
// call to change_strong_roots_parity, and |
|
177 |
// c) to never return a distinguished value (zero) with which such |
|
178 |
// task-claiming variables may be initialized, to indicate "never |
|
179 |
// claimed". |
|
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
2105
diff
changeset
|
180 |
public: |
1 | 181 |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
182 |
// Call these in sequential code around process_roots. |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
2105
diff
changeset
|
183 |
// strong_roots_prologue calls change_strong_roots_parity, if |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
2105
diff
changeset
|
184 |
// parallel tasks are enabled. |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
2105
diff
changeset
|
185 |
class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope { |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
186 |
SharedHeap* _sh; |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
187 |
|
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
188 |
public: |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
189 |
StrongRootsScope(SharedHeap* heap, bool activate = true); |
29802
d485440c958a
8076225: Move the thread claim parity from SharedHeap to Thread
mgerdin
parents:
29795
diff
changeset
|
190 |
~StrongRootsScope(); |
3908
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
2105
diff
changeset
|
191 |
}; |
24b55ad4c228
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
2105
diff
changeset
|
192 |
|
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
193 |
private: |
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
194 |
|
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
195 |
public: |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
196 |
FlexibleWorkGang* workers() const { return _workers; } |
1 | 197 |
|
198 |
// The functions below are helper functions that a subclass of |
|
199 |
// "SharedHeap" can use in the implementation of its virtual |
|
200 |
// functions. |
|
201 |
||
1374 | 202 |
public: |
1 | 203 |
|
204 |
// Do anything common to GC's. |
|
205 |
virtual void gc_prologue(bool full) = 0; |
|
206 |
virtual void gc_epilogue(bool full) = 0; |
|
207 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
9342
diff
changeset
|
208 |
// Sets the number of parallel threads that will be doing tasks |
25492
d27050bdfb04
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
25491
diff
changeset
|
209 |
// (such as process roots) subsequently. |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
210 |
virtual void set_par_threads(uint t); |
1 | 211 |
}; |
7397 | 212 |
|
213 |
#endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP |