rev 60538 : imported patch jep387-all.patch
1 /*
2 * Copyright (c) 2000, 2020, 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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "aot/aotLoader.hpp"
27 #include "classfile/classLoaderDataGraph.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/stringTable.hpp"
30 #include "classfile/vmSymbols.hpp"
31 #include "code/codeCache.hpp"
32 #include "code/icBuffer.hpp"
33 #include "gc/serial/defNewGeneration.hpp"
34 #include "gc/shared/adaptiveSizePolicy.hpp"
35 #include "gc/shared/cardTableBarrierSet.hpp"
36 #include "gc/shared/cardTableRS.hpp"
37 #include "gc/shared/collectedHeap.inline.hpp"
38 #include "gc/shared/collectorCounters.hpp"
39 #include "gc/shared/gcId.hpp"
40 #include "gc/shared/gcLocker.hpp"
41 #include "gc/shared/gcPolicyCounters.hpp"
42 #include "gc/shared/gcTrace.hpp"
43 #include "gc/shared/gcTraceTime.inline.hpp"
44 #include "gc/shared/genArguments.hpp"
45 #include "gc/shared/gcVMOperations.hpp"
46 #include "gc/shared/genCollectedHeap.hpp"
47 #include "gc/shared/genOopClosures.inline.hpp"
48 #include "gc/shared/generationSpec.hpp"
49 #include "gc/shared/gcInitLogger.hpp"
50 #include "gc/shared/locationPrinter.inline.hpp"
51 #include "gc/shared/oopStorage.inline.hpp"
52 #include "gc/shared/oopStorageSet.inline.hpp"
53 #include "gc/shared/oopStorageParState.inline.hpp"
54 #include "gc/shared/scavengableNMethods.hpp"
55 #include "gc/shared/space.hpp"
56 #include "gc/shared/strongRootsScope.hpp"
57 #include "gc/shared/weakProcessor.hpp"
58 #include "gc/shared/workgroup.hpp"
59 #include "memory/filemap.hpp"
60 #include "memory/iterator.hpp"
61 #include "memory/metaspaceCounters.hpp"
62 #include "memory/resourceArea.hpp"
63 #include "memory/universe.hpp"
64 #include "oops/oop.inline.hpp"
65 #include "runtime/biasedLocking.hpp"
66 #include "runtime/handles.hpp"
67 #include "runtime/handles.inline.hpp"
68 #include "runtime/java.hpp"
69 #include "runtime/vmThread.hpp"
70 #include "services/memoryService.hpp"
71 #include "utilities/autoRestore.hpp"
72 #include "utilities/debug.hpp"
73 #include "utilities/formatBuffer.hpp"
74 #include "utilities/macros.hpp"
75 #include "utilities/stack.inline.hpp"
76 #include "utilities/vmError.hpp"
77 #if INCLUDE_JVMCI
78 #include "jvmci/jvmci.hpp"
79 #endif
80
81 GenCollectedHeap::GenCollectedHeap(Generation::Name young,
82 Generation::Name old,
83 const char* policy_counters_name) :
84 CollectedHeap(),
85 _young_gen(NULL),
86 _old_gen(NULL),
87 _young_gen_spec(new GenerationSpec(young,
88 NewSize,
89 MaxNewSize,
90 GenAlignment)),
91 _old_gen_spec(new GenerationSpec(old,
92 OldSize,
93 MaxOldSize,
94 GenAlignment)),
95 _rem_set(NULL),
96 _soft_ref_gen_policy(),
97 _size_policy(NULL),
98 _gc_policy_counters(new GCPolicyCounters(policy_counters_name, 2, 2)),
99 _incremental_collection_failed(false),
100 _full_collections_completed(0),
101 _process_strong_tasks(new SubTasksDone(GCH_PS_NumElements)),
102 _young_manager(NULL),
103 _old_manager(NULL) {
104 }
105
106 jint GenCollectedHeap::initialize() {
107 // While there are no constraints in the GC code that HeapWordSize
108 // be any particular value, there are multiple other areas in the
109 // system which believe this to be true (e.g. oop->object_size in some
110 // cases incorrectly returns the size in wordSize units rather than
111 // HeapWordSize).
112 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
113
114 // Allocate space for the heap.
115
116 ReservedHeapSpace heap_rs = allocate(HeapAlignment);
117
118 if (!heap_rs.is_reserved()) {
119 vm_shutdown_during_initialization(
120 "Could not reserve enough space for object heap");
121 return JNI_ENOMEM;
122 }
123
124 initialize_reserved_region(heap_rs);
125
126 _rem_set = create_rem_set(heap_rs.region());
127 _rem_set->initialize();
128 CardTableBarrierSet *bs = new CardTableBarrierSet(_rem_set);
129 bs->initialize();
130 BarrierSet::set_barrier_set(bs);
131
132 ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size());
133 _young_gen = _young_gen_spec->init(young_rs, rem_set());
134 ReservedSpace old_rs = heap_rs.last_part(_young_gen_spec->max_size());
135
136 old_rs = old_rs.first_part(_old_gen_spec->max_size());
137 _old_gen = _old_gen_spec->init(old_rs, rem_set());
138
139 GCInitLogger::print();
140
141 return JNI_OK;
142 }
143
144 CardTableRS* GenCollectedHeap::create_rem_set(const MemRegion& reserved_region) {
145 return new CardTableRS(reserved_region, false /* scan_concurrently */);
146 }
147
148 void GenCollectedHeap::initialize_size_policy(size_t init_eden_size,
149 size_t init_promo_size,
150 size_t init_survivor_size) {
151 const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
152 _size_policy = new AdaptiveSizePolicy(init_eden_size,
153 init_promo_size,
154 init_survivor_size,
155 max_gc_pause_sec,
156 GCTimeRatio);
157 }
158
159 ReservedHeapSpace GenCollectedHeap::allocate(size_t alignment) {
160 // Now figure out the total size.
161 const size_t pageSize = UseLargePages ? os::large_page_size() : os::vm_page_size();
162 assert(alignment % pageSize == 0, "Must be");
163
164 // Check for overflow.
165 size_t total_reserved = _young_gen_spec->max_size() + _old_gen_spec->max_size();
166 if (total_reserved < _young_gen_spec->max_size()) {
167 vm_exit_during_initialization("The size of the object heap + VM data exceeds "
168 "the maximum representable size");
169 }
170 assert(total_reserved % alignment == 0,
171 "Gen size; total_reserved=" SIZE_FORMAT ", alignment="
172 SIZE_FORMAT, total_reserved, alignment);
173
174 ReservedHeapSpace heap_rs = Universe::reserve_heap(total_reserved, alignment);
175
176 os::trace_page_sizes("Heap",
177 MinHeapSize,
178 total_reserved,
179 alignment,
180 heap_rs.base(),
181 heap_rs.size());
182
183 return heap_rs;
184 }
185
186 class GenIsScavengable : public BoolObjectClosure {
187 public:
188 bool do_object_b(oop obj) {
189 return GenCollectedHeap::heap()->is_in_young(obj);
190 }
191 };
192
193 static GenIsScavengable _is_scavengable;
194
195 void GenCollectedHeap::post_initialize() {
196 CollectedHeap::post_initialize();
197 ref_processing_init();
198
199 DefNewGeneration* def_new_gen = (DefNewGeneration*)_young_gen;
200
201 initialize_size_policy(def_new_gen->eden()->capacity(),
202 _old_gen->capacity(),
203 def_new_gen->from()->capacity());
204
205 MarkSweep::initialize();
206
207 ScavengableNMethods::initialize(&_is_scavengable);
208 }
209
210 void GenCollectedHeap::ref_processing_init() {
211 _young_gen->ref_processor_init();
212 _old_gen->ref_processor_init();
213 }
214
215 PreGenGCValues GenCollectedHeap::get_pre_gc_values() const {
216 const DefNewGeneration* const def_new_gen = (DefNewGeneration*) young_gen();
217
218 return PreGenGCValues(def_new_gen->used(),
219 def_new_gen->capacity(),
220 def_new_gen->eden()->used(),
221 def_new_gen->eden()->capacity(),
222 def_new_gen->from()->used(),
223 def_new_gen->from()->capacity(),
224 old_gen()->used(),
225 old_gen()->capacity());
226 }
227
228 GenerationSpec* GenCollectedHeap::young_gen_spec() const {
229 return _young_gen_spec;
230 }
231
232 GenerationSpec* GenCollectedHeap::old_gen_spec() const {
233 return _old_gen_spec;
234 }
235
236 size_t GenCollectedHeap::capacity() const {
237 return _young_gen->capacity() + _old_gen->capacity();
238 }
239
240 size_t GenCollectedHeap::used() const {
241 return _young_gen->used() + _old_gen->used();
242 }
243
244 void GenCollectedHeap::save_used_regions() {
245 _old_gen->save_used_region();
246 _young_gen->save_used_region();
247 }
248
249 size_t GenCollectedHeap::max_capacity() const {
250 return _young_gen->max_capacity() + _old_gen->max_capacity();
251 }
252
253 // Update the _full_collections_completed counter
254 // at the end of a stop-world full GC.
255 unsigned int GenCollectedHeap::update_full_collections_completed() {
256 MonitorLocker ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
257 assert(_full_collections_completed <= _total_full_collections,
258 "Can't complete more collections than were started");
259 _full_collections_completed = _total_full_collections;
260 ml.notify_all();
261 return _full_collections_completed;
262 }
263
264 // Update the _full_collections_completed counter, as appropriate,
265 // at the end of a concurrent GC cycle. Note the conditional update
266 // below to allow this method to be called by a concurrent collector
267 // without synchronizing in any manner with the VM thread (which
268 // may already have initiated a STW full collection "concurrently").
269 unsigned int GenCollectedHeap::update_full_collections_completed(unsigned int count) {
270 MonitorLocker ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
271 assert((_full_collections_completed <= _total_full_collections) &&
272 (count <= _total_full_collections),
273 "Can't complete more collections than were started");
274 if (count > _full_collections_completed) {
275 _full_collections_completed = count;
276 ml.notify_all();
277 }
278 return _full_collections_completed;
279 }
280
281 // Return true if any of the following is true:
282 // . the allocation won't fit into the current young gen heap
283 // . gc locker is occupied (jni critical section)
284 // . heap memory is tight -- the most recent previous collection
285 // was a full collection because a partial collection (would
286 // have) failed and is likely to fail again
287 bool GenCollectedHeap::should_try_older_generation_allocation(size_t word_size) const {
288 size_t young_capacity = _young_gen->capacity_before_gc();
289 return (word_size > heap_word_size(young_capacity))
290 || GCLocker::is_active_and_needs_gc()
291 || incremental_collection_failed();
292 }
293
294 HeapWord* GenCollectedHeap::expand_heap_and_allocate(size_t size, bool is_tlab) {
295 HeapWord* result = NULL;
296 if (_old_gen->should_allocate(size, is_tlab)) {
297 result = _old_gen->expand_and_allocate(size, is_tlab);
298 }
299 if (result == NULL) {
300 if (_young_gen->should_allocate(size, is_tlab)) {
301 result = _young_gen->expand_and_allocate(size, is_tlab);
302 }
303 }
304 assert(result == NULL || is_in_reserved(result), "result not in heap");
305 return result;
306 }
307
308 HeapWord* GenCollectedHeap::mem_allocate_work(size_t size,
309 bool is_tlab,
310 bool* gc_overhead_limit_was_exceeded) {
311 // In general gc_overhead_limit_was_exceeded should be false so
312 // set it so here and reset it to true only if the gc time
313 // limit is being exceeded as checked below.
314 *gc_overhead_limit_was_exceeded = false;
315
316 HeapWord* result = NULL;
317
318 // Loop until the allocation is satisfied, or unsatisfied after GC.
319 for (uint try_count = 1, gclocker_stalled_count = 0; /* return or throw */; try_count += 1) {
320
321 // First allocation attempt is lock-free.
322 Generation *young = _young_gen;
323 assert(young->supports_inline_contig_alloc(),
324 "Otherwise, must do alloc within heap lock");
325 if (young->should_allocate(size, is_tlab)) {
326 result = young->par_allocate(size, is_tlab);
327 if (result != NULL) {
328 assert(is_in_reserved(result), "result not in heap");
329 return result;
330 }
331 }
332 uint gc_count_before; // Read inside the Heap_lock locked region.
333 {
334 MutexLocker ml(Heap_lock);
335 log_trace(gc, alloc)("GenCollectedHeap::mem_allocate_work: attempting locked slow path allocation");
336 // Note that only large objects get a shot at being
337 // allocated in later generations.
338 bool first_only = !should_try_older_generation_allocation(size);
339
340 result = attempt_allocation(size, is_tlab, first_only);
341 if (result != NULL) {
342 assert(is_in_reserved(result), "result not in heap");
343 return result;
344 }
345
346 if (GCLocker::is_active_and_needs_gc()) {
347 if (is_tlab) {
348 return NULL; // Caller will retry allocating individual object.
349 }
350 if (!is_maximal_no_gc()) {
351 // Try and expand heap to satisfy request.
352 result = expand_heap_and_allocate(size, is_tlab);
353 // Result could be null if we are out of space.
354 if (result != NULL) {
355 return result;
356 }
357 }
358
359 if (gclocker_stalled_count > GCLockerRetryAllocationCount) {
360 return NULL; // We didn't get to do a GC and we didn't get any memory.
361 }
362
363 // If this thread is not in a jni critical section, we stall
364 // the requestor until the critical section has cleared and
365 // GC allowed. When the critical section clears, a GC is
366 // initiated by the last thread exiting the critical section; so
367 // we retry the allocation sequence from the beginning of the loop,
368 // rather than causing more, now probably unnecessary, GC attempts.
369 JavaThread* jthr = JavaThread::current();
370 if (!jthr->in_critical()) {
371 MutexUnlocker mul(Heap_lock);
372 // Wait for JNI critical section to be exited
373 GCLocker::stall_until_clear();
374 gclocker_stalled_count += 1;
375 continue;
376 } else {
377 if (CheckJNICalls) {
378 fatal("Possible deadlock due to allocating while"
379 " in jni critical section");
380 }
381 return NULL;
382 }
383 }
384
385 // Read the gc count while the heap lock is held.
386 gc_count_before = total_collections();
387 }
388
389 VM_GenCollectForAllocation op(size, is_tlab, gc_count_before);
390 VMThread::execute(&op);
391 if (op.prologue_succeeded()) {
392 result = op.result();
393 if (op.gc_locked()) {
394 assert(result == NULL, "must be NULL if gc_locked() is true");
395 continue; // Retry and/or stall as necessary.
396 }
397
398 // Allocation has failed and a collection
399 // has been done. If the gc time limit was exceeded the
400 // this time, return NULL so that an out-of-memory
401 // will be thrown. Clear gc_overhead_limit_exceeded
402 // so that the overhead exceeded does not persist.
403
404 const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded();
405 const bool softrefs_clear = soft_ref_policy()->all_soft_refs_clear();
406
407 if (limit_exceeded && softrefs_clear) {
408 *gc_overhead_limit_was_exceeded = true;
409 size_policy()->set_gc_overhead_limit_exceeded(false);
410 if (op.result() != NULL) {
411 CollectedHeap::fill_with_object(op.result(), size);
412 }
413 return NULL;
414 }
415 assert(result == NULL || is_in_reserved(result),
416 "result not in heap");
417 return result;
418 }
419
420 // Give a warning if we seem to be looping forever.
421 if ((QueuedAllocationWarningCount > 0) &&
422 (try_count % QueuedAllocationWarningCount == 0)) {
423 log_warning(gc, ergo)("GenCollectedHeap::mem_allocate_work retries %d times,"
424 " size=" SIZE_FORMAT " %s", try_count, size, is_tlab ? "(TLAB)" : "");
425 }
426 }
427 }
428
429 HeapWord* GenCollectedHeap::attempt_allocation(size_t size,
430 bool is_tlab,
431 bool first_only) {
432 HeapWord* res = NULL;
433
434 if (_young_gen->should_allocate(size, is_tlab)) {
435 res = _young_gen->allocate(size, is_tlab);
436 if (res != NULL || first_only) {
437 return res;
438 }
439 }
440
441 if (_old_gen->should_allocate(size, is_tlab)) {
442 res = _old_gen->allocate(size, is_tlab);
443 }
444
445 return res;
446 }
447
448 HeapWord* GenCollectedHeap::mem_allocate(size_t size,
449 bool* gc_overhead_limit_was_exceeded) {
450 return mem_allocate_work(size,
451 false /* is_tlab */,
452 gc_overhead_limit_was_exceeded);
453 }
454
455 bool GenCollectedHeap::must_clear_all_soft_refs() {
456 return _gc_cause == GCCause::_metadata_GC_clear_soft_refs ||
457 _gc_cause == GCCause::_wb_full_gc;
458 }
459
460 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
461 bool is_tlab, bool run_verification, bool clear_soft_refs,
462 bool restore_marks_for_biased_locking) {
463 FormatBuffer<> title("Collect gen: %s", gen->short_name());
464 GCTraceTime(Trace, gc, phases) t1(title);
465 TraceCollectorStats tcs(gen->counters());
466 TraceMemoryManagerStats tmms(gen->gc_manager(), gc_cause());
467
468 gen->stat_record()->invocations++;
469 gen->stat_record()->accumulated_time.start();
470
471 // Must be done anew before each collection because
472 // a previous collection will do mangling and will
473 // change top of some spaces.
474 record_gen_tops_before_GC();
475
476 log_trace(gc)("%s invoke=%d size=" SIZE_FORMAT, heap()->is_young_gen(gen) ? "Young" : "Old", gen->stat_record()->invocations, size * HeapWordSize);
477
478 if (run_verification && VerifyBeforeGC) {
479 Universe::verify("Before GC");
480 }
481 COMPILER2_OR_JVMCI_PRESENT(DerivedPointerTable::clear());
482
483 if (restore_marks_for_biased_locking) {
484 // We perform this mark word preservation work lazily
485 // because it's only at this point that we know whether we
486 // absolutely have to do it; we want to avoid doing it for
487 // scavenge-only collections where it's unnecessary
488 BiasedLocking::preserve_marks();
489 }
490
491 // Do collection work
492 {
493 // Note on ref discovery: For what appear to be historical reasons,
494 // GCH enables and disabled (by enqueing) refs discovery.
495 // In the future this should be moved into the generation's
496 // collect method so that ref discovery and enqueueing concerns
497 // are local to a generation. The collect method could return
498 // an appropriate indication in the case that notification on
499 // the ref lock was needed. This will make the treatment of
500 // weak refs more uniform (and indeed remove such concerns
501 // from GCH). XXX
502
503 save_marks(); // save marks for all gens
504 // We want to discover references, but not process them yet.
505 // This mode is disabled in process_discovered_references if the
506 // generation does some collection work, or in
507 // enqueue_discovered_references if the generation returns
508 // without doing any work.
509 ReferenceProcessor* rp = gen->ref_processor();
510 // If the discovery of ("weak") refs in this generation is
511 // atomic wrt other collectors in this configuration, we
512 // are guaranteed to have empty discovered ref lists.
513 if (rp->discovery_is_atomic()) {
514 rp->enable_discovery();
515 rp->setup_policy(clear_soft_refs);
516 } else {
517 // collect() below will enable discovery as appropriate
518 }
519 gen->collect(full, clear_soft_refs, size, is_tlab);
520 if (!rp->enqueuing_is_done()) {
521 rp->disable_discovery();
522 } else {
523 rp->set_enqueuing_is_done(false);
524 }
525 rp->verify_no_references_recorded();
526 }
527
528 COMPILER2_OR_JVMCI_PRESENT(DerivedPointerTable::update_pointers());
529
530 gen->stat_record()->accumulated_time.stop();
531
532 update_gc_stats(gen, full);
533
534 if (run_verification && VerifyAfterGC) {
535 Universe::verify("After GC");
536 }
537 }
538
539 void GenCollectedHeap::do_collection(bool full,
540 bool clear_all_soft_refs,
541 size_t size,
542 bool is_tlab,
543 GenerationType max_generation) {
544 ResourceMark rm;
545 DEBUG_ONLY(Thread* my_thread = Thread::current();)
546
547 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
548 assert(my_thread->is_VM_thread() ||
549 my_thread->is_ConcurrentGC_thread(),
550 "incorrect thread type capability");
551 assert(Heap_lock->is_locked(),
552 "the requesting thread should have the Heap_lock");
553 guarantee(!is_gc_active(), "collection is not reentrant");
554
555 if (GCLocker::check_active_before_gc()) {
556 return; // GC is disabled (e.g. JNI GetXXXCritical operation)
557 }
558
559 const bool do_clear_all_soft_refs = clear_all_soft_refs ||
560 soft_ref_policy()->should_clear_all_soft_refs();
561
562 ClearedAllSoftRefs casr(do_clear_all_soft_refs, soft_ref_policy());
563
564 AutoModifyRestore<bool> temporarily(_is_gc_active, true);
565
566 bool complete = full && (max_generation == OldGen);
567 bool old_collects_young = complete && !ScavengeBeforeFullGC;
568 bool do_young_collection = !old_collects_young && _young_gen->should_collect(full, size, is_tlab);
569
570 const PreGenGCValues pre_gc_values = get_pre_gc_values();
571
572 bool run_verification = total_collections() >= VerifyGCStartAt;
573 bool prepared_for_verification = false;
574 bool do_full_collection = false;
575
576 if (do_young_collection) {
577 GCIdMark gc_id_mark;
578 GCTraceCPUTime tcpu;
579 GCTraceTime(Info, gc) t("Pause Young", NULL, gc_cause(), true);
580
581 print_heap_before_gc();
582
583 if (run_verification && VerifyGCLevel <= 0 && VerifyBeforeGC) {
584 prepare_for_verify();
585 prepared_for_verification = true;
586 }
587
588 gc_prologue(complete);
589 increment_total_collections(complete);
590
591 collect_generation(_young_gen,
592 full,
593 size,
594 is_tlab,
595 run_verification && VerifyGCLevel <= 0,
596 do_clear_all_soft_refs,
597 false);
598
599 if (size > 0 && (!is_tlab || _young_gen->supports_tlab_allocation()) &&
600 size * HeapWordSize <= _young_gen->unsafe_max_alloc_nogc()) {
601 // Allocation request was met by young GC.
602 size = 0;
603 }
604
605 // Ask if young collection is enough. If so, do the final steps for young collection,
606 // and fallthrough to the end.
607 do_full_collection = should_do_full_collection(size, full, is_tlab, max_generation);
608 if (!do_full_collection) {
609 // Adjust generation sizes.
610 _young_gen->compute_new_size();
611
612 print_heap_change(pre_gc_values);
613
614 // Track memory usage and detect low memory after GC finishes
615 MemoryService::track_memory_usage();
616
617 gc_epilogue(complete);
618 }
619
620 print_heap_after_gc();
621
622 } else {
623 // No young collection, ask if we need to perform Full collection.
624 do_full_collection = should_do_full_collection(size, full, is_tlab, max_generation);
625 }
626
627 if (do_full_collection) {
628 GCIdMark gc_id_mark;
629 GCTraceCPUTime tcpu;
630 GCTraceTime(Info, gc) t("Pause Full", NULL, gc_cause(), true);
631
632 print_heap_before_gc();
633
634 if (!prepared_for_verification && run_verification &&
635 VerifyGCLevel <= 1 && VerifyBeforeGC) {
636 prepare_for_verify();
637 }
638
639 if (!do_young_collection) {
640 gc_prologue(complete);
641 increment_total_collections(complete);
642 }
643
644 // Accounting quirk: total full collections would be incremented when "complete"
645 // is set, by calling increment_total_collections above. However, we also need to
646 // account Full collections that had "complete" unset.
647 if (!complete) {
648 increment_total_full_collections();
649 }
650
651 collect_generation(_old_gen,
652 full,
653 size,
654 is_tlab,
655 run_verification && VerifyGCLevel <= 1,
656 do_clear_all_soft_refs,
657 true);
658
659 // Adjust generation sizes.
660 _old_gen->compute_new_size();
661 _young_gen->compute_new_size();
662
663 // Delete metaspaces for unloaded class loaders and clean up loader_data graph
664 ClassLoaderDataGraph::purge();
665 MetaspaceUtils::verify_metrics();
666 // Resize the metaspace capacity after full collections
667 MetaspaceGC::compute_new_size();
668 update_full_collections_completed();
669
670 print_heap_change(pre_gc_values);
671
672 // Track memory usage and detect low memory after GC finishes
673 MemoryService::track_memory_usage();
674
675 // Need to tell the epilogue code we are done with Full GC, regardless what was
676 // the initial value for "complete" flag.
677 gc_epilogue(true);
678
679 BiasedLocking::restore_marks();
680
681 print_heap_after_gc();
682 }
683 }
684
685 bool GenCollectedHeap::should_do_full_collection(size_t size, bool full, bool is_tlab,
686 GenCollectedHeap::GenerationType max_gen) const {
687 return max_gen == OldGen && _old_gen->should_collect(full, size, is_tlab);
688 }
689
690 void GenCollectedHeap::register_nmethod(nmethod* nm) {
691 ScavengableNMethods::register_nmethod(nm);
692 }
693
694 void GenCollectedHeap::unregister_nmethod(nmethod* nm) {
695 ScavengableNMethods::unregister_nmethod(nm);
696 }
697
698 void GenCollectedHeap::verify_nmethod(nmethod* nm) {
699 ScavengableNMethods::verify_nmethod(nm);
700 }
701
702 void GenCollectedHeap::flush_nmethod(nmethod* nm) {
703 // Do nothing.
704 }
705
706 void GenCollectedHeap::prune_scavengable_nmethods() {
707 ScavengableNMethods::prune_nmethods();
708 }
709
710 HeapWord* GenCollectedHeap::satisfy_failed_allocation(size_t size, bool is_tlab) {
711 GCCauseSetter x(this, GCCause::_allocation_failure);
712 HeapWord* result = NULL;
713
714 assert(size != 0, "Precondition violated");
715 if (GCLocker::is_active_and_needs_gc()) {
716 // GC locker is active; instead of a collection we will attempt
717 // to expand the heap, if there's room for expansion.
718 if (!is_maximal_no_gc()) {
719 result = expand_heap_and_allocate(size, is_tlab);
720 }
721 return result; // Could be null if we are out of space.
722 } else if (!incremental_collection_will_fail(false /* don't consult_young */)) {
723 // Do an incremental collection.
724 do_collection(false, // full
725 false, // clear_all_soft_refs
726 size, // size
727 is_tlab, // is_tlab
728 GenCollectedHeap::OldGen); // max_generation
729 } else {
730 log_trace(gc)(" :: Trying full because partial may fail :: ");
731 // Try a full collection; see delta for bug id 6266275
732 // for the original code and why this has been simplified
733 // with from-space allocation criteria modified and
734 // such allocation moved out of the safepoint path.
735 do_collection(true, // full
736 false, // clear_all_soft_refs
737 size, // size
738 is_tlab, // is_tlab
739 GenCollectedHeap::OldGen); // max_generation
740 }
741
742 result = attempt_allocation(size, is_tlab, false /*first_only*/);
743
744 if (result != NULL) {
745 assert(is_in_reserved(result), "result not in heap");
746 return result;
747 }
748
749 // OK, collection failed, try expansion.
750 result = expand_heap_and_allocate(size, is_tlab);
751 if (result != NULL) {
752 return result;
753 }
754
755 // If we reach this point, we're really out of memory. Try every trick
756 // we can to reclaim memory. Force collection of soft references. Force
757 // a complete compaction of the heap. Any additional methods for finding
758 // free memory should be here, especially if they are expensive. If this
759 // attempt fails, an OOM exception will be thrown.
760 {
761 UIntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted
762
763 do_collection(true, // full
764 true, // clear_all_soft_refs
765 size, // size
766 is_tlab, // is_tlab
767 GenCollectedHeap::OldGen); // max_generation
768 }
769
770 result = attempt_allocation(size, is_tlab, false /* first_only */);
771 if (result != NULL) {
772 assert(is_in_reserved(result), "result not in heap");
773 return result;
774 }
775
776 assert(!soft_ref_policy()->should_clear_all_soft_refs(),
777 "Flag should have been handled and cleared prior to this point");
778
779 // What else? We might try synchronous finalization later. If the total
780 // space available is large enough for the allocation, then a more
781 // complete compaction phase than we've tried so far might be
782 // appropriate.
783 return NULL;
784 }
785
786 #ifdef ASSERT
787 class AssertNonScavengableClosure: public OopClosure {
788 public:
789 virtual void do_oop(oop* p) {
790 assert(!GenCollectedHeap::heap()->is_in_partial_collection(*p),
791 "Referent should not be scavengable."); }
792 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
793 };
794 static AssertNonScavengableClosure assert_is_non_scavengable_closure;
795 #endif
796
797 void GenCollectedHeap::process_roots(StrongRootsScope* scope,
798 ScanningOption so,
799 OopClosure* strong_roots,
800 CLDClosure* strong_cld_closure,
801 CLDClosure* weak_cld_closure,
802 CodeBlobToOopClosure* code_roots) {
803 // General roots.
804 assert(code_roots != NULL, "code root closure should always be set");
805 // _n_termination for _process_strong_tasks should be set up stream
806 // in a method not running in a GC worker. Otherwise the GC worker
807 // could be trying to change the termination condition while the task
808 // is executing in another GC worker.
809
810 if (_process_strong_tasks->try_claim_task(GCH_PS_ClassLoaderDataGraph_oops_do)) {
811 ClassLoaderDataGraph::roots_cld_do(strong_cld_closure, weak_cld_closure);
812 }
813
814 // Only process code roots from thread stacks if we aren't visiting the entire CodeCache anyway
815 CodeBlobToOopClosure* roots_from_code_p = (so & SO_AllCodeCache) ? NULL : code_roots;
816
817 bool is_par = scope->n_threads() > 1;
818 Threads::possibly_parallel_oops_do(is_par, strong_roots, roots_from_code_p);
819
820 if (_process_strong_tasks->try_claim_task(GCH_PS_ObjectSynchronizer_oops_do)) {
821 ObjectSynchronizer::oops_do(strong_roots);
822 }
823 #if INCLUDE_AOT
824 if (UseAOT && _process_strong_tasks->try_claim_task(GCH_PS_aot_oops_do)) {
825 AOTLoader::oops_do(strong_roots);
826 }
827 #endif
828 if (_process_strong_tasks->try_claim_task(GCH_PS_OopStorageSet_oops_do)) {
829 OopStorageSet::strong_oops_do(strong_roots);
830 }
831
832 if (_process_strong_tasks->try_claim_task(GCH_PS_CodeCache_oops_do)) {
833 if (so & SO_ScavengeCodeCache) {
834 assert(code_roots != NULL, "must supply closure for code cache");
835
836 // We only visit parts of the CodeCache when scavenging.
837 ScavengableNMethods::nmethods_do(code_roots);
838 }
839 if (so & SO_AllCodeCache) {
840 assert(code_roots != NULL, "must supply closure for code cache");
841
842 // CMSCollector uses this to do intermediate-strength collections.
843 // We scan the entire code cache, since CodeCache::do_unloading is not called.
844 CodeCache::blobs_do(code_roots);
845 }
846 // Verify that the code cache contents are not subject to
847 // movement by a scavenging collection.
848 DEBUG_ONLY(CodeBlobToOopClosure assert_code_is_non_scavengable(&assert_is_non_scavengable_closure, !CodeBlobToOopClosure::FixRelocations));
849 DEBUG_ONLY(ScavengableNMethods::asserted_non_scavengable_nmethods_do(&assert_code_is_non_scavengable));
850 }
851 }
852
853 void GenCollectedHeap::young_process_roots(StrongRootsScope* scope,
854 OopsInGenClosure* root_closure,
855 OopsInGenClosure* old_gen_closure,
856 CLDClosure* cld_closure) {
857 MarkingCodeBlobClosure mark_code_closure(root_closure, CodeBlobToOopClosure::FixRelocations);
858
859 process_roots(scope, SO_ScavengeCodeCache, root_closure,
860 cld_closure, cld_closure, &mark_code_closure);
861
862 if (_process_strong_tasks->try_claim_task(GCH_PS_younger_gens)) {
863 root_closure->reset_generation();
864 }
865
866 // When collection is parallel, all threads get to cooperate to do
867 // old generation scanning.
868 old_gen_closure->set_generation(_old_gen);
869 rem_set()->younger_refs_iterate(_old_gen, old_gen_closure, scope->n_threads());
870 old_gen_closure->reset_generation();
871
872 _process_strong_tasks->all_tasks_completed(scope->n_threads());
873 }
874
875 void GenCollectedHeap::full_process_roots(StrongRootsScope* scope,
876 bool is_adjust_phase,
877 ScanningOption so,
878 bool only_strong_roots,
879 OopsInGenClosure* root_closure,
880 CLDClosure* cld_closure) {
881 MarkingCodeBlobClosure mark_code_closure(root_closure, is_adjust_phase);
882 CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure;
883
884 process_roots(scope, so, root_closure, cld_closure, weak_cld_closure, &mark_code_closure);
885 _process_strong_tasks->all_tasks_completed(scope->n_threads());
886 }
887
888 void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure) {
889 WeakProcessor::oops_do(root_closure);
890 _young_gen->ref_processor()->weak_oops_do(root_closure);
891 _old_gen->ref_processor()->weak_oops_do(root_closure);
892 }
893
894 bool GenCollectedHeap::no_allocs_since_save_marks() {
895 return _young_gen->no_allocs_since_save_marks() &&
896 _old_gen->no_allocs_since_save_marks();
897 }
898
899 bool GenCollectedHeap::supports_inline_contig_alloc() const {
900 return _young_gen->supports_inline_contig_alloc();
901 }
902
903 HeapWord* volatile* GenCollectedHeap::top_addr() const {
904 return _young_gen->top_addr();
905 }
906
907 HeapWord** GenCollectedHeap::end_addr() const {
908 return _young_gen->end_addr();
909 }
910
911 // public collection interfaces
912
913 void GenCollectedHeap::collect(GCCause::Cause cause) {
914 if ((cause == GCCause::_wb_young_gc) ||
915 (cause == GCCause::_gc_locker)) {
916 // Young collection for WhiteBox or GCLocker.
917 collect(cause, YoungGen);
918 } else {
919 #ifdef ASSERT
920 if (cause == GCCause::_scavenge_alot) {
921 // Young collection only.
922 collect(cause, YoungGen);
923 } else {
924 // Stop-the-world full collection.
925 collect(cause, OldGen);
926 }
927 #else
928 // Stop-the-world full collection.
929 collect(cause, OldGen);
930 #endif
931 }
932 }
933
934 void GenCollectedHeap::collect(GCCause::Cause cause, GenerationType max_generation) {
935 // The caller doesn't have the Heap_lock
936 assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
937 MutexLocker ml(Heap_lock);
938 collect_locked(cause, max_generation);
939 }
940
941 void GenCollectedHeap::collect_locked(GCCause::Cause cause) {
942 // The caller has the Heap_lock
943 assert(Heap_lock->owned_by_self(), "this thread should own the Heap_lock");
944 collect_locked(cause, OldGen);
945 }
946
947 // this is the private collection interface
948 // The Heap_lock is expected to be held on entry.
949
950 void GenCollectedHeap::collect_locked(GCCause::Cause cause, GenerationType max_generation) {
951 // Read the GC count while holding the Heap_lock
952 unsigned int gc_count_before = total_collections();
953 unsigned int full_gc_count_before = total_full_collections();
954
955 if (GCLocker::should_discard(cause, gc_count_before)) {
956 return;
957 }
958
959 {
960 MutexUnlocker mu(Heap_lock); // give up heap lock, execute gets it back
961 VM_GenCollectFull op(gc_count_before, full_gc_count_before,
962 cause, max_generation);
963 VMThread::execute(&op);
964 }
965 }
966
967 void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs) {
968 do_full_collection(clear_all_soft_refs, OldGen);
969 }
970
971 void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs,
972 GenerationType last_generation) {
973 do_collection(true, // full
974 clear_all_soft_refs, // clear_all_soft_refs
975 0, // size
976 false, // is_tlab
977 last_generation); // last_generation
978 // Hack XXX FIX ME !!!
979 // A scavenge may not have been attempted, or may have
980 // been attempted and failed, because the old gen was too full
981 if (gc_cause() == GCCause::_gc_locker && incremental_collection_failed()) {
982 log_debug(gc, jni)("GC locker: Trying a full collection because scavenge failed");
983 // This time allow the old gen to be collected as well
984 do_collection(true, // full
985 clear_all_soft_refs, // clear_all_soft_refs
986 0, // size
987 false, // is_tlab
988 OldGen); // last_generation
989 }
990 }
991
992 bool GenCollectedHeap::is_in_young(oop p) {
993 bool result = cast_from_oop<HeapWord*>(p) < _old_gen->reserved().start();
994 assert(result == _young_gen->is_in_reserved(p),
995 "incorrect test - result=%d, p=" INTPTR_FORMAT, result, p2i((void*)p));
996 return result;
997 }
998
999 // Returns "TRUE" iff "p" points into the committed areas of the heap.
1000 bool GenCollectedHeap::is_in(const void* p) const {
1001 return _young_gen->is_in(p) || _old_gen->is_in(p);
1002 }
1003
1004 #ifdef ASSERT
1005 // Don't implement this by using is_in_young(). This method is used
1006 // in some cases to check that is_in_young() is correct.
1007 bool GenCollectedHeap::is_in_partial_collection(const void* p) {
1008 assert(is_in_reserved(p) || p == NULL,
1009 "Does not work if address is non-null and outside of the heap");
1010 return p < _young_gen->reserved().end() && p != NULL;
1011 }
1012 #endif
1013
1014 void GenCollectedHeap::oop_iterate(OopIterateClosure* cl) {
1015 _young_gen->oop_iterate(cl);
1016 _old_gen->oop_iterate(cl);
1017 }
1018
1019 void GenCollectedHeap::object_iterate(ObjectClosure* cl) {
1020 _young_gen->object_iterate(cl);
1021 _old_gen->object_iterate(cl);
1022 }
1023
1024 Space* GenCollectedHeap::space_containing(const void* addr) const {
1025 Space* res = _young_gen->space_containing(addr);
1026 if (res != NULL) {
1027 return res;
1028 }
1029 res = _old_gen->space_containing(addr);
1030 assert(res != NULL, "Could not find containing space");
1031 return res;
1032 }
1033
1034 HeapWord* GenCollectedHeap::block_start(const void* addr) const {
1035 assert(is_in_reserved(addr), "block_start of address outside of heap");
1036 if (_young_gen->is_in_reserved(addr)) {
1037 assert(_young_gen->is_in(addr), "addr should be in allocated part of generation");
1038 return _young_gen->block_start(addr);
1039 }
1040
1041 assert(_old_gen->is_in_reserved(addr), "Some generation should contain the address");
1042 assert(_old_gen->is_in(addr), "addr should be in allocated part of generation");
1043 return _old_gen->block_start(addr);
1044 }
1045
1046 bool GenCollectedHeap::block_is_obj(const HeapWord* addr) const {
1047 assert(is_in_reserved(addr), "block_is_obj of address outside of heap");
1048 assert(block_start(addr) == addr, "addr must be a block start");
1049 if (_young_gen->is_in_reserved(addr)) {
1050 return _young_gen->block_is_obj(addr);
1051 }
1052
1053 assert(_old_gen->is_in_reserved(addr), "Some generation should contain the address");
1054 return _old_gen->block_is_obj(addr);
1055 }
1056
1057 bool GenCollectedHeap::supports_tlab_allocation() const {
1058 assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
1059 return _young_gen->supports_tlab_allocation();
1060 }
1061
1062 size_t GenCollectedHeap::tlab_capacity(Thread* thr) const {
1063 assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
1064 if (_young_gen->supports_tlab_allocation()) {
1065 return _young_gen->tlab_capacity();
1066 }
1067 return 0;
1068 }
1069
1070 size_t GenCollectedHeap::tlab_used(Thread* thr) const {
1071 assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
1072 if (_young_gen->supports_tlab_allocation()) {
1073 return _young_gen->tlab_used();
1074 }
1075 return 0;
1076 }
1077
1078 size_t GenCollectedHeap::unsafe_max_tlab_alloc(Thread* thr) const {
1079 assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
1080 if (_young_gen->supports_tlab_allocation()) {
1081 return _young_gen->unsafe_max_tlab_alloc();
1082 }
1083 return 0;
1084 }
1085
1086 HeapWord* GenCollectedHeap::allocate_new_tlab(size_t min_size,
1087 size_t requested_size,
1088 size_t* actual_size) {
1089 bool gc_overhead_limit_was_exceeded;
1090 HeapWord* result = mem_allocate_work(requested_size /* size */,
1091 true /* is_tlab */,
1092 &gc_overhead_limit_was_exceeded);
1093 if (result != NULL) {
1094 *actual_size = requested_size;
1095 }
1096
1097 return result;
1098 }
1099
1100 // Requires "*prev_ptr" to be non-NULL. Deletes and a block of minimal size
1101 // from the list headed by "*prev_ptr".
1102 static ScratchBlock *removeSmallestScratch(ScratchBlock **prev_ptr) {
1103 bool first = true;
1104 size_t min_size = 0; // "first" makes this conceptually infinite.
1105 ScratchBlock **smallest_ptr, *smallest;
1106 ScratchBlock *cur = *prev_ptr;
1107 while (cur) {
1108 assert(*prev_ptr == cur, "just checking");
1109 if (first || cur->num_words < min_size) {
1110 smallest_ptr = prev_ptr;
1111 smallest = cur;
1112 min_size = smallest->num_words;
1113 first = false;
1114 }
1115 prev_ptr = &cur->next;
1116 cur = cur->next;
1117 }
1118 smallest = *smallest_ptr;
1119 *smallest_ptr = smallest->next;
1120 return smallest;
1121 }
1122
1123 // Sort the scratch block list headed by res into decreasing size order,
1124 // and set "res" to the result.
1125 static void sort_scratch_list(ScratchBlock*& list) {
1126 ScratchBlock* sorted = NULL;
1127 ScratchBlock* unsorted = list;
1128 while (unsorted) {
1129 ScratchBlock *smallest = removeSmallestScratch(&unsorted);
1130 smallest->next = sorted;
1131 sorted = smallest;
1132 }
1133 list = sorted;
1134 }
1135
1136 ScratchBlock* GenCollectedHeap::gather_scratch(Generation* requestor,
1137 size_t max_alloc_words) {
1138 ScratchBlock* res = NULL;
1139 _young_gen->contribute_scratch(res, requestor, max_alloc_words);
1140 _old_gen->contribute_scratch(res, requestor, max_alloc_words);
1141 sort_scratch_list(res);
1142 return res;
1143 }
1144
1145 void GenCollectedHeap::release_scratch() {
1146 _young_gen->reset_scratch();
1147 _old_gen->reset_scratch();
1148 }
1149
1150 class GenPrepareForVerifyClosure: public GenCollectedHeap::GenClosure {
1151 void do_generation(Generation* gen) {
1152 gen->prepare_for_verify();
1153 }
1154 };
1155
1156 void GenCollectedHeap::prepare_for_verify() {
1157 ensure_parsability(false); // no need to retire TLABs
1158 GenPrepareForVerifyClosure blk;
1159 generation_iterate(&blk, false);
1160 }
1161
1162 void GenCollectedHeap::generation_iterate(GenClosure* cl,
1163 bool old_to_young) {
1164 if (old_to_young) {
1165 cl->do_generation(_old_gen);
1166 cl->do_generation(_young_gen);
1167 } else {
1168 cl->do_generation(_young_gen);
1169 cl->do_generation(_old_gen);
1170 }
1171 }
1172
1173 bool GenCollectedHeap::is_maximal_no_gc() const {
1174 return _young_gen->is_maximal_no_gc() && _old_gen->is_maximal_no_gc();
1175 }
1176
1177 void GenCollectedHeap::save_marks() {
1178 _young_gen->save_marks();
1179 _old_gen->save_marks();
1180 }
1181
1182 GenCollectedHeap* GenCollectedHeap::heap() {
1183 // SerialHeap is the only subtype of GenCollectedHeap.
1184 return named_heap<GenCollectedHeap>(CollectedHeap::Serial);
1185 }
1186
1187 #if INCLUDE_SERIALGC
1188 void GenCollectedHeap::prepare_for_compaction() {
1189 // Start by compacting into same gen.
1190 CompactPoint cp(_old_gen);
1191 _old_gen->prepare_for_compaction(&cp);
1192 _young_gen->prepare_for_compaction(&cp);
1193 }
1194 #endif // INCLUDE_SERIALGC
1195
1196 void GenCollectedHeap::verify(VerifyOption option /* ignored */) {
1197 log_debug(gc, verify)("%s", _old_gen->name());
1198 _old_gen->verify();
1199
1200 log_debug(gc, verify)("%s", _old_gen->name());
1201 _young_gen->verify();
1202
1203 log_debug(gc, verify)("RemSet");
1204 rem_set()->verify();
1205 }
1206
1207 void GenCollectedHeap::print_on(outputStream* st) const {
1208 if (_young_gen != NULL) {
1209 _young_gen->print_on(st);
1210 }
1211 if (_old_gen != NULL) {
1212 _old_gen->print_on(st);
1213 }
1214 MetaspaceUtils::print_on(st);
1215 }
1216
1217 void GenCollectedHeap::gc_threads_do(ThreadClosure* tc) const {
1218 }
1219
1220 bool GenCollectedHeap::print_location(outputStream* st, void* addr) const {
1221 return BlockLocationPrinter<GenCollectedHeap>::print_location(st, addr);
1222 }
1223
1224 void GenCollectedHeap::print_tracing_info() const {
1225 if (log_is_enabled(Debug, gc, heap, exit)) {
1226 LogStreamHandle(Debug, gc, heap, exit) lsh;
1227 _young_gen->print_summary_info_on(&lsh);
1228 _old_gen->print_summary_info_on(&lsh);
1229 }
1230 }
1231
1232 void GenCollectedHeap::print_heap_change(const PreGenGCValues& pre_gc_values) const {
1233 const DefNewGeneration* const def_new_gen = (DefNewGeneration*) young_gen();
1234
1235 log_info(gc, heap)(HEAP_CHANGE_FORMAT" "
1236 HEAP_CHANGE_FORMAT" "
1237 HEAP_CHANGE_FORMAT,
1238 HEAP_CHANGE_FORMAT_ARGS(def_new_gen->short_name(),
1239 pre_gc_values.young_gen_used(),
1240 pre_gc_values.young_gen_capacity(),
1241 def_new_gen->used(),
1242 def_new_gen->capacity()),
1243 HEAP_CHANGE_FORMAT_ARGS("Eden",
1244 pre_gc_values.eden_used(),
1245 pre_gc_values.eden_capacity(),
1246 def_new_gen->eden()->used(),
1247 def_new_gen->eden()->capacity()),
1248 HEAP_CHANGE_FORMAT_ARGS("From",
1249 pre_gc_values.from_used(),
1250 pre_gc_values.from_capacity(),
1251 def_new_gen->from()->used(),
1252 def_new_gen->from()->capacity()));
1253 log_info(gc, heap)(HEAP_CHANGE_FORMAT,
1254 HEAP_CHANGE_FORMAT_ARGS(old_gen()->short_name(),
1255 pre_gc_values.old_gen_used(),
1256 pre_gc_values.old_gen_capacity(),
1257 old_gen()->used(),
1258 old_gen()->capacity()));
1259 MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());
1260 }
1261
1262 class GenGCPrologueClosure: public GenCollectedHeap::GenClosure {
1263 private:
1264 bool _full;
1265 public:
1266 void do_generation(Generation* gen) {
1267 gen->gc_prologue(_full);
1268 }
1269 GenGCPrologueClosure(bool full) : _full(full) {};
1270 };
1271
1272 void GenCollectedHeap::gc_prologue(bool full) {
1273 assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");
1274
1275 // Fill TLAB's and such
1276 ensure_parsability(true); // retire TLABs
1277
1278 // Walk generations
1279 GenGCPrologueClosure blk(full);
1280 generation_iterate(&blk, false); // not old-to-young.
1281 };
1282
1283 class GenGCEpilogueClosure: public GenCollectedHeap::GenClosure {
1284 private:
1285 bool _full;
1286 public:
1287 void do_generation(Generation* gen) {
1288 gen->gc_epilogue(_full);
1289 }
1290 GenGCEpilogueClosure(bool full) : _full(full) {};
1291 };
1292
1293 void GenCollectedHeap::gc_epilogue(bool full) {
1294 #if COMPILER2_OR_JVMCI
1295 assert(DerivedPointerTable::is_empty(), "derived pointer present");
1296 size_t actual_gap = pointer_delta((HeapWord*) (max_uintx-3), *(end_addr()));
1297 guarantee(is_client_compilation_mode_vm() || actual_gap > (size_t)FastAllocateSizeLimit, "inline allocation wraps");
1298 #endif // COMPILER2_OR_JVMCI
1299
1300 resize_all_tlabs();
1301
1302 GenGCEpilogueClosure blk(full);
1303 generation_iterate(&blk, false); // not old-to-young.
1304
1305 if (!CleanChunkPoolAsync) {
1306 Chunk::clean_chunk_pool();
1307 }
1308
1309 MetaspaceCounters::update_performance_counters();
1310 CompressedClassSpaceCounters::update_performance_counters();
1311 };
1312
1313 #ifndef PRODUCT
1314 class GenGCSaveTopsBeforeGCClosure: public GenCollectedHeap::GenClosure {
1315 private:
1316 public:
1317 void do_generation(Generation* gen) {
1318 gen->record_spaces_top();
1319 }
1320 };
1321
1322 void GenCollectedHeap::record_gen_tops_before_GC() {
1323 if (ZapUnusedHeapArea) {
1324 GenGCSaveTopsBeforeGCClosure blk;
1325 generation_iterate(&blk, false); // not old-to-young.
1326 }
1327 }
1328 #endif // not PRODUCT
1329
1330 class GenEnsureParsabilityClosure: public GenCollectedHeap::GenClosure {
1331 public:
1332 void do_generation(Generation* gen) {
1333 gen->ensure_parsability();
1334 }
1335 };
1336
1337 void GenCollectedHeap::ensure_parsability(bool retire_tlabs) {
1338 CollectedHeap::ensure_parsability(retire_tlabs);
1339 GenEnsureParsabilityClosure ep_cl;
1340 generation_iterate(&ep_cl, false);
1341 }
1342
1343 oop GenCollectedHeap::handle_failed_promotion(Generation* old_gen,
1344 oop obj,
1345 size_t obj_size) {
1346 guarantee(old_gen == _old_gen, "We only get here with an old generation");
1347 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
1348 HeapWord* result = NULL;
1349
1350 result = old_gen->expand_and_allocate(obj_size, false);
1351
1352 if (result != NULL) {
1353 Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), result, obj_size);
1354 }
1355 return oop(result);
1356 }
--- EOF ---