annotate src/share/vm/memory/sharedHeap.hpp @ 4095:bca17e38de00

6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads Summary: Select number of GC threads dynamically based on heap usage and number of Java threads Reviewed-by: johnc, ysr, jcoomes
author jmasa
date Tue, 09 Aug 2011 10:16:01 -0700
parents 1f4413413144
children 441e946dc1af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1833
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
25 #ifndef SHARE_VM_MEMORY_SHAREDHEAP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
26 #define SHARE_VM_MEMORY_SHAREDHEAP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
28 #include "gc_interface/collectedHeap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
29 #include "memory/generation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
30 #include "memory/permGen.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
31
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // A "SharedHeap" is an implementation of a java heap for HotSpot. This
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // is an abstract class: there may be many different kinds of heaps. This
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // class defines the functions that a heap must implement, and contains
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // infrastructure common to all heaps.
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class PermGen;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 class Generation;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 class BarrierSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 class GenRemSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class Space;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class SpaceClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class OopClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 class OopsInGenClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 class ObjectClosure;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 class SubTasksDone;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 class WorkGang;
1833
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1552
diff changeset
48 class FlexibleWorkGang;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 class CollectorPolicy;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 class KlassHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
51
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
52 // Note on use of FlexibleWorkGang's for GC.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
53 // There are three places where task completion is determined.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
54 // In
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
55 // 1) ParallelTaskTerminator::offer_termination() where _n_threads
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
56 // 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
57 // have offered termination will exactly match the number
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
58 // 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
59 // use ParallelTaskTerminator's. Tasks that want load balancing
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
60 // by work stealing use this method to gauge completion.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
61 // 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
62 // all_tasks_completed() to determine completion. all_tasks_complete()
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
63 // 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
64 // 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
65 // tasks is set to the number of GC workers, then _n_threads must
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
66 // be set to the number of active GC workers. G1CollectedHeap,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
67 // HRInto_G1RemSet, GenCollectedHeap and SharedHeap have SubTasksDone.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
68 // This seems too many.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
69 // 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
70 // 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
71 // number of active GC workers. CompactibleFreeListSpace and Space
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
72 // have SequentialSubTasksDone's.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
73 // Example of using SubTasksDone and SequentialSubTasksDone
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
74 // G1CollectedHeap::g1_process_strong_roots() calls
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
75 // process_strong_roots(false, // no scoping; this is parallel code
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
76 // collecting_perm_gen, so,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
77 // &buf_scan_non_heap_roots,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
78 // &eager_scan_code_roots,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
79 // &buf_scan_perm);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
80 // which delegates to SharedHeap::process_strong_roots() and uses
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
81 // SubTasksDone* _process_strong_tasks to claim tasks.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
82 // process_strong_roots() calls
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
83 // rem_set()->younger_refs_iterate(perm_gen(), perm_blk);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
84 // 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
85 // CardTableModRefBS::par_non_clean_card_iterate_work(). This method
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
86 // uses SequentialSubTasksDone* _pst to claim tasks.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
87 // Both SubTasksDone and SequentialSubTasksDone call their method
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
88 // 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
89 // 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
90 // finished the tasks are finished".
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
91 //
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
92 // 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
93 // 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
94 // 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
95 // 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
96 // setting _n_threads to 1.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
97 //
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
98 // 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
99 // 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
100 // 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
101 // examples.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
102 //
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
103 // 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
104 // 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
105 // (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
106 // on the partitioning done in the previous parallel scavenge).
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
107
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 class SharedHeap : public CollectedHeap {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
110
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
111 friend class VM_GC_Operation;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
112 friend class VM_CGC_Operation;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
113
0
a61af66fc99e Initial load
duke
parents:
diff changeset
114 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // For claiming strong_roots tasks.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 SubTasksDone* _process_strong_tasks;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // There should be only a single instance of "SharedHeap" in a program.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // This is enforced with the protected constructor below, which will also
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // set the static pointer "_sh" to that instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 static SharedHeap* _sh;
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // All heaps contain a "permanent generation." This is some ways
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // similar to a generation in a generational system, in other ways not.
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // See the "PermGen" class.
a61af66fc99e Initial load
duke
parents:
diff changeset
127 PermGen* _perm_gen;
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // and the Gen Remembered Set, at least one good enough to scan the perm
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // gen.
a61af66fc99e Initial load
duke
parents:
diff changeset
131 GenRemSet* _rem_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // A gc policy, controls global gc resource issues
a61af66fc99e Initial load
duke
parents:
diff changeset
134 CollectorPolicy *_collector_policy;
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // See the discussion below, in the specification of the reader function
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // for this variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 int _strong_roots_parity;
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // 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
141 FlexibleWorkGang* _workers;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Full initialization is done in a concrete subtype's "initialize"
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // function.
a61af66fc99e Initial load
duke
parents:
diff changeset
145 SharedHeap(CollectorPolicy* policy_);
a61af66fc99e Initial load
duke
parents:
diff changeset
146
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
147 // Returns true if the calling thread holds the heap lock,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
148 // or the calling thread is a par gc thread and the heap_lock is held
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
149 // by the vm thread doing a gc operation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
150 bool heap_lock_held_for_gc();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
151 // True if the heap_lock is held by the a non-gc thread invoking a gc
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
152 // operation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
153 bool _thread_holds_heap_lock_for_gc;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
154
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
156 static SharedHeap* heap() { return _sh; }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 CollectorPolicy *collector_policy() const { return _collector_policy; }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 void set_barrier_set(BarrierSet* bs);
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
161 SubTasksDone* process_strong_tasks() { return _process_strong_tasks; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Does operations required after initialization has been done.
a61af66fc99e Initial load
duke
parents:
diff changeset
164 virtual void post_initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Initialization of ("weak") reference processing support
a61af66fc99e Initial load
duke
parents:
diff changeset
167 virtual void ref_processing_init();
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 void set_perm(PermGen* perm_gen) { _perm_gen = perm_gen; }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // This function returns the "GenRemSet" object that allows us to scan
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // generations; at least the perm gen, possibly more in a fully
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // generational heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 GenRemSet* rem_set() { return _rem_set; }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // These function return the "permanent" generation, in which
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // reflective objects are allocated and stored. Two versions, the second
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // of which returns the view of the perm gen as a generation.
a61af66fc99e Initial load
duke
parents:
diff changeset
179 PermGen* perm() const { return _perm_gen; }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 Generation* perm_gen() const { return _perm_gen->as_gen(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // Iteration functions.
a61af66fc99e Initial load
duke
parents:
diff changeset
183 void oop_iterate(OopClosure* cl) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // Same as above, restricted to a memory region.
a61af66fc99e Initial load
duke
parents:
diff changeset
186 virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Iterate over all objects allocated since the last collection, calling
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // "cl->do_object" on each. The heap must have been initialized properly
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // to support this function, or else this call will fail.
a61af66fc99e Initial load
duke
parents:
diff changeset
191 virtual void object_iterate_since_last_GC(ObjectClosure* cl) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // Iterate over all spaces in use in the heap, in an undefined order.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 virtual void space_iterate(SpaceClosure* cl) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // A SharedHeap will contain some number of spaces. This finds the
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // space whose reserved area contains the given address, or else returns
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
199 virtual Space* space_containing(const void* addr) const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 bool no_gc_in_progress() { return !is_gc_active(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Some collectors will perform "process_strong_roots" in parallel.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // Such a call will involve claiming some fine-grained tasks, such as
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // scanning of threads. To make this process simpler, we provide the
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // "strong_roots_parity()" method. Collectors that start parallel tasks
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // whose threads invoke "process_strong_roots" must
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // call "change_strong_roots_parity" in sequential code starting such a
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // task. (This also means that a parallel thread may only call
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // process_strong_roots once.)
a61af66fc99e Initial load
duke
parents:
diff changeset
211 //
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // For calls to process_strong_roots by sequential code, the parity is
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // updated automatically.
a61af66fc99e Initial load
duke
parents:
diff changeset
214 //
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // The idea is that objects representing fine-grained tasks, such as
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // threads, will contain a "parity" field. A task will is claimed in the
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // current "process_strong_roots" call only if its parity field is the
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // same as the "strong_roots_parity"; task claiming is accomplished by
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // updating the parity field to the strong_roots_parity with a CAS.
a61af66fc99e Initial load
duke
parents:
diff changeset
220 //
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // If the client meats this spec, then strong_roots_parity() will have
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // the following properties:
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // a) to return a different value than was returned before the last
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // call to change_strong_roots_parity, and
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // c) to never return a distinguished value (zero) with which such
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // task-claiming variables may be initialized, to indicate "never
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // claimed".
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
228 private:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
229 void change_strong_roots_parity();
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
230 public:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
231 int strong_roots_parity() { return _strong_roots_parity; }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
233 // Call these in sequential code around process_strong_roots.
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
234 // 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
235 // parallel tasks are enabled.
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
236 class StrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
237 public:
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
238 StrongRootsScope(SharedHeap* outer, bool activate = true);
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
239 ~StrongRootsScope();
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
240 };
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
241 friend class StrongRootsScope;
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
242
0
a61af66fc99e Initial load
duke
parents:
diff changeset
243 enum ScanningOption {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 SO_None = 0x0,
a61af66fc99e Initial load
duke
parents:
diff changeset
245 SO_AllClasses = 0x1,
a61af66fc99e Initial load
duke
parents:
diff changeset
246 SO_SystemClasses = 0x2,
3293
1f4413413144 7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents: 1972
diff changeset
247 SO_Strings = 0x4,
1f4413413144 7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents: 1972
diff changeset
248 SO_CodeCache = 0x8
0
a61af66fc99e Initial load
duke
parents:
diff changeset
249 };
a61af66fc99e Initial load
duke
parents:
diff changeset
250
1833
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1552
diff changeset
251 FlexibleWorkGang* workers() const { return _workers; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // Invoke the "do_oop" method the closure "roots" on all root locations.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // If "collecting_perm_gen" is false, then roots that may only contain
3293
1f4413413144 7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents: 1972
diff changeset
255 // references to permGen objects are not scanned; instead, in that case,
1f4413413144 7039089: G1: changeset for 7037276 broke heap verification, and related cleanups
ysr
parents: 1972
diff changeset
256 // the "perm_blk" closure is applied to all outgoing refs in the
0
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // permanent generation. The "so" argument determines which of roots
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // the closure is applied to:
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // "SO_None" does none;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // "SO_AllClasses" applies the closure to all entries in the SystemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // "SO_SystemClasses" to all the "system" classes and loaders;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // "SO_Strings" applies the closure to all entries in StringTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // "SO_CodeCache" applies the closure to all elements of the CodeCache.
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
264 void process_strong_roots(bool activate_scope,
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
265 bool collecting_perm_gen,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
266 ScanningOption so,
a61af66fc99e Initial load
duke
parents:
diff changeset
267 OopClosure* roots,
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
268 CodeBlobClosure* code_roots,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
269 OopsInGenClosure* perm_blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Apply "blk" to all the weak roots of the system. These include
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // JNI weak roots, the code cache, system dictionary, symbol table,
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // string table.
a61af66fc99e Initial load
duke
parents:
diff changeset
274 void process_weak_roots(OopClosure* root_closure,
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 579
diff changeset
275 CodeBlobClosure* code_roots,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
276 OopClosure* non_root_closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // The functions below are helper functions that a subclass of
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // "SharedHeap" can use in the implementation of its virtual
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // functions.
a61af66fc99e Initial load
duke
parents:
diff changeset
281
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
282 public:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // Do anything common to GC's.
a61af66fc99e Initial load
duke
parents:
diff changeset
285 virtual void gc_prologue(bool full) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 virtual void gc_epilogue(bool full) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
287
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
288 // Sets the number of parallel threads that will be doing tasks
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
289 // (such as process strong roots) subsequently.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
290 virtual void set_par_threads(int t);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
291
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
292 int n_termination();
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
293 void set_n_termination(int t);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 3293
diff changeset
294
0
a61af66fc99e Initial load
duke
parents:
diff changeset
295 //
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // New methods from CollectedHeap
a61af66fc99e Initial load
duke
parents:
diff changeset
297 //
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 size_t permanent_capacity() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return perm_gen()->capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 size_t permanent_used() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return perm_gen()->used();
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 bool is_in_permanent(const void *p) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
311 return perm_gen()->is_in_reserved(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // Different from is_in_permanent in that is_in_permanent
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // only checks if p is in the reserved area of the heap
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // and this checks to see if it in the commited area.
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // This is typically used by things like the forte stackwalker
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // during verification of suspicious frame values.
a61af66fc99e Initial load
duke
parents:
diff changeset
319 bool is_permanent(const void *p) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
321 return perm_gen()->is_in(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 HeapWord* permanent_mem_allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
326 return _perm_gen->mem_allocate(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 void permanent_oop_iterate(OopClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
331 _perm_gen->oop_iterate(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 void permanent_object_iterate(ObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 assert(perm_gen(), "NULL perm gen");
a61af66fc99e Initial load
duke
parents:
diff changeset
336 _perm_gen->object_iterate(cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // Some utilities.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
340 void print_size_transition(outputStream* out,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
341 size_t bytes_before,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
342 size_t bytes_after,
a61af66fc99e Initial load
duke
parents:
diff changeset
343 size_t capacity);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
345
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
346 #endif // SHARE_VM_MEMORY_SHAREDHEAP_HPP