src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp

Mon, 31 Mar 2014 17:09:38 +0200

author
ehelin
date
Mon, 31 Mar 2014 17:09:38 +0200
changeset 6609
270d7cb38f40
parent 6131
86e6d691f2e1
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8038934: Remove prefix allocated_ from methods and variables in Metaspace
Reviewed-by: jmasa, coleenp

duke@435 1 /*
tamao@5120 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/symbolTable.hpp"
stefank@2314 27 #include "classfile/systemDictionary.hpp"
stefank@2314 28 #include "code/codeCache.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
stefank@2314 30 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
stefank@2314 31 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp"
stefank@2314 32 #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp"
stefank@2314 33 #include "gc_implementation/parallelScavenge/psOldGen.hpp"
stefank@2314 34 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
stefank@2314 35 #include "gc_implementation/parallelScavenge/psYoungGen.hpp"
sla@5237 36 #include "gc_implementation/shared/gcHeapSummary.hpp"
sla@5237 37 #include "gc_implementation/shared/gcTimer.hpp"
sla@5237 38 #include "gc_implementation/shared/gcTrace.hpp"
sla@5237 39 #include "gc_implementation/shared/gcTraceTime.hpp"
stefank@2314 40 #include "gc_implementation/shared/isGCActiveMark.hpp"
coleenp@4037 41 #include "gc_implementation/shared/markSweep.hpp"
stefank@2314 42 #include "gc_implementation/shared/spaceDecorator.hpp"
stefank@2314 43 #include "gc_interface/gcCause.hpp"
stefank@2314 44 #include "memory/gcLocker.inline.hpp"
stefank@2314 45 #include "memory/referencePolicy.hpp"
stefank@2314 46 #include "memory/referenceProcessor.hpp"
stefank@2314 47 #include "oops/oop.inline.hpp"
stefank@2314 48 #include "runtime/biasedLocking.hpp"
stefank@2314 49 #include "runtime/fprofiler.hpp"
stefank@2314 50 #include "runtime/safepoint.hpp"
stefank@2314 51 #include "runtime/vmThread.hpp"
stefank@2314 52 #include "services/management.hpp"
stefank@2314 53 #include "services/memoryService.hpp"
stefank@2314 54 #include "utilities/events.hpp"
stefank@2314 55 #include "utilities/stack.inline.hpp"
duke@435 56
duke@435 57 elapsedTimer PSMarkSweep::_accumulated_time;
duke@435 58 jlong PSMarkSweep::_time_of_last_gc = 0;
duke@435 59 CollectorCounters* PSMarkSweep::_counters = NULL;
duke@435 60
duke@435 61 void PSMarkSweep::initialize() {
duke@435 62 MemRegion mr = Universe::heap()->reserved_region();
ysr@2651 63 _ref_processor = new ReferenceProcessor(mr); // a vanilla ref proc
jcoomes@809 64 _counters = new CollectorCounters("PSMarkSweep", 1);
duke@435 65 }
duke@435 66
duke@435 67 // This method contains all heap specific policy for invoking mark sweep.
duke@435 68 // PSMarkSweep::invoke_no_policy() will only attempt to mark-sweep-compact
duke@435 69 // the heap. It will do nothing further. If we need to bail out for policy
duke@435 70 // reasons, scavenge before full gc, or any other specialized behavior, it
duke@435 71 // needs to be added here.
duke@435 72 //
duke@435 73 // Note that this method should only be called from the vm_thread while
duke@435 74 // at a safepoint!
jmasa@1822 75 //
jmasa@1822 76 // Note that the all_soft_refs_clear flag in the collector policy
jmasa@1822 77 // may be true because this method can be called without intervening
jmasa@1822 78 // activity. For example when the heap space is tight and full measure
jmasa@1822 79 // are being taken to free space.
jmasa@1822 80
duke@435 81 void PSMarkSweep::invoke(bool maximum_heap_compaction) {
duke@435 82 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
duke@435 83 assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
duke@435 84 assert(!Universe::heap()->is_gc_active(), "not reentrant");
duke@435 85
duke@435 86 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 87 GCCause::Cause gc_cause = heap->gc_cause();
duke@435 88 PSAdaptiveSizePolicy* policy = heap->size_policy();
jmasa@1822 89 IsGCActiveMark mark;
duke@435 90
jmasa@1822 91 if (ScavengeBeforeFullGC) {
jmasa@1822 92 PSScavenge::invoke_no_policy();
jmasa@1822 93 }
duke@435 94
jmasa@1822 95 const bool clear_all_soft_refs =
jmasa@1822 96 heap->collector_policy()->should_clear_all_soft_refs();
duke@435 97
tschatzl@5119 98 uint count = maximum_heap_compaction ? 1 : MarkSweepAlwaysCompactCount;
tschatzl@5119 99 UIntFlagSetting flag_setting(MarkSweepAlwaysCompactCount, count);
jmasa@1822 100 PSMarkSweep::invoke_no_policy(clear_all_soft_refs || maximum_heap_compaction);
duke@435 101 }
duke@435 102
duke@435 103 // This method contains no policy. You should probably
duke@435 104 // be calling invoke() instead.
jcoomes@3540 105 bool PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) {
duke@435 106 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
duke@435 107 assert(ref_processor() != NULL, "Sanity");
duke@435 108
duke@435 109 if (GC_locker::check_active_before_gc()) {
jcoomes@3540 110 return false;
duke@435 111 }
duke@435 112
duke@435 113 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
sla@5237 114 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 115 GCCause::Cause gc_cause = heap->gc_cause();
sla@5237 116
mgronlun@6131 117 _gc_timer->register_gc_start();
sla@5237 118 _gc_tracer->report_gc_start(gc_cause, _gc_timer->gc_start());
sla@5237 119
duke@435 120 PSAdaptiveSizePolicy* size_policy = heap->size_policy();
duke@435 121
jmasa@1822 122 // The scope of casr should end after code that can change
jmasa@1822 123 // CollectorPolicy::_should_clear_all_soft_refs.
jmasa@1822 124 ClearedAllSoftRefs casr(clear_all_softrefs, heap->collector_policy());
jmasa@1822 125
duke@435 126 PSYoungGen* young_gen = heap->young_gen();
duke@435 127 PSOldGen* old_gen = heap->old_gen();
duke@435 128
duke@435 129 // Increment the invocation count
duke@435 130 heap->increment_total_collections(true /* full */);
duke@435 131
jmasa@698 132 // Save information needed to minimize mangling
jmasa@698 133 heap->record_gen_tops_before_GC();
jmasa@698 134
duke@435 135 // We need to track unique mark sweep invocations as well.
duke@435 136 _total_invocations++;
duke@435 137
duke@435 138 AdaptiveSizePolicyOutput(size_policy, heap->total_collections());
duke@435 139
never@3499 140 heap->print_heap_before_gc();
sla@5237 141 heap->trace_heap_before_gc(_gc_tracer);
duke@435 142
duke@435 143 // Fill in TLABs
duke@435 144 heap->accumulate_statistics_all_tlabs();
duke@435 145 heap->ensure_parsability(true); // retire TLABs
duke@435 146
duke@435 147 if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {
duke@435 148 HandleMark hm; // Discard invalid handles created during verification
stefank@5018 149 Universe::verify(" VerifyBeforeGC:");
duke@435 150 }
duke@435 151
duke@435 152 // Verify object start arrays
duke@435 153 if (VerifyObjectStartArray &&
duke@435 154 VerifyBeforeGC) {
duke@435 155 old_gen->verify_object_start_array();
duke@435 156 }
duke@435 157
sla@5237 158 heap->pre_full_gc_dump(_gc_timer);
ysr@1050 159
duke@435 160 // Filled in below to track the state of the young gen after the collection.
duke@435 161 bool eden_empty;
duke@435 162 bool survivors_empty;
duke@435 163 bool young_gen_empty;
duke@435 164
duke@435 165 {
duke@435 166 HandleMark hm;
brutisso@3767 167
duke@435 168 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
duke@435 169 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
sla@5237 170 GCTraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, NULL);
duke@435 171 TraceCollectorStats tcs(counters());
fparain@2888 172 TraceMemoryManagerStats tms(true /* Full GC */,gc_cause);
duke@435 173
duke@435 174 if (TraceGen1Time) accumulated_time()->start();
duke@435 175
duke@435 176 // Let the size policy know we're starting
duke@435 177 size_policy->major_collection_begin();
duke@435 178
duke@435 179 CodeCache::gc_prologue();
duke@435 180 Threads::gc_prologue();
duke@435 181 BiasedLocking::preserve_marks();
duke@435 182
duke@435 183 // Capture heap size before collection for printing.
duke@435 184 size_t prev_used = heap->used();
duke@435 185
coleenp@4037 186 // Capture metadata size before collection for sizing.
ehelin@6609 187 size_t metadata_prev_used = MetaspaceAux::used_bytes();
duke@435 188
duke@435 189 // For PrintGCDetails
duke@435 190 size_t old_gen_prev_used = old_gen->used_in_bytes();
duke@435 191 size_t young_gen_prev_used = young_gen->used_in_bytes();
duke@435 192
duke@435 193 allocate_stacks();
duke@435 194
duke@435 195 COMPILER2_PRESENT(DerivedPointerTable::clear());
duke@435 196
johnc@3175 197 ref_processor()->enable_discovery(true /*verify_disabled*/, true /*verify_no_refs*/);
ysr@892 198 ref_processor()->setup_policy(clear_all_softrefs);
duke@435 199
duke@435 200 mark_sweep_phase1(clear_all_softrefs);
duke@435 201
duke@435 202 mark_sweep_phase2();
duke@435 203
duke@435 204 // Don't add any more derived pointers during phase3
duke@435 205 COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity"));
duke@435 206 COMPILER2_PRESENT(DerivedPointerTable::set_active(false));
duke@435 207
duke@435 208 mark_sweep_phase3();
duke@435 209
duke@435 210 mark_sweep_phase4();
duke@435 211
duke@435 212 restore_marks();
duke@435 213
duke@435 214 deallocate_stacks();
duke@435 215
jmasa@698 216 if (ZapUnusedHeapArea) {
jmasa@698 217 // Do a complete mangle (top to end) because the usage for
jmasa@698 218 // scratch does not maintain a top pointer.
jmasa@698 219 young_gen->to_space()->mangle_unused_area_complete();
jmasa@698 220 }
jmasa@698 221
duke@435 222 eden_empty = young_gen->eden_space()->is_empty();
duke@435 223 if (!eden_empty) {
duke@435 224 eden_empty = absorb_live_data_from_eden(size_policy, young_gen, old_gen);
duke@435 225 }
duke@435 226
duke@435 227 // Update heap occupancy information which is used as
duke@435 228 // input to soft ref clearing policy at the next gc.
duke@435 229 Universe::update_heap_info_at_gc();
duke@435 230
duke@435 231 survivors_empty = young_gen->from_space()->is_empty() &&
jmasa@698 232 young_gen->to_space()->is_empty();
duke@435 233 young_gen_empty = eden_empty && survivors_empty;
duke@435 234
duke@435 235 BarrierSet* bs = heap->barrier_set();
duke@435 236 if (bs->is_a(BarrierSet::ModRef)) {
duke@435 237 ModRefBarrierSet* modBS = (ModRefBarrierSet*)bs;
duke@435 238 MemRegion old_mr = heap->old_gen()->reserved();
duke@435 239 if (young_gen_empty) {
coleenp@4037 240 modBS->clear(MemRegion(old_mr.start(), old_mr.end()));
duke@435 241 } else {
coleenp@4037 242 modBS->invalidate(MemRegion(old_mr.start(), old_mr.end()));
duke@435 243 }
duke@435 244 }
duke@435 245
coleenp@4037 246 // Delete metaspaces for unloaded class loaders and clean up loader_data graph
coleenp@4037 247 ClassLoaderDataGraph::purge();
jmasa@5015 248 MetaspaceAux::verify_metrics();
coleenp@4037 249
duke@435 250 BiasedLocking::restore_marks();
duke@435 251 Threads::gc_epilogue();
duke@435 252 CodeCache::gc_epilogue();
kamg@2467 253 JvmtiExport::gc_epilogue();
duke@435 254
duke@435 255 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
duke@435 256
duke@435 257 ref_processor()->enqueue_discovered_references(NULL);
duke@435 258
duke@435 259 // Update time of last GC
duke@435 260 reset_millis_since_last_gc();
duke@435 261
duke@435 262 // Let the size policy know we're done
duke@435 263 size_policy->major_collection_end(old_gen->used_in_bytes(), gc_cause);
duke@435 264
duke@435 265 if (UseAdaptiveSizePolicy) {
duke@435 266
duke@435 267 if (PrintAdaptiveSizePolicy) {
duke@435 268 gclog_or_tty->print("AdaptiveSizeStart: ");
duke@435 269 gclog_or_tty->stamp();
duke@435 270 gclog_or_tty->print_cr(" collection: %d ",
duke@435 271 heap->total_collections());
duke@435 272 if (Verbose) {
coleenp@4037 273 gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d",
coleenp@4037 274 old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes());
duke@435 275 }
duke@435 276 }
duke@435 277
duke@435 278 // Don't check if the size_policy is ready here. Let
duke@435 279 // the size_policy check that internally.
duke@435 280 if (UseAdaptiveGenerationSizePolicyAtMajorCollection &&
duke@435 281 ((gc_cause != GCCause::_java_lang_system_gc) ||
duke@435 282 UseAdaptiveSizePolicyWithSystemGC)) {
duke@435 283 // Calculate optimal free space amounts
duke@435 284 assert(young_gen->max_size() >
duke@435 285 young_gen->from_space()->capacity_in_bytes() +
duke@435 286 young_gen->to_space()->capacity_in_bytes(),
duke@435 287 "Sizes of space in young gen are out-of-bounds");
tamao@5120 288
tamao@5120 289 size_t young_live = young_gen->used_in_bytes();
tamao@5120 290 size_t eden_live = young_gen->eden_space()->used_in_bytes();
tamao@5120 291 size_t old_live = old_gen->used_in_bytes();
tamao@5120 292 size_t cur_eden = young_gen->eden_space()->capacity_in_bytes();
tamao@5120 293 size_t max_old_gen_size = old_gen->max_gen_size();
duke@435 294 size_t max_eden_size = young_gen->max_size() -
duke@435 295 young_gen->from_space()->capacity_in_bytes() -
duke@435 296 young_gen->to_space()->capacity_in_bytes();
tamao@5120 297
tamao@5120 298 // Used for diagnostics
tamao@5120 299 size_policy->clear_generation_free_space_flags();
tamao@5120 300
tamao@5192 301 size_policy->compute_generations_free_space(young_live,
tamao@5192 302 eden_live,
tamao@5192 303 old_live,
tamao@5192 304 cur_eden,
tamao@5192 305 max_old_gen_size,
tamao@5192 306 max_eden_size,
tamao@5192 307 true /* full gc*/);
tamao@5120 308
tamao@5120 309 size_policy->check_gc_overhead_limit(young_live,
tamao@5120 310 eden_live,
tamao@5120 311 max_old_gen_size,
tamao@5120 312 max_eden_size,
tamao@5120 313 true /* full gc*/,
tamao@5120 314 gc_cause,
tamao@5120 315 heap->collector_policy());
tamao@5120 316
tamao@5120 317 size_policy->decay_supplemental_growth(true /* full gc*/);
duke@435 318
duke@435 319 heap->resize_old_gen(size_policy->calculated_old_free_size_in_bytes());
duke@435 320
duke@435 321 // Don't resize the young generation at an major collection. A
duke@435 322 // desired young generation size may have been calculated but
duke@435 323 // resizing the young generation complicates the code because the
duke@435 324 // resizing of the old generation may have moved the boundary
duke@435 325 // between the young generation and the old generation. Let the
duke@435 326 // young generation resizing happen at the minor collections.
duke@435 327 }
duke@435 328 if (PrintAdaptiveSizePolicy) {
duke@435 329 gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ",
duke@435 330 heap->total_collections());
duke@435 331 }
duke@435 332 }
duke@435 333
duke@435 334 if (UsePerfData) {
duke@435 335 heap->gc_policy_counters()->update_counters();
duke@435 336 heap->gc_policy_counters()->update_old_capacity(
duke@435 337 old_gen->capacity_in_bytes());
duke@435 338 heap->gc_policy_counters()->update_young_capacity(
duke@435 339 young_gen->capacity_in_bytes());
duke@435 340 }
duke@435 341
duke@435 342 heap->resize_all_tlabs();
duke@435 343
coleenp@4037 344 // We collected the heap, recalculate the metaspace capacity
coleenp@4037 345 MetaspaceGC::compute_new_size();
duke@435 346
duke@435 347 if (TraceGen1Time) accumulated_time()->stop();
duke@435 348
duke@435 349 if (PrintGC) {
duke@435 350 if (PrintGCDetails) {
duke@435 351 // Don't print a GC timestamp here. This is after the GC so
duke@435 352 // would be confusing.
duke@435 353 young_gen->print_used_change(young_gen_prev_used);
duke@435 354 old_gen->print_used_change(old_gen_prev_used);
duke@435 355 }
duke@435 356 heap->print_heap_change(prev_used);
duke@435 357 if (PrintGCDetails) {
coleenp@4037 358 MetaspaceAux::print_metaspace_change(metadata_prev_used);
duke@435 359 }
duke@435 360 }
duke@435 361
duke@435 362 // Track memory usage and detect low memory
duke@435 363 MemoryService::track_memory_usage();
duke@435 364 heap->update_counters();
duke@435 365 }
duke@435 366
duke@435 367 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
duke@435 368 HandleMark hm; // Discard invalid handles created during verification
stefank@5018 369 Universe::verify(" VerifyAfterGC:");
duke@435 370 }
duke@435 371
duke@435 372 // Re-verify object start arrays
duke@435 373 if (VerifyObjectStartArray &&
duke@435 374 VerifyAfterGC) {
duke@435 375 old_gen->verify_object_start_array();
duke@435 376 }
duke@435 377
jmasa@698 378 if (ZapUnusedHeapArea) {
jmasa@698 379 old_gen->object_space()->check_mangled_unused_area_complete();
jmasa@698 380 }
jmasa@698 381
duke@435 382 NOT_PRODUCT(ref_processor()->verify_no_references_recorded());
duke@435 383
never@3499 384 heap->print_heap_after_gc();
sla@5237 385 heap->trace_heap_after_gc(_gc_tracer);
jmasa@981 386
sla@5237 387 heap->post_full_gc_dump(_gc_timer);
ysr@1050 388
jmasa@981 389 #ifdef TRACESPINNING
jmasa@981 390 ParallelTaskTerminator::print_termination_counts();
jmasa@981 391 #endif
jcoomes@3540 392
mgronlun@6131 393 _gc_timer->register_gc_end();
sla@5237 394
sla@5237 395 _gc_tracer->report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions());
sla@5237 396
jcoomes@3540 397 return true;
duke@435 398 }
duke@435 399
duke@435 400 bool PSMarkSweep::absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
duke@435 401 PSYoungGen* young_gen,
duke@435 402 PSOldGen* old_gen) {
duke@435 403 MutableSpace* const eden_space = young_gen->eden_space();
duke@435 404 assert(!eden_space->is_empty(), "eden must be non-empty");
duke@435 405 assert(young_gen->virtual_space()->alignment() ==
duke@435 406 old_gen->virtual_space()->alignment(), "alignments do not match");
duke@435 407
duke@435 408 if (!(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary)) {
duke@435 409 return false;
duke@435 410 }
duke@435 411
duke@435 412 // Both generations must be completely committed.
duke@435 413 if (young_gen->virtual_space()->uncommitted_size() != 0) {
duke@435 414 return false;
duke@435 415 }
duke@435 416 if (old_gen->virtual_space()->uncommitted_size() != 0) {
duke@435 417 return false;
duke@435 418 }
duke@435 419
duke@435 420 // Figure out how much to take from eden. Include the average amount promoted
duke@435 421 // in the total; otherwise the next young gen GC will simply bail out to a
duke@435 422 // full GC.
duke@435 423 const size_t alignment = old_gen->virtual_space()->alignment();
duke@435 424 const size_t eden_used = eden_space->used_in_bytes();
jcoomes@916 425 const size_t promoted = (size_t)size_policy->avg_promoted()->padded_average();
duke@435 426 const size_t absorb_size = align_size_up(eden_used + promoted, alignment);
duke@435 427 const size_t eden_capacity = eden_space->capacity_in_bytes();
duke@435 428
duke@435 429 if (absorb_size >= eden_capacity) {
duke@435 430 return false; // Must leave some space in eden.
duke@435 431 }
duke@435 432
duke@435 433 const size_t new_young_size = young_gen->capacity_in_bytes() - absorb_size;
duke@435 434 if (new_young_size < young_gen->min_gen_size()) {
duke@435 435 return false; // Respect young gen minimum size.
duke@435 436 }
duke@435 437
duke@435 438 if (TraceAdaptiveGCBoundary && Verbose) {
duke@435 439 gclog_or_tty->print(" absorbing " SIZE_FORMAT "K: "
duke@435 440 "eden " SIZE_FORMAT "K->" SIZE_FORMAT "K "
duke@435 441 "from " SIZE_FORMAT "K, to " SIZE_FORMAT "K "
duke@435 442 "young_gen " SIZE_FORMAT "K->" SIZE_FORMAT "K ",
duke@435 443 absorb_size / K,
duke@435 444 eden_capacity / K, (eden_capacity - absorb_size) / K,
duke@435 445 young_gen->from_space()->used_in_bytes() / K,
duke@435 446 young_gen->to_space()->used_in_bytes() / K,
duke@435 447 young_gen->capacity_in_bytes() / K, new_young_size / K);
duke@435 448 }
duke@435 449
duke@435 450 // Fill the unused part of the old gen.
duke@435 451 MutableSpace* const old_space = old_gen->object_space();
jcoomes@916 452 HeapWord* const unused_start = old_space->top();
jcoomes@916 453 size_t const unused_words = pointer_delta(old_space->end(), unused_start);
duke@435 454
jcoomes@916 455 if (unused_words > 0) {
jcoomes@916 456 if (unused_words < CollectedHeap::min_fill_size()) {
jcoomes@916 457 return false; // If the old gen cannot be filled, must give up.
jcoomes@916 458 }
jcoomes@916 459 CollectedHeap::fill_with_objects(unused_start, unused_words);
duke@435 460 }
duke@435 461
duke@435 462 // Take the live data from eden and set both top and end in the old gen to
duke@435 463 // eden top. (Need to set end because reset_after_change() mangles the region
duke@435 464 // from end to virtual_space->high() in debug builds).
duke@435 465 HeapWord* const new_top = eden_space->top();
duke@435 466 old_gen->virtual_space()->expand_into(young_gen->virtual_space(),
duke@435 467 absorb_size);
duke@435 468 young_gen->reset_after_change();
duke@435 469 old_space->set_top(new_top);
duke@435 470 old_space->set_end(new_top);
duke@435 471 old_gen->reset_after_change();
duke@435 472
duke@435 473 // Update the object start array for the filler object and the data from eden.
duke@435 474 ObjectStartArray* const start_array = old_gen->start_array();
jcoomes@916 475 for (HeapWord* p = unused_start; p < new_top; p += oop(p)->size()) {
jcoomes@916 476 start_array->allocate_block(p);
duke@435 477 }
duke@435 478
duke@435 479 // Could update the promoted average here, but it is not typically updated at
duke@435 480 // full GCs and the value to use is unclear. Something like
duke@435 481 //
duke@435 482 // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
duke@435 483
duke@435 484 size_policy->set_bytes_absorbed_from_eden(absorb_size);
duke@435 485 return true;
duke@435 486 }
duke@435 487
duke@435 488 void PSMarkSweep::allocate_stacks() {
duke@435 489 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 490 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 491
duke@435 492 PSYoungGen* young_gen = heap->young_gen();
duke@435 493
duke@435 494 MutableSpace* to_space = young_gen->to_space();
duke@435 495 _preserved_marks = (PreservedMark*)to_space->top();
duke@435 496 _preserved_count = 0;
duke@435 497
duke@435 498 // We want to calculate the size in bytes first.
duke@435 499 _preserved_count_max = pointer_delta(to_space->end(), to_space->top(), sizeof(jbyte));
duke@435 500 // Now divide by the size of a PreservedMark
duke@435 501 _preserved_count_max /= sizeof(PreservedMark);
duke@435 502 }
duke@435 503
duke@435 504
duke@435 505 void PSMarkSweep::deallocate_stacks() {
jcoomes@2191 506 _preserved_mark_stack.clear(true);
jcoomes@2191 507 _preserved_oop_stack.clear(true);
jcoomes@2191 508 _marking_stack.clear();
jcoomes@2191 509 _objarray_stack.clear(true);
duke@435 510 }
duke@435 511
duke@435 512 void PSMarkSweep::mark_sweep_phase1(bool clear_all_softrefs) {
duke@435 513 // Recursively traverse all live objects and mark them
sla@5237 514 GCTraceTime tm("phase 1", PrintGCDetails && Verbose, true, _gc_timer);
duke@435 515 trace(" 1");
duke@435 516
duke@435 517 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 518 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 519
coleenp@4037 520 // Need to clear claim bits before the tracing starts.
coleenp@4037 521 ClassLoaderDataGraph::clear_claimed_marks();
coleenp@4037 522
duke@435 523 // General strong roots.
jrose@1424 524 {
jrose@1424 525 ParallelScavengeHeap::ParStrongRootsScope psrs;
jrose@1424 526 Universe::oops_do(mark_and_push_closure());
jrose@1424 527 JNIHandles::oops_do(mark_and_push_closure()); // Global (strong) JNI handles
stefank@4298 528 CLDToOopClosure mark_and_push_from_cld(mark_and_push_closure());
jrose@1424 529 CodeBlobToOopClosure each_active_code_blob(mark_and_push_closure(), /*do_marking=*/ true);
stefank@4298 530 Threads::oops_do(mark_and_push_closure(), &mark_and_push_from_cld, &each_active_code_blob);
jrose@1424 531 ObjectSynchronizer::oops_do(mark_and_push_closure());
jrose@1424 532 FlatProfiler::oops_do(mark_and_push_closure());
jrose@1424 533 Management::oops_do(mark_and_push_closure());
jrose@1424 534 JvmtiExport::oops_do(mark_and_push_closure());
jrose@1424 535 SystemDictionary::always_strong_oops_do(mark_and_push_closure());
coleenp@4037 536 ClassLoaderDataGraph::always_strong_oops_do(mark_and_push_closure(), follow_klass_closure(), true);
jrose@1424 537 // Do not treat nmethods as strong roots for mark/sweep, since we can unload them.
jrose@1424 538 //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(mark_and_push_closure()));
jrose@1424 539 }
duke@435 540
duke@435 541 // Flush marking stack.
duke@435 542 follow_stack();
duke@435 543
duke@435 544 // Process reference objects found during marking
duke@435 545 {
ysr@892 546 ref_processor()->setup_policy(clear_all_softrefs);
sla@5237 547 const ReferenceProcessorStats& stats =
sla@5237 548 ref_processor()->process_discovered_references(
sla@5237 549 is_alive_closure(), mark_and_push_closure(), follow_stack_closure(), NULL, _gc_timer);
sla@5237 550 gc_tracer()->report_gc_reference_stats(stats);
duke@435 551 }
duke@435 552
stefank@5020 553 // This is the point where the entire marking should have completed.
stefank@5020 554 assert(_marking_stack.is_empty(), "Marking should have completed");
stefank@5020 555
stefank@5020 556 // Unload classes and purge the SystemDictionary.
duke@435 557 bool purged_class = SystemDictionary::do_unloading(is_alive_closure());
duke@435 558
stefank@5020 559 // Unload nmethods.
brutisso@4098 560 CodeCache::do_unloading(is_alive_closure(), purged_class);
duke@435 561
stefank@5020 562 // Prune dead klasses from subklass/sibling/implementor lists.
stefank@5020 563 Klass::clean_weak_klass_links(is_alive_closure());
ysr@1376 564
stefank@5020 565 // Delete entries for dead interned strings.
duke@435 566 StringTable::unlink(is_alive_closure());
stefank@5020 567
coleenp@2497 568 // Clean up unreferenced symbols in symbol table.
coleenp@2497 569 SymbolTable::unlink();
sla@5237 570 _gc_tracer->report_object_count_after_gc(is_alive_closure());
duke@435 571 }
duke@435 572
duke@435 573
duke@435 574 void PSMarkSweep::mark_sweep_phase2() {
sla@5237 575 GCTraceTime tm("phase 2", PrintGCDetails && Verbose, true, _gc_timer);
duke@435 576 trace("2");
duke@435 577
duke@435 578 // Now all live objects are marked, compute the new object addresses.
duke@435 579
duke@435 580 // It is not required that we traverse spaces in the same order in
duke@435 581 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
duke@435 582 // tracking expects us to do so. See comment under phase4.
duke@435 583
duke@435 584 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 585 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 586
duke@435 587 PSOldGen* old_gen = heap->old_gen();
duke@435 588
duke@435 589 // Begin compacting into the old gen
duke@435 590 PSMarkSweepDecorator::set_destination_decorator_tenured();
duke@435 591
duke@435 592 // This will also compact the young gen spaces.
duke@435 593 old_gen->precompact();
duke@435 594 }
duke@435 595
duke@435 596 // This should be moved to the shared markSweep code!
duke@435 597 class PSAlwaysTrueClosure: public BoolObjectClosure {
duke@435 598 public:
duke@435 599 bool do_object_b(oop p) { return true; }
duke@435 600 };
duke@435 601 static PSAlwaysTrueClosure always_true;
duke@435 602
duke@435 603 void PSMarkSweep::mark_sweep_phase3() {
duke@435 604 // Adjust the pointers to reflect the new locations
sla@5237 605 GCTraceTime tm("phase 3", PrintGCDetails && Verbose, true, _gc_timer);
duke@435 606 trace("3");
duke@435 607
duke@435 608 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 609 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 610
duke@435 611 PSYoungGen* young_gen = heap->young_gen();
duke@435 612 PSOldGen* old_gen = heap->old_gen();
coleenp@4037 613
coleenp@4037 614 // Need to clear claim bits before the tracing starts.
coleenp@4037 615 ClassLoaderDataGraph::clear_claimed_marks();
duke@435 616
duke@435 617 // General strong roots.
stefank@5011 618 Universe::oops_do(adjust_pointer_closure());
stefank@5011 619 JNIHandles::oops_do(adjust_pointer_closure()); // Global (strong) JNI handles
stefank@5011 620 CLDToOopClosure adjust_from_cld(adjust_pointer_closure());
stefank@5011 621 Threads::oops_do(adjust_pointer_closure(), &adjust_from_cld, NULL);
stefank@5011 622 ObjectSynchronizer::oops_do(adjust_pointer_closure());
stefank@5011 623 FlatProfiler::oops_do(adjust_pointer_closure());
stefank@5011 624 Management::oops_do(adjust_pointer_closure());
stefank@5011 625 JvmtiExport::oops_do(adjust_pointer_closure());
duke@435 626 // SO_AllClasses
stefank@5011 627 SystemDictionary::oops_do(adjust_pointer_closure());
stefank@5011 628 ClassLoaderDataGraph::oops_do(adjust_pointer_closure(), adjust_klass_closure(), true);
duke@435 629
duke@435 630 // Now adjust pointers in remaining weak roots. (All of which should
duke@435 631 // have been cleared if they pointed to non-surviving objects.)
duke@435 632 // Global (weak) JNI handles
stefank@5011 633 JNIHandles::weak_oops_do(&always_true, adjust_pointer_closure());
duke@435 634
duke@435 635 CodeCache::oops_do(adjust_pointer_closure());
stefank@5011 636 StringTable::oops_do(adjust_pointer_closure());
stefank@5011 637 ref_processor()->weak_oops_do(adjust_pointer_closure());
stefank@5011 638 PSScavenge::reference_processor()->weak_oops_do(adjust_pointer_closure());
duke@435 639
duke@435 640 adjust_marks();
duke@435 641
duke@435 642 young_gen->adjust_pointers();
duke@435 643 old_gen->adjust_pointers();
duke@435 644 }
duke@435 645
duke@435 646 void PSMarkSweep::mark_sweep_phase4() {
duke@435 647 EventMark m("4 compact heap");
sla@5237 648 GCTraceTime tm("phase 4", PrintGCDetails && Verbose, true, _gc_timer);
duke@435 649 trace("4");
duke@435 650
duke@435 651 // All pointers are now adjusted, move objects accordingly
duke@435 652
duke@435 653 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 654 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
duke@435 655
duke@435 656 PSYoungGen* young_gen = heap->young_gen();
duke@435 657 PSOldGen* old_gen = heap->old_gen();
duke@435 658
duke@435 659 old_gen->compact();
duke@435 660 young_gen->compact();
duke@435 661 }
duke@435 662
duke@435 663 jlong PSMarkSweep::millis_since_last_gc() {
johnc@3339 664 // We need a monotonically non-deccreasing time in ms but
johnc@3339 665 // os::javaTimeMillis() does not guarantee monotonicity.
johnc@3339 666 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
johnc@3339 667 jlong ret_val = now - _time_of_last_gc;
duke@435 668 // XXX See note in genCollectedHeap::millis_since_last_gc().
duke@435 669 if (ret_val < 0) {
johnc@3339 670 NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);)
duke@435 671 return 0;
duke@435 672 }
duke@435 673 return ret_val;
duke@435 674 }
duke@435 675
duke@435 676 void PSMarkSweep::reset_millis_since_last_gc() {
johnc@3339 677 // We need a monotonically non-deccreasing time in ms but
johnc@3339 678 // os::javaTimeMillis() does not guarantee monotonicity.
johnc@3339 679 _time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
duke@435 680 }

mercurial