1 /*
2 * Copyright (c) 2015, 2017, 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 */
38 #include "gc/z/zRootsIterator.hpp"
39 #include "gc/z/zStat.hpp"
40 #include "gc/z/zTask.hpp"
41 #include "gc/z/zThread.hpp"
42 #include "gc/z/zTracer.inline.hpp"
43 #include "gc/z/zVirtualMemory.inline.hpp"
44 #include "gc/z/zWorkers.inline.hpp"
45 #include "logging/log.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "runtime/safepoint.hpp"
48 #include "runtime/thread.hpp"
49 #include "utilities/align.hpp"
50 #include "utilities/debug.hpp"
51
52 static const ZStatSampler ZSamplerHeapUsedBeforeMark("Memory", "Heap Used Before Mark", ZStatUnitBytes);
53 static const ZStatSampler ZSamplerHeapUsedAfterMark("Memory", "Heap Used After Mark", ZStatUnitBytes);
54 static const ZStatSampler ZSamplerHeapUsedBeforeRelocation("Memory", "Heap Used Before Relocation", ZStatUnitBytes);
55 static const ZStatSampler ZSamplerHeapUsedAfterRelocation("Memory", "Heap Used After Relocation", ZStatUnitBytes);
56 static const ZStatCounter ZCounterUndoPageAllocation("Memory", "Undo Page Allocation", ZStatUnitOpsPerSecond);
57 static const ZStatCounter ZCounterOutOfMemory("Memory", "Out Of Memory", ZStatUnitOpsPerSecond);
58 static const ZStatSubPhase ZPhaseConcurrentReferencesProcessing("Concurrent References Processing");
59 static const ZStatSubPhase ZPhaseConcurrentWeakRootsProcessing("Concurrent Weak Roots Processing");
60
61 ZHeap* ZHeap::_heap = NULL;
62
63 ZHeap::ZHeap() :
64 _initialize(),
65 _workers(),
66 _object_allocator(_workers.nworkers()),
67 _page_allocator(heap_min_size(), heap_max_size(), heap_max_reserve_size()),
68 _pagetable(),
69 _mark(&_workers, &_pagetable),
70 _reference_processor(&_workers),
71 _weak_roots_processor(&_workers),
72 _relocate(&_workers),
73 _relocation_set(),
74 _serviceability(heap_min_size(), heap_max_size()) {
75 // Install global heap instance
76 assert(_heap == NULL, "Already initialized");
77 _heap = this;
78
79 // Update statistics
329
330 // Try end marking
331 if (!_mark.end()) {
332 // Marking not completed, continue concurrent mark
333 return false;
334 }
335
336 // Enter mark completed phase
337 ZGlobalPhase = ZPhaseMarkCompleted;
338
339 // Resize metaspace
340 MetaspaceGC::compute_new_size();
341
342 // Update statistics
343 ZStatSample(ZSamplerHeapUsedAfterMark, used());
344 ZStatHeap::set_at_mark_end(capacity(), allocated(), used());
345
346 // Block resurrection of weak/phantom references
347 ZResurrection::block();
348
349 // Clean weak roots
350 _weak_roots_processor.process_weak_roots();
351
352 // Verification
353 if (VerifyBeforeGC || VerifyDuringGC || VerifyAfterGC) {
354 Universe::verify();
355 }
356
357 return true;
358 }
359
360 void ZHeap::set_soft_reference_policy(bool clear) {
361 _reference_processor.set_soft_reference_policy(clear);
362 }
363
364 void ZHeap::concurrent_weak_processing() {
365 {
366 ZStatTimer timer(ZPhaseConcurrentReferencesProcessing);
367 _reference_processor.process_and_enqueue_references();
368 }
369
370 {
371 ZStatTimer timer(ZPhaseConcurrentWeakRootsProcessing);
372 _weak_roots_processor.process_concurrent_weak_roots();
373 }
374
375 // Unblock resurrection of weak/phantom references
376 ZResurrection::unblock();
377 }
378
379 void ZHeap::destroy_detached_pages() {
380 ZList<ZPage> list;
381
382 _page_allocator.flush_detached_pages(&list);
383
384 for (ZPage* page = list.remove_first(); page != NULL; page = list.remove_first()) {
385 // Remove pagetable entry
386 _pagetable.remove(page);
387
388 // Delete the page
389 _page_allocator.destroy_page(page);
390 }
391 }
392
393 void ZHeap::select_relocation_set() {
|
1 /*
2 * Copyright (c) 2015, 2018, 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 */
38 #include "gc/z/zRootsIterator.hpp"
39 #include "gc/z/zStat.hpp"
40 #include "gc/z/zTask.hpp"
41 #include "gc/z/zThread.hpp"
42 #include "gc/z/zTracer.inline.hpp"
43 #include "gc/z/zVirtualMemory.inline.hpp"
44 #include "gc/z/zWorkers.inline.hpp"
45 #include "logging/log.hpp"
46 #include "oops/oop.inline.hpp"
47 #include "runtime/safepoint.hpp"
48 #include "runtime/thread.hpp"
49 #include "utilities/align.hpp"
50 #include "utilities/debug.hpp"
51
52 static const ZStatSampler ZSamplerHeapUsedBeforeMark("Memory", "Heap Used Before Mark", ZStatUnitBytes);
53 static const ZStatSampler ZSamplerHeapUsedAfterMark("Memory", "Heap Used After Mark", ZStatUnitBytes);
54 static const ZStatSampler ZSamplerHeapUsedBeforeRelocation("Memory", "Heap Used Before Relocation", ZStatUnitBytes);
55 static const ZStatSampler ZSamplerHeapUsedAfterRelocation("Memory", "Heap Used After Relocation", ZStatUnitBytes);
56 static const ZStatCounter ZCounterUndoPageAllocation("Memory", "Undo Page Allocation", ZStatUnitOpsPerSecond);
57 static const ZStatCounter ZCounterOutOfMemory("Memory", "Out Of Memory", ZStatUnitOpsPerSecond);
58
59 ZHeap* ZHeap::_heap = NULL;
60
61 ZHeap::ZHeap() :
62 _initialize(),
63 _workers(),
64 _object_allocator(_workers.nworkers()),
65 _page_allocator(heap_min_size(), heap_max_size(), heap_max_reserve_size()),
66 _pagetable(),
67 _mark(&_workers, &_pagetable),
68 _reference_processor(&_workers),
69 _weak_roots_processor(&_workers),
70 _relocate(&_workers),
71 _relocation_set(),
72 _serviceability(heap_min_size(), heap_max_size()) {
73 // Install global heap instance
74 assert(_heap == NULL, "Already initialized");
75 _heap = this;
76
77 // Update statistics
327
328 // Try end marking
329 if (!_mark.end()) {
330 // Marking not completed, continue concurrent mark
331 return false;
332 }
333
334 // Enter mark completed phase
335 ZGlobalPhase = ZPhaseMarkCompleted;
336
337 // Resize metaspace
338 MetaspaceGC::compute_new_size();
339
340 // Update statistics
341 ZStatSample(ZSamplerHeapUsedAfterMark, used());
342 ZStatHeap::set_at_mark_end(capacity(), allocated(), used());
343
344 // Block resurrection of weak/phantom references
345 ZResurrection::block();
346
347 // Process weak roots
348 _weak_roots_processor.process_weak_roots();
349
350 // Verification
351 if (VerifyBeforeGC || VerifyDuringGC || VerifyAfterGC) {
352 Universe::verify();
353 }
354
355 return true;
356 }
357
358 void ZHeap::set_soft_reference_policy(bool clear) {
359 _reference_processor.set_soft_reference_policy(clear);
360 }
361
362 void ZHeap::process_non_strong_references() {
363 // Process and enqueue Soft/Weak/Final/PhantomReferences
364 _reference_processor.process_and_enqueue_references();
365
366 // Process concurrent weak roots
367 _weak_roots_processor.process_concurrent_weak_roots();
368
369 // Unblock resurrection of weak/phantom references
370 ZResurrection::unblock();
371 }
372
373 void ZHeap::destroy_detached_pages() {
374 ZList<ZPage> list;
375
376 _page_allocator.flush_detached_pages(&list);
377
378 for (ZPage* page = list.remove_first(); page != NULL; page = list.remove_first()) {
379 // Remove pagetable entry
380 _pagetable.remove(page);
381
382 // Delete the page
383 _page_allocator.destroy_page(page);
384 }
385 }
386
387 void ZHeap::select_relocation_set() {
|