1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
97 // value may be used in later phases and in one instance at least
98 // (the parallel remark) it has to be used (the parallel remark depends
99 // on the partitioning done in the previous parallel scavenge).
100
101 class SharedHeap : public CollectedHeap {
102 friend class VMStructs;
103
104 friend class VM_GC_Operation;
105 friend class VM_CGC_Operation;
106
107 private:
108 // For claiming strong_roots tasks.
109 SubTasksDone* _process_strong_tasks;
110
111 protected:
112 // There should be only a single instance of "SharedHeap" in a program.
113 // This is enforced with the protected constructor below, which will also
114 // set the static pointer "_sh" to that instance.
115 static SharedHeap* _sh;
116
117 // and the Gen Remembered Set, at least one good enough to scan the perm
118 // gen.
119 GenRemSet* _rem_set;
120
121 // A gc policy, controls global gc resource issues
122 CollectorPolicy *_collector_policy;
123
124 // See the discussion below, in the specification of the reader function
125 // for this variable.
126 int _strong_roots_parity;
127
128 // If we're doing parallel GC, use this gang of threads.
129 FlexibleWorkGang* _workers;
130
131 // Full initialization is done in a concrete subtype's "initialize"
132 // function.
133 SharedHeap(CollectorPolicy* policy_);
134
135 // Returns true if the calling thread holds the heap lock,
136 // or the calling thread is a par gc thread and the heap_lock is held
137 // by the vm thread doing a gc operation.
138 bool heap_lock_held_for_gc();
139 // True if the heap_lock is held by the a non-gc thread invoking a gc
140 // operation.
141 bool _thread_holds_heap_lock_for_gc;
142
143 public:
144 static SharedHeap* heap() { return _sh; }
145
146 void set_barrier_set(BarrierSet* bs);
147 SubTasksDone* process_strong_tasks() { return _process_strong_tasks; }
148
149 // Does operations required after initialization has been done.
150 virtual void post_initialize();
151
152 // Initialization of ("weak") reference processing support
153 virtual void ref_processing_init();
154
155 // This function returns the "GenRemSet" object that allows us to scan
156 // generations in a fully generational heap.
157 GenRemSet* rem_set() { return _rem_set; }
158
159 // Iteration functions.
160 void oop_iterate(ExtendedOopClosure* cl) = 0;
161
162 // Iterate over all spaces in use in the heap, in an undefined order.
163 virtual void space_iterate(SpaceClosure* cl) = 0;
164
165 // A SharedHeap will contain some number of spaces. This finds the
166 // space whose reserved area contains the given address, or else returns
167 // NULL.
168 virtual Space* space_containing(const void* addr) const = 0;
169
170 bool no_gc_in_progress() { return !is_gc_active(); }
171
172 // Some collectors will perform "process_strong_roots" in parallel.
173 // Such a call will involve claiming some fine-grained tasks, such as
174 // scanning of threads. To make this process simpler, we provide the
175 // "strong_roots_parity()" method. Collectors that start parallel tasks
176 // whose threads invoke "process_strong_roots" must
177 // call "change_strong_roots_parity" in sequential code starting such a
|
1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
97 // value may be used in later phases and in one instance at least
98 // (the parallel remark) it has to be used (the parallel remark depends
99 // on the partitioning done in the previous parallel scavenge).
100
101 class SharedHeap : public CollectedHeap {
102 friend class VMStructs;
103
104 friend class VM_GC_Operation;
105 friend class VM_CGC_Operation;
106
107 private:
108 // For claiming strong_roots tasks.
109 SubTasksDone* _process_strong_tasks;
110
111 protected:
112 // There should be only a single instance of "SharedHeap" in a program.
113 // This is enforced with the protected constructor below, which will also
114 // set the static pointer "_sh" to that instance.
115 static SharedHeap* _sh;
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.
125 FlexibleWorkGang* _workers;
126
127 // Full initialization is done in a concrete subtype's "initialize"
128 // function.
129 SharedHeap(CollectorPolicy* policy_);
130
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
139 public:
140 static SharedHeap* heap() { return _sh; }
141
142 void set_barrier_set(BarrierSet* bs);
143 SubTasksDone* process_strong_tasks() { return _process_strong_tasks; }
144
145 // Does operations required after initialization has been done.
146 virtual void post_initialize();
147
148 // Initialization of ("weak") reference processing support
149 virtual void ref_processing_init();
150
151 // Iteration functions.
152 void oop_iterate(ExtendedOopClosure* cl) = 0;
153
154 // Iterate over all spaces in use in the heap, in an undefined order.
155 virtual void space_iterate(SpaceClosure* cl) = 0;
156
157 // A SharedHeap will contain some number of spaces. This finds the
158 // space whose reserved area contains the given address, or else returns
159 // NULL.
160 virtual Space* space_containing(const void* addr) const = 0;
161
162 bool no_gc_in_progress() { return !is_gc_active(); }
163
164 // Some collectors will perform "process_strong_roots" in parallel.
165 // Such a call will involve claiming some fine-grained tasks, such as
166 // scanning of threads. To make this process simpler, we provide the
167 // "strong_roots_parity()" method. Collectors that start parallel tasks
168 // whose threads invoke "process_strong_roots" must
169 // call "change_strong_roots_parity" in sequential code starting such a
|