Mercurial > hg > graal-jvmci-8
annotate src/share/vm/memory/sharedHeap.hpp @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | dd9cc155639c |
children |
rev | line source |
---|---|
0 | 1 /* |
14223
de6a9e811145
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
11096
diff
changeset
|
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1088
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1088
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1088
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 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 | |
0 | 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; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
46 class FlexibleWorkGang; |
0 | 47 class CollectorPolicy; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4728
diff
changeset
|
48 class KlassClosure; |
0 | 49 |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
50 // Note on use of FlexibleWorkGang's for GC. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
51 // There are three places where task completion is determined. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
52 // In |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
53 // 1) ParallelTaskTerminator::offer_termination() where _n_threads |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
54 // must be set to the correct value so that count of workers that |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
55 // have offered termination will exactly match the number |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
56 // working on the task. Tasks such as those derived from GCTask |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
57 // use ParallelTaskTerminator's. Tasks that want load balancing |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
58 // by work stealing use this method to gauge completion. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
59 // 2) SubTasksDone has a variable _n_threads that is used in |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
60 // all_tasks_completed() to determine completion. all_tasks_complete() |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
61 // counts the number of tasks that have been done and then reset |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
62 // the SubTasksDone so that it can be used again. When the number of |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
63 // tasks is set to the number of GC workers, then _n_threads must |
22909
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
64 // be set to the number of active GC workers. G1RootProcessor and |
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
65 // GenCollectedHeap have SubTasksDone. |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
66 // 3) SequentialSubTasksDone has an _n_threads that is used in |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
67 // a way similar to SubTasksDone and has the same dependency on the |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
68 // number of active GC workers. CompactibleFreeListSpace and Space |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
69 // have SequentialSubTasksDone's. |
22909
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
70 // |
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
71 // Examples of using SubTasksDone and SequentialSubTasksDone: |
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
72 // G1RootProcessor and GenCollectedHeap::process_roots() use |
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
73 // SubTasksDone* _process_strong_tasks to claim tasks for workers |
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
74 // |
38d6febe66af
8075210: Refactor strong root processing in order to allow G1 to evolve separately from GenCollectedHeap
mgerdin
parents:
20278
diff
changeset
|
75 // GenCollectedHeap::gen_process_roots() calls |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4728
diff
changeset
|
76 // rem_set()->younger_refs_iterate() |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
77 // to scan the card table and which eventually calls down into |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
78 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
79 // uses SequentialSubTasksDone* _pst to claim tasks. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
80 // Both SubTasksDone and SequentialSubTasksDone call their method |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
81 // all_tasks_completed() to count the number of GC workers that have |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
82 // finished their work. That logic is "when all the workers are |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
83 // finished the tasks are finished". |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
84 // |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
85 // The pattern that appears in the code is to set _n_threads |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
86 // to a value > 1 before a task that you would like executed in parallel |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
87 // and then to set it to 0 after that task has completed. A value of |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
88 // 0 is a "special" value in set_n_threads() which translates to |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
89 // setting _n_threads to 1. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
90 // |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
91 // Some code uses _n_terminiation to decide if work should be done in |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
92 // parallel. The notorious possibly_parallel_oops_do() in threads.cpp |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
93 // is an example of such code. Look for variable "is_par" for other |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
94 // examples. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
95 // |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
96 // The active_workers is not reset to 0 after a parallel phase. It's |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
97 // value may be used in later phases and in one instance at least |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
98 // (the parallel remark) it has to be used (the parallel remark depends |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
99 // on the partitioning done in the previous parallel scavenge). |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
100 |
0 | 101 class SharedHeap : public CollectedHeap { |
102 friend class VMStructs; | |
103 | |
342 | 104 friend class VM_GC_Operation; |
105 friend class VM_CGC_Operation; | |
106 | |
0 | 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 // and the Gen Remembered Set, at least one good enough to scan the perm | |
114 // gen. | |
115 GenRemSet* _rem_set; | |
116 | |
117 // A gc policy, controls global gc resource issues | |
118 CollectorPolicy *_collector_policy; | |
119 | |
120 // See the discussion below, in the specification of the reader function | |
121 // for this variable. | |
122 int _strong_roots_parity; | |
123 | |
124 // If we're doing parallel GC, use this gang of threads. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
125 FlexibleWorkGang* _workers; |
0 | 126 |
127 // Full initialization is done in a concrete subtype's "initialize" | |
128 // function. | |
129 SharedHeap(CollectorPolicy* policy_); | |
130 | |
342 | 131 // Returns true if the calling thread holds the heap lock, |
132 // or the calling thread is a par gc thread and the heap_lock is held | |
133 // by the vm thread doing a gc operation. | |
134 bool heap_lock_held_for_gc(); | |
135 // True if the heap_lock is held by the a non-gc thread invoking a gc | |
136 // operation. | |
137 bool _thread_holds_heap_lock_for_gc; | |
138 | |
0 | 139 public: |
140 static SharedHeap* heap() { return _sh; } | |
141 | |
142 void set_barrier_set(BarrierSet* bs); | |
143 | |
144 // Does operations required after initialization has been done. | |
145 virtual void post_initialize(); | |
146 | |
147 // Initialization of ("weak") reference processing support | |
148 virtual void ref_processing_init(); | |
149 | |
150 // This function returns the "GenRemSet" object that allows us to scan | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4728
diff
changeset
|
151 // generations in a fully generational heap. |
0 | 152 GenRemSet* rem_set() { return _rem_set; } |
153 | |
154 // Iteration functions. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4728
diff
changeset
|
155 void oop_iterate(ExtendedOopClosure* cl) = 0; |
0 | 156 |
157 // Iterate over all spaces in use in the heap, in an undefined order. | |
158 virtual void space_iterate(SpaceClosure* cl) = 0; | |
159 | |
160 // A SharedHeap will contain some number of spaces. This finds the | |
161 // space whose reserved area contains the given address, or else returns | |
162 // NULL. | |
163 virtual Space* space_containing(const void* addr) const = 0; | |
164 | |
165 bool no_gc_in_progress() { return !is_gc_active(); } | |
166 | |
167 // Some collectors will perform "process_strong_roots" in parallel. | |
168 // Such a call will involve claiming some fine-grained tasks, such as | |
169 // scanning of threads. To make this process simpler, we provide the | |
170 // "strong_roots_parity()" method. Collectors that start parallel tasks | |
171 // whose threads invoke "process_strong_roots" must | |
172 // call "change_strong_roots_parity" in sequential code starting such a | |
173 // task. (This also means that a parallel thread may only call | |
174 // process_strong_roots once.) | |
175 // | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
176 // For calls to process_roots by sequential code, the parity is |
0 | 177 // updated automatically. |
178 // | |
179 // The idea is that objects representing fine-grained tasks, such as | |
180 // threads, will contain a "parity" field. A task will is claimed in the | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
181 // current "process_roots" call only if its parity field is the |
0 | 182 // same as the "strong_roots_parity"; task claiming is accomplished by |
183 // updating the parity field to the strong_roots_parity with a CAS. | |
184 // | |
185 // If the client meats this spec, then strong_roots_parity() will have | |
186 // the following properties: | |
187 // a) to return a different value than was returned before the last | |
188 // call to change_strong_roots_parity, and | |
189 // c) to never return a distinguished value (zero) with which such | |
190 // task-claiming variables may be initialized, to indicate "never | |
191 // claimed". | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
192 public: |
0 | 193 int strong_roots_parity() { return _strong_roots_parity; } |
194 | |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
195 // Call these in sequential code around process_roots. |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
196 // strong_roots_prologue calls change_strong_roots_parity, if |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
197 // parallel tasks are enabled. |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
198 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope { |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
199 SharedHeap* _sh; |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
200 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
201 public: |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
202 StrongRootsScope(SharedHeap* heap, bool activate = true); |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
203 }; |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
204 friend class StrongRootsScope; |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
579
diff
changeset
|
205 |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
206 private: |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
207 void change_strong_roots_parity(); |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
208 |
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
209 public: |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
210 FlexibleWorkGang* workers() const { return _workers; } |
0 | 211 |
212 // The functions below are helper functions that a subclass of | |
213 // "SharedHeap" can use in the implementation of its virtual | |
214 // functions. | |
215 | |
342 | 216 public: |
0 | 217 |
218 // Do anything common to GC's. | |
219 virtual void gc_prologue(bool full) = 0; | |
220 virtual void gc_epilogue(bool full) = 0; | |
221 | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
222 // Sets the number of parallel threads that will be doing tasks |
20278
2c6ef90f030a
8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents:
20264
diff
changeset
|
223 // (such as process roots) subsequently. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
224 virtual void set_par_threads(uint t); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
3293
diff
changeset
|
225 |
0 | 226 // |
227 // New methods from CollectedHeap | |
228 // | |
229 | |
230 // Some utilities. | |
342 | 231 void print_size_transition(outputStream* out, |
232 size_t bytes_before, | |
0 | 233 size_t bytes_after, |
234 size_t capacity); | |
235 }; | |
1972 | 236 |
237 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP |