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

Tue, 09 Oct 2012 10:09:34 -0700

author
mikael
date
Tue, 09 Oct 2012 10:09:34 -0700
changeset 4153
b9a9ed0f8eeb
parent 4098
8966c2d65d96
child 4176
4202510ee0fe
permissions
-rw-r--r--

7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp

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

mercurial