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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.hpp"
27 #include "memory/universe.hpp"
28
29 #include "gc/shared/gcArguments.hpp"
30 #include "gc/shared/gcTimer.hpp"
31 #include "gc/shared/gcTraceTime.inline.hpp"
32 #include "gc/shared/locationPrinter.inline.hpp"
33 #include "gc/shared/memAllocator.hpp"
34 #include "gc/shared/plab.hpp"
35 #include "gc/shared/tlab_globals.hpp"
36
37 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
38 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
39 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
40 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
41 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
42 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
43 #include "gc/shenandoah/shenandoahControlThread.hpp"
44 #include "gc/shenandoah/shenandoahFreeSet.hpp"
45 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
46 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
47 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
48 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
49 #include "gc/shenandoah/shenandoahInitLogger.hpp"
50 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
51 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
52 #include "gc/shenandoah/shenandoahMetrics.hpp"
53 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
54 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
176 _soft_max_size = _num_regions * reg_size_bytes;
177
178 _committed = _initial_size;
179
180 size_t heap_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
181 size_t bitmap_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
182 size_t region_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
183
184 //
185 // Reserve and commit memory for heap
186 //
187
188 ReservedHeapSpace heap_rs = Universe::reserve_heap(max_byte_size, heap_alignment);
189 initialize_reserved_region(heap_rs);
190 _heap_region = MemRegion((HeapWord*)heap_rs.base(), heap_rs.size() / HeapWordSize);
191 _heap_region_special = heap_rs.special();
192
193 assert((((size_t) base()) & ShenandoahHeapRegion::region_size_bytes_mask()) == 0,
194 "Misaligned heap: " PTR_FORMAT, p2i(base()));
195
196 #if SHENANDOAH_OPTIMIZED_MARKTASK
197 // The optimized ShenandoahMarkTask takes some bits away from the full object bits.
198 // Fail if we ever attempt to address more than we can.
199 if ((uintptr_t)heap_rs.end() >= ShenandoahMarkTask::max_addressable()) {
200 FormatBuffer<512> buf("Shenandoah reserved [" PTR_FORMAT ", " PTR_FORMAT") for the heap, \n"
201 "but max object address is " PTR_FORMAT ". Try to reduce heap size, or try other \n"
202 "VM options that allocate heap at lower addresses (HeapBaseMinAddress, AllocateHeapAt, etc).",
203 p2i(heap_rs.base()), p2i(heap_rs.end()), ShenandoahMarkTask::max_addressable());
204 vm_exit_during_initialization("Fatal Error", buf);
205 }
206 #endif
207
208 ReservedSpace sh_rs = heap_rs.first_part(max_byte_size);
209 if (!_heap_region_special) {
210 os::commit_memory_or_exit(sh_rs.base(), _initial_size, heap_alignment, false,
211 "Cannot commit heap memory");
212 }
213
214 //
215 // Reserve and commit memory for bitmap(s)
932 // Expand and retry allocation
933 result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype);
934 if (result != NULL) {
935 return result;
936 }
937
938 // Out of memory
939 return NULL;
940 }
941
942 class ShenandoahConcurrentEvacuateRegionObjectClosure : public ObjectClosure {
943 private:
944 ShenandoahHeap* const _heap;
945 Thread* const _thread;
946 public:
947 ShenandoahConcurrentEvacuateRegionObjectClosure(ShenandoahHeap* heap) :
948 _heap(heap), _thread(Thread::current()) {}
949
950 void do_object(oop p) {
951 shenandoah_assert_marked(NULL, p);
952 if (!p->is_forwarded()) {
953 _heap->evacuate_object(p, _thread);
954 }
955 }
956 };
957
958 class ShenandoahEvacuationTask : public WorkerTask {
959 private:
960 ShenandoahHeap* const _sh;
961 ShenandoahCollectionSet* const _cs;
962 bool _concurrent;
963 public:
964 ShenandoahEvacuationTask(ShenandoahHeap* sh,
965 ShenandoahCollectionSet* cs,
966 bool concurrent) :
967 WorkerTask("Shenandoah Evacuation"),
968 _sh(sh),
969 _cs(cs),
970 _concurrent(concurrent)
971 {}
972
1277 * wiped the bitmap in preparation for next marking).
1278 *
1279 * For all those reasons, we implement object iteration as a single marking traversal, reporting
1280 * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1281 * is allowed to report dead objects, but is not required to do so.
1282 */
1283 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1284 // Reset bitmap
1285 if (!prepare_aux_bitmap_for_iteration())
1286 return;
1287
1288 ShenandoahScanObjectStack oop_stack;
1289 ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1290 // Seed the stack with root scan
1291 scan_roots_for_iteration(&oop_stack, &oops);
1292
1293 // Work through the oop stack to traverse heap
1294 while (! oop_stack.is_empty()) {
1295 oop obj = oop_stack.pop();
1296 assert(oopDesc::is_oop(obj), "must be a valid oop");
1297 cl->do_object(obj);
1298 obj->oop_iterate(&oops);
1299 }
1300
1301 assert(oop_stack.is_empty(), "should be empty");
1302 // Reclaim bitmap
1303 reclaim_aux_bitmap_for_iteration();
1304 }
1305
1306 bool ShenandoahHeap::prepare_aux_bitmap_for_iteration() {
1307 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1308
1309 if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1310 log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1311 return false;
1312 }
1313 // Reset bitmap
1314 _aux_bit_map.clear();
1315 return true;
1316 }
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.hpp"
27 #include "memory/universe.hpp"
28
29 #include "gc/shared/gcArguments.hpp"
30 #include "gc/shared/gcTimer.hpp"
31 #include "gc/shared/gcTraceTime.inline.hpp"
32 #include "gc/shared/locationPrinter.inline.hpp"
33 #include "gc/shared/memAllocator.hpp"
34 #include "gc/shared/plab.hpp"
35 #include "gc/shared/slidingForwarding.hpp"
36 #include "gc/shared/tlab_globals.hpp"
37
38 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
39 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
40 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
41 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
42 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
43 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
44 #include "gc/shenandoah/shenandoahControlThread.hpp"
45 #include "gc/shenandoah/shenandoahFreeSet.hpp"
46 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
47 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
48 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
49 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
50 #include "gc/shenandoah/shenandoahInitLogger.hpp"
51 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
52 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
53 #include "gc/shenandoah/shenandoahMetrics.hpp"
54 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
55 #include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
177 _soft_max_size = _num_regions * reg_size_bytes;
178
179 _committed = _initial_size;
180
181 size_t heap_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
182 size_t bitmap_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
183 size_t region_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
184
185 //
186 // Reserve and commit memory for heap
187 //
188
189 ReservedHeapSpace heap_rs = Universe::reserve_heap(max_byte_size, heap_alignment);
190 initialize_reserved_region(heap_rs);
191 _heap_region = MemRegion((HeapWord*)heap_rs.base(), heap_rs.size() / HeapWordSize);
192 _heap_region_special = heap_rs.special();
193
194 assert((((size_t) base()) & ShenandoahHeapRegion::region_size_bytes_mask()) == 0,
195 "Misaligned heap: " PTR_FORMAT, p2i(base()));
196
197 _forwarding = new SlidingForwarding(_heap_region, ShenandoahHeapRegion::region_size_words_shift());
198
199 #if SHENANDOAH_OPTIMIZED_MARKTASK
200 // The optimized ShenandoahMarkTask takes some bits away from the full object bits.
201 // Fail if we ever attempt to address more than we can.
202 if ((uintptr_t)heap_rs.end() >= ShenandoahMarkTask::max_addressable()) {
203 FormatBuffer<512> buf("Shenandoah reserved [" PTR_FORMAT ", " PTR_FORMAT") for the heap, \n"
204 "but max object address is " PTR_FORMAT ". Try to reduce heap size, or try other \n"
205 "VM options that allocate heap at lower addresses (HeapBaseMinAddress, AllocateHeapAt, etc).",
206 p2i(heap_rs.base()), p2i(heap_rs.end()), ShenandoahMarkTask::max_addressable());
207 vm_exit_during_initialization("Fatal Error", buf);
208 }
209 #endif
210
211 ReservedSpace sh_rs = heap_rs.first_part(max_byte_size);
212 if (!_heap_region_special) {
213 os::commit_memory_or_exit(sh_rs.base(), _initial_size, heap_alignment, false,
214 "Cannot commit heap memory");
215 }
216
217 //
218 // Reserve and commit memory for bitmap(s)
935 // Expand and retry allocation
936 result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype);
937 if (result != NULL) {
938 return result;
939 }
940
941 // Out of memory
942 return NULL;
943 }
944
945 class ShenandoahConcurrentEvacuateRegionObjectClosure : public ObjectClosure {
946 private:
947 ShenandoahHeap* const _heap;
948 Thread* const _thread;
949 public:
950 ShenandoahConcurrentEvacuateRegionObjectClosure(ShenandoahHeap* heap) :
951 _heap(heap), _thread(Thread::current()) {}
952
953 void do_object(oop p) {
954 shenandoah_assert_marked(NULL, p);
955 if (!ShenandoahForwarding::is_forwarded(p)) {
956 _heap->evacuate_object(p, _thread);
957 }
958 }
959 };
960
961 class ShenandoahEvacuationTask : public WorkerTask {
962 private:
963 ShenandoahHeap* const _sh;
964 ShenandoahCollectionSet* const _cs;
965 bool _concurrent;
966 public:
967 ShenandoahEvacuationTask(ShenandoahHeap* sh,
968 ShenandoahCollectionSet* cs,
969 bool concurrent) :
970 WorkerTask("Shenandoah Evacuation"),
971 _sh(sh),
972 _cs(cs),
973 _concurrent(concurrent)
974 {}
975
1280 * wiped the bitmap in preparation for next marking).
1281 *
1282 * For all those reasons, we implement object iteration as a single marking traversal, reporting
1283 * objects as we mark+traverse through the heap, starting from GC roots. JVMTI IterateThroughHeap
1284 * is allowed to report dead objects, but is not required to do so.
1285 */
1286 void ShenandoahHeap::object_iterate(ObjectClosure* cl) {
1287 // Reset bitmap
1288 if (!prepare_aux_bitmap_for_iteration())
1289 return;
1290
1291 ShenandoahScanObjectStack oop_stack;
1292 ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
1293 // Seed the stack with root scan
1294 scan_roots_for_iteration(&oop_stack, &oops);
1295
1296 // Work through the oop stack to traverse heap
1297 while (! oop_stack.is_empty()) {
1298 oop obj = oop_stack.pop();
1299 assert(oopDesc::is_oop(obj), "must be a valid oop");
1300 shenandoah_assert_not_in_cset_except(NULL, obj, cancelled_gc());
1301 cl->do_object(obj);
1302 obj->oop_iterate(&oops);
1303 }
1304
1305 assert(oop_stack.is_empty(), "should be empty");
1306 // Reclaim bitmap
1307 reclaim_aux_bitmap_for_iteration();
1308 }
1309
1310 bool ShenandoahHeap::prepare_aux_bitmap_for_iteration() {
1311 assert(SafepointSynchronize::is_at_safepoint(), "safe iteration is only available during safepoints");
1312
1313 if (!_aux_bitmap_region_special && !os::commit_memory((char*)_aux_bitmap_region.start(), _aux_bitmap_region.byte_size(), false)) {
1314 log_warning(gc)("Could not commit native memory for auxiliary marking bitmap for heap iteration");
1315 return false;
1316 }
1317 // Reset bitmap
1318 _aux_bit_map.clear();
1319 return true;
1320 }
|