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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/symbolTable.hpp"
aoqi@0 27 #include "code/codeCache.hpp"
aoqi@0 28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
aoqi@0 29 #include "gc_implementation/parallelScavenge/gcTaskManager.hpp"
aoqi@0 30 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
aoqi@0 31 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
aoqi@0 32 #include "gc_implementation/parallelScavenge/psMarkSweep.hpp"
aoqi@0 33 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
aoqi@0 34 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
aoqi@0 35 #include "gc_implementation/parallelScavenge/psTasks.hpp"
aoqi@0 36 #include "gc_implementation/shared/gcHeapSummary.hpp"
aoqi@0 37 #include "gc_implementation/shared/gcTimer.hpp"
aoqi@0 38 #include "gc_implementation/shared/gcTrace.hpp"
aoqi@0 39 #include "gc_implementation/shared/gcTraceTime.hpp"
aoqi@0 40 #include "gc_implementation/shared/isGCActiveMark.hpp"
aoqi@0 41 #include "gc_implementation/shared/spaceDecorator.hpp"
aoqi@0 42 #include "gc_interface/gcCause.hpp"
aoqi@0 43 #include "memory/collectorPolicy.hpp"
aoqi@0 44 #include "memory/gcLocker.inline.hpp"
aoqi@0 45 #include "memory/referencePolicy.hpp"
aoqi@0 46 #include "memory/referenceProcessor.hpp"
aoqi@0 47 #include "memory/resourceArea.hpp"
aoqi@0 48 #include "oops/oop.inline.hpp"
aoqi@0 49 #include "oops/oop.psgc.inline.hpp"
aoqi@0 50 #include "runtime/biasedLocking.hpp"
aoqi@0 51 #include "runtime/fprofiler.hpp"
aoqi@0 52 #include "runtime/handles.inline.hpp"
aoqi@0 53 #include "runtime/threadCritical.hpp"
aoqi@0 54 #include "runtime/vmThread.hpp"
aoqi@0 55 #include "runtime/vm_operations.hpp"
aoqi@0 56 #include "services/memoryService.hpp"
aoqi@0 57 #include "utilities/stack.inline.hpp"
aoqi@0 58
aoqi@0 59 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 60
aoqi@0 61 HeapWord* PSScavenge::_to_space_top_before_gc = NULL;
aoqi@0 62 int PSScavenge::_consecutive_skipped_scavenges = 0;
aoqi@0 63 ReferenceProcessor* PSScavenge::_ref_processor = NULL;
aoqi@0 64 CardTableExtension* PSScavenge::_card_table = NULL;
aoqi@0 65 bool PSScavenge::_survivor_overflow = false;
aoqi@0 66 uint PSScavenge::_tenuring_threshold = 0;
aoqi@0 67 HeapWord* PSScavenge::_young_generation_boundary = NULL;
aoqi@0 68 uintptr_t PSScavenge::_young_generation_boundary_compressed = 0;
aoqi@0 69 elapsedTimer PSScavenge::_accumulated_time;
aoqi@0 70 STWGCTimer PSScavenge::_gc_timer;
aoqi@0 71 ParallelScavengeTracer PSScavenge::_gc_tracer;
aoqi@0 72 Stack<markOop, mtGC> PSScavenge::_preserved_mark_stack;
aoqi@0 73 Stack<oop, mtGC> PSScavenge::_preserved_oop_stack;
aoqi@0 74 CollectorCounters* PSScavenge::_counters = NULL;
aoqi@0 75
aoqi@0 76 // Define before use
aoqi@0 77 class PSIsAliveClosure: public BoolObjectClosure {
aoqi@0 78 public:
aoqi@0 79 bool do_object_b(oop p) {
aoqi@0 80 return (!PSScavenge::is_obj_in_young(p)) || p->is_forwarded();
aoqi@0 81 }
aoqi@0 82 };
aoqi@0 83
aoqi@0 84 PSIsAliveClosure PSScavenge::_is_alive_closure;
aoqi@0 85
aoqi@0 86 class PSKeepAliveClosure: public OopClosure {
aoqi@0 87 protected:
aoqi@0 88 MutableSpace* _to_space;
aoqi@0 89 PSPromotionManager* _promotion_manager;
aoqi@0 90
aoqi@0 91 public:
aoqi@0 92 PSKeepAliveClosure(PSPromotionManager* pm) : _promotion_manager(pm) {
aoqi@0 93 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 94 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 95 _to_space = heap->young_gen()->to_space();
aoqi@0 96
aoqi@0 97 assert(_promotion_manager != NULL, "Sanity");
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 template <class T> void do_oop_work(T* p) {
aoqi@0 101 assert (!oopDesc::is_null(*p), "expected non-null ref");
aoqi@0 102 assert ((oopDesc::load_decode_heap_oop_not_null(p))->is_oop(),
aoqi@0 103 "expected an oop while scanning weak refs");
aoqi@0 104
aoqi@0 105 // Weak refs may be visited more than once.
aoqi@0 106 if (PSScavenge::should_scavenge(p, _to_space)) {
aoqi@0 107 PSScavenge::copy_and_push_safe_barrier<T, /*promote_immediately=*/false>(_promotion_manager, p);
aoqi@0 108 }
aoqi@0 109 }
aoqi@0 110 virtual void do_oop(oop* p) { PSKeepAliveClosure::do_oop_work(p); }
aoqi@0 111 virtual void do_oop(narrowOop* p) { PSKeepAliveClosure::do_oop_work(p); }
aoqi@0 112 };
aoqi@0 113
aoqi@0 114 class PSEvacuateFollowersClosure: public VoidClosure {
aoqi@0 115 private:
aoqi@0 116 PSPromotionManager* _promotion_manager;
aoqi@0 117 public:
aoqi@0 118 PSEvacuateFollowersClosure(PSPromotionManager* pm) : _promotion_manager(pm) {}
aoqi@0 119
aoqi@0 120 virtual void do_void() {
aoqi@0 121 assert(_promotion_manager != NULL, "Sanity");
aoqi@0 122 _promotion_manager->drain_stacks(true);
aoqi@0 123 guarantee(_promotion_manager->stacks_empty(),
aoqi@0 124 "stacks should be empty at this point");
aoqi@0 125 }
aoqi@0 126 };
aoqi@0 127
aoqi@0 128 class PSPromotionFailedClosure : public ObjectClosure {
aoqi@0 129 virtual void do_object(oop obj) {
aoqi@0 130 if (obj->is_forwarded()) {
aoqi@0 131 obj->init_mark();
aoqi@0 132 }
aoqi@0 133 }
aoqi@0 134 };
aoqi@0 135
aoqi@0 136 class PSRefProcTaskProxy: public GCTask {
aoqi@0 137 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
aoqi@0 138 ProcessTask & _rp_task;
aoqi@0 139 uint _work_id;
aoqi@0 140 public:
aoqi@0 141 PSRefProcTaskProxy(ProcessTask & rp_task, uint work_id)
aoqi@0 142 : _rp_task(rp_task),
aoqi@0 143 _work_id(work_id)
aoqi@0 144 { }
aoqi@0 145
aoqi@0 146 private:
aoqi@0 147 virtual char* name() { return (char *)"Process referents by policy in parallel"; }
aoqi@0 148 virtual void do_it(GCTaskManager* manager, uint which);
aoqi@0 149 };
aoqi@0 150
aoqi@0 151 void PSRefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
aoqi@0 152 {
aoqi@0 153 PSPromotionManager* promotion_manager =
aoqi@0 154 PSPromotionManager::gc_thread_promotion_manager(which);
aoqi@0 155 assert(promotion_manager != NULL, "sanity check");
aoqi@0 156 PSKeepAliveClosure keep_alive(promotion_manager);
aoqi@0 157 PSEvacuateFollowersClosure evac_followers(promotion_manager);
aoqi@0 158 PSIsAliveClosure is_alive;
aoqi@0 159 _rp_task.work(_work_id, is_alive, keep_alive, evac_followers);
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 class PSRefEnqueueTaskProxy: public GCTask {
aoqi@0 163 typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask;
aoqi@0 164 EnqueueTask& _enq_task;
aoqi@0 165 uint _work_id;
aoqi@0 166
aoqi@0 167 public:
aoqi@0 168 PSRefEnqueueTaskProxy(EnqueueTask& enq_task, uint work_id)
aoqi@0 169 : _enq_task(enq_task),
aoqi@0 170 _work_id(work_id)
aoqi@0 171 { }
aoqi@0 172
aoqi@0 173 virtual char* name() { return (char *)"Enqueue reference objects in parallel"; }
aoqi@0 174 virtual void do_it(GCTaskManager* manager, uint which)
aoqi@0 175 {
aoqi@0 176 _enq_task.work(_work_id);
aoqi@0 177 }
aoqi@0 178 };
aoqi@0 179
aoqi@0 180 class PSRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
aoqi@0 181 virtual void execute(ProcessTask& task);
aoqi@0 182 virtual void execute(EnqueueTask& task);
aoqi@0 183 };
aoqi@0 184
aoqi@0 185 void PSRefProcTaskExecutor::execute(ProcessTask& task)
aoqi@0 186 {
aoqi@0 187 GCTaskQueue* q = GCTaskQueue::create();
aoqi@0 188 GCTaskManager* manager = ParallelScavengeHeap::gc_task_manager();
aoqi@0 189 for(uint i=0; i < manager->active_workers(); i++) {
aoqi@0 190 q->enqueue(new PSRefProcTaskProxy(task, i));
aoqi@0 191 }
aoqi@0 192 ParallelTaskTerminator terminator(manager->active_workers(),
aoqi@0 193 (TaskQueueSetSuper*) PSPromotionManager::stack_array_depth());
aoqi@0 194 if (task.marks_oops_alive() && manager->active_workers() > 1) {
aoqi@0 195 for (uint j = 0; j < manager->active_workers(); j++) {
aoqi@0 196 q->enqueue(new StealTask(&terminator));
aoqi@0 197 }
aoqi@0 198 }
aoqi@0 199 manager->execute_and_wait(q);
aoqi@0 200 }
aoqi@0 201
aoqi@0 202
aoqi@0 203 void PSRefProcTaskExecutor::execute(EnqueueTask& task)
aoqi@0 204 {
aoqi@0 205 GCTaskQueue* q = GCTaskQueue::create();
aoqi@0 206 GCTaskManager* manager = ParallelScavengeHeap::gc_task_manager();
aoqi@0 207 for(uint i=0; i < manager->active_workers(); i++) {
aoqi@0 208 q->enqueue(new PSRefEnqueueTaskProxy(task, i));
aoqi@0 209 }
aoqi@0 210 manager->execute_and_wait(q);
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 // This method contains all heap specific policy for invoking scavenge.
aoqi@0 214 // PSScavenge::invoke_no_policy() will do nothing but attempt to
aoqi@0 215 // scavenge. It will not clean up after failed promotions, bail out if
aoqi@0 216 // we've exceeded policy time limits, or any other special behavior.
aoqi@0 217 // All such policy should be placed here.
aoqi@0 218 //
aoqi@0 219 // Note that this method should only be called from the vm_thread while
aoqi@0 220 // at a safepoint!
aoqi@0 221 bool PSScavenge::invoke() {
aoqi@0 222 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
aoqi@0 223 assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
aoqi@0 224 assert(!Universe::heap()->is_gc_active(), "not reentrant");
aoqi@0 225
aoqi@0 226 ParallelScavengeHeap* const heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 227 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 228
aoqi@0 229 PSAdaptiveSizePolicy* policy = heap->size_policy();
aoqi@0 230 IsGCActiveMark mark;
aoqi@0 231
aoqi@0 232 const bool scavenge_done = PSScavenge::invoke_no_policy();
aoqi@0 233 const bool need_full_gc = !scavenge_done ||
aoqi@0 234 policy->should_full_GC(heap->old_gen()->free_in_bytes());
aoqi@0 235 bool full_gc_done = false;
aoqi@0 236
aoqi@0 237 if (UsePerfData) {
aoqi@0 238 PSGCAdaptivePolicyCounters* const counters = heap->gc_policy_counters();
aoqi@0 239 const int ffs_val = need_full_gc ? full_follows_scavenge : not_skipped;
aoqi@0 240 counters->update_full_follows_scavenge(ffs_val);
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 if (need_full_gc) {
aoqi@0 244 GCCauseSetter gccs(heap, GCCause::_adaptive_size_policy);
aoqi@0 245 CollectorPolicy* cp = heap->collector_policy();
aoqi@0 246 const bool clear_all_softrefs = cp->should_clear_all_soft_refs();
aoqi@0 247
aoqi@0 248 if (UseParallelOldGC) {
aoqi@0 249 full_gc_done = PSParallelCompact::invoke_no_policy(clear_all_softrefs);
aoqi@0 250 } else {
aoqi@0 251 full_gc_done = PSMarkSweep::invoke_no_policy(clear_all_softrefs);
aoqi@0 252 }
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 return full_gc_done;
aoqi@0 256 }
aoqi@0 257
aoqi@0 258 // This method contains no policy. You should probably
aoqi@0 259 // be calling invoke() instead.
aoqi@0 260 bool PSScavenge::invoke_no_policy() {
aoqi@0 261 assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
aoqi@0 262 assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
aoqi@0 263
aoqi@0 264 assert(_preserved_mark_stack.is_empty(), "should be empty");
aoqi@0 265 assert(_preserved_oop_stack.is_empty(), "should be empty");
aoqi@0 266
aoqi@0 267 _gc_timer.register_gc_start();
aoqi@0 268
aoqi@0 269 TimeStamp scavenge_entry;
aoqi@0 270 TimeStamp scavenge_midpoint;
aoqi@0 271 TimeStamp scavenge_exit;
aoqi@0 272
aoqi@0 273 scavenge_entry.update();
aoqi@0 274
aoqi@0 275 if (GC_locker::check_active_before_gc()) {
aoqi@0 276 return false;
aoqi@0 277 }
aoqi@0 278
aoqi@0 279 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 280 GCCause::Cause gc_cause = heap->gc_cause();
aoqi@0 281 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 282
aoqi@0 283 // Check for potential problems.
aoqi@0 284 if (!should_attempt_scavenge()) {
aoqi@0 285 return false;
aoqi@0 286 }
aoqi@0 287
aoqi@0 288 _gc_tracer.report_gc_start(heap->gc_cause(), _gc_timer.gc_start());
aoqi@0 289
aoqi@0 290 bool promotion_failure_occurred = false;
aoqi@0 291
aoqi@0 292 PSYoungGen* young_gen = heap->young_gen();
aoqi@0 293 PSOldGen* old_gen = heap->old_gen();
aoqi@0 294 PSAdaptiveSizePolicy* size_policy = heap->size_policy();
aoqi@0 295
aoqi@0 296 heap->increment_total_collections();
aoqi@0 297
aoqi@0 298 AdaptiveSizePolicyOutput(size_policy, heap->total_collections());
aoqi@0 299
aoqi@0 300 if ((gc_cause != GCCause::_java_lang_system_gc) ||
aoqi@0 301 UseAdaptiveSizePolicyWithSystemGC) {
aoqi@0 302 // Gather the feedback data for eden occupancy.
aoqi@0 303 young_gen->eden_space()->accumulate_statistics();
aoqi@0 304 }
aoqi@0 305
aoqi@0 306 if (ZapUnusedHeapArea) {
aoqi@0 307 // Save information needed to minimize mangling
aoqi@0 308 heap->record_gen_tops_before_GC();
aoqi@0 309 }
aoqi@0 310
aoqi@0 311 heap->print_heap_before_gc();
aoqi@0 312 heap->trace_heap_before_gc(&_gc_tracer);
aoqi@0 313
aoqi@0 314 assert(!NeverTenure || _tenuring_threshold == markOopDesc::max_age + 1, "Sanity");
aoqi@0 315 assert(!AlwaysTenure || _tenuring_threshold == 0, "Sanity");
aoqi@0 316
aoqi@0 317 size_t prev_used = heap->used();
aoqi@0 318
aoqi@0 319 // Fill in TLABs
aoqi@0 320 heap->accumulate_statistics_all_tlabs();
aoqi@0 321 heap->ensure_parsability(true); // retire TLABs
aoqi@0 322
aoqi@0 323 if (VerifyBeforeGC && heap->total_collections() >= VerifyGCStartAt) {
aoqi@0 324 HandleMark hm; // Discard invalid handles created during verification
aoqi@0 325 Universe::verify(" VerifyBeforeGC:");
aoqi@0 326 }
aoqi@0 327
aoqi@0 328 {
aoqi@0 329 ResourceMark rm;
aoqi@0 330 HandleMark hm;
aoqi@0 331
aoqi@0 332 gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps);
aoqi@0 333 TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty);
aoqi@0 334 GCTraceTime t1(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, NULL);
aoqi@0 335 TraceCollectorStats tcs(counters());
aoqi@0 336 TraceMemoryManagerStats tms(false /* not full GC */,gc_cause);
aoqi@0 337
aoqi@0 338 if (TraceGen0Time) accumulated_time()->start();
aoqi@0 339
aoqi@0 340 // Let the size policy know we're starting
aoqi@0 341 size_policy->minor_collection_begin();
aoqi@0 342
aoqi@0 343 // Verify the object start arrays.
aoqi@0 344 if (VerifyObjectStartArray &&
aoqi@0 345 VerifyBeforeGC) {
aoqi@0 346 old_gen->verify_object_start_array();
aoqi@0 347 }
aoqi@0 348
aoqi@0 349 // Verify no unmarked old->young roots
aoqi@0 350 if (VerifyRememberedSets) {
aoqi@0 351 CardTableExtension::verify_all_young_refs_imprecise();
aoqi@0 352 }
aoqi@0 353
aoqi@0 354 if (!ScavengeWithObjectsInToSpace) {
aoqi@0 355 assert(young_gen->to_space()->is_empty(),
aoqi@0 356 "Attempt to scavenge with live objects in to_space");
aoqi@0 357 young_gen->to_space()->clear(SpaceDecorator::Mangle);
aoqi@0 358 } else if (ZapUnusedHeapArea) {
aoqi@0 359 young_gen->to_space()->mangle_unused_area();
aoqi@0 360 }
aoqi@0 361 save_to_space_top_before_gc();
aoqi@0 362
aoqi@0 363 COMPILER2_PRESENT(DerivedPointerTable::clear());
aoqi@0 364
aoqi@0 365 reference_processor()->enable_discovery(true /*verify_disabled*/, true /*verify_no_refs*/);
aoqi@0 366 reference_processor()->setup_policy(false);
aoqi@0 367
aoqi@0 368 // We track how much was promoted to the next generation for
aoqi@0 369 // the AdaptiveSizePolicy.
aoqi@0 370 size_t old_gen_used_before = old_gen->used_in_bytes();
aoqi@0 371
aoqi@0 372 // For PrintGCDetails
aoqi@0 373 size_t young_gen_used_before = young_gen->used_in_bytes();
aoqi@0 374
aoqi@0 375 // Reset our survivor overflow.
aoqi@0 376 set_survivor_overflow(false);
aoqi@0 377
aoqi@0 378 // We need to save the old top values before
aoqi@0 379 // creating the promotion_manager. We pass the top
aoqi@0 380 // values to the card_table, to prevent it from
aoqi@0 381 // straying into the promotion labs.
aoqi@0 382 HeapWord* old_top = old_gen->object_space()->top();
aoqi@0 383
aoqi@0 384 // Release all previously held resources
aoqi@0 385 gc_task_manager()->release_all_resources();
aoqi@0 386
aoqi@0 387 // Set the number of GC threads to be used in this collection
aoqi@0 388 gc_task_manager()->set_active_gang();
aoqi@0 389 gc_task_manager()->task_idle_workers();
aoqi@0 390 // Get the active number of workers here and use that value
aoqi@0 391 // throughout the methods.
aoqi@0 392 uint active_workers = gc_task_manager()->active_workers();
aoqi@0 393 heap->set_par_threads(active_workers);
aoqi@0 394
aoqi@0 395 PSPromotionManager::pre_scavenge();
aoqi@0 396
aoqi@0 397 // We'll use the promotion manager again later.
aoqi@0 398 PSPromotionManager* promotion_manager = PSPromotionManager::vm_thread_promotion_manager();
aoqi@0 399 {
aoqi@0 400 GCTraceTime tm("Scavenge", false, false, &_gc_timer);
aoqi@0 401 ParallelScavengeHeap::ParStrongRootsScope psrs;
aoqi@0 402
aoqi@0 403 GCTaskQueue* q = GCTaskQueue::create();
aoqi@0 404
aoqi@0 405 if (!old_gen->object_space()->is_empty()) {
aoqi@0 406 // There are only old-to-young pointers if there are objects
aoqi@0 407 // in the old gen.
aoqi@0 408 uint stripe_total = active_workers;
aoqi@0 409 for(uint i=0; i < stripe_total; i++) {
aoqi@0 410 q->enqueue(new OldToYoungRootsTask(old_gen, old_top, i, stripe_total));
aoqi@0 411 }
aoqi@0 412 }
aoqi@0 413
aoqi@0 414 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::universe));
aoqi@0 415 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::jni_handles));
aoqi@0 416 // We scan the thread roots in parallel
aoqi@0 417 Threads::create_thread_roots_tasks(q);
aoqi@0 418 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::object_synchronizer));
aoqi@0 419 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::flat_profiler));
aoqi@0 420 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::management));
aoqi@0 421 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::system_dictionary));
aoqi@0 422 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::class_loader_data));
aoqi@0 423 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::jvmti));
aoqi@0 424 q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::code_cache));
aoqi@0 425
aoqi@0 426 ParallelTaskTerminator terminator(
aoqi@0 427 active_workers,
aoqi@0 428 (TaskQueueSetSuper*) promotion_manager->stack_array_depth());
aoqi@0 429 if (active_workers > 1) {
aoqi@0 430 for (uint j = 0; j < active_workers; j++) {
aoqi@0 431 q->enqueue(new StealTask(&terminator));
aoqi@0 432 }
aoqi@0 433 }
aoqi@0 434
aoqi@0 435 gc_task_manager()->execute_and_wait(q);
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 scavenge_midpoint.update();
aoqi@0 439
aoqi@0 440 // Process reference objects discovered during scavenge
aoqi@0 441 {
aoqi@0 442 GCTraceTime tm("References", false, false, &_gc_timer);
aoqi@0 443
aoqi@0 444 reference_processor()->setup_policy(false); // not always_clear
aoqi@0 445 reference_processor()->set_active_mt_degree(active_workers);
aoqi@0 446 PSKeepAliveClosure keep_alive(promotion_manager);
aoqi@0 447 PSEvacuateFollowersClosure evac_followers(promotion_manager);
aoqi@0 448 ReferenceProcessorStats stats;
aoqi@0 449 if (reference_processor()->processing_is_mt()) {
aoqi@0 450 PSRefProcTaskExecutor task_executor;
aoqi@0 451 stats = reference_processor()->process_discovered_references(
aoqi@0 452 &_is_alive_closure, &keep_alive, &evac_followers, &task_executor,
aoqi@0 453 &_gc_timer);
aoqi@0 454 } else {
aoqi@0 455 stats = reference_processor()->process_discovered_references(
aoqi@0 456 &_is_alive_closure, &keep_alive, &evac_followers, NULL, &_gc_timer);
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 _gc_tracer.report_gc_reference_stats(stats);
aoqi@0 460
aoqi@0 461 // Enqueue reference objects discovered during scavenge.
aoqi@0 462 if (reference_processor()->processing_is_mt()) {
aoqi@0 463 PSRefProcTaskExecutor task_executor;
aoqi@0 464 reference_processor()->enqueue_discovered_references(&task_executor);
aoqi@0 465 } else {
aoqi@0 466 reference_processor()->enqueue_discovered_references(NULL);
aoqi@0 467 }
aoqi@0 468 }
aoqi@0 469
aoqi@0 470 {
aoqi@0 471 GCTraceTime tm("StringTable", false, false, &_gc_timer);
aoqi@0 472 // Unlink any dead interned Strings and process the remaining live ones.
aoqi@0 473 PSScavengeRootsClosure root_closure(promotion_manager);
aoqi@0 474 StringTable::unlink_or_oops_do(&_is_alive_closure, &root_closure);
aoqi@0 475 }
aoqi@0 476
aoqi@0 477 // Finally, flush the promotion_manager's labs, and deallocate its stacks.
aoqi@0 478 promotion_failure_occurred = PSPromotionManager::post_scavenge(_gc_tracer);
aoqi@0 479 if (promotion_failure_occurred) {
aoqi@0 480 clean_up_failed_promotion();
aoqi@0 481 if (PrintGC) {
aoqi@0 482 gclog_or_tty->print("--");
aoqi@0 483 }
aoqi@0 484 }
aoqi@0 485
aoqi@0 486 // Let the size policy know we're done. Note that we count promotion
aoqi@0 487 // failure cleanup time as part of the collection (otherwise, we're
aoqi@0 488 // implicitly saying it's mutator time).
aoqi@0 489 size_policy->minor_collection_end(gc_cause);
aoqi@0 490
aoqi@0 491 if (!promotion_failure_occurred) {
aoqi@0 492 // Swap the survivor spaces.
aoqi@0 493 young_gen->eden_space()->clear(SpaceDecorator::Mangle);
aoqi@0 494 young_gen->from_space()->clear(SpaceDecorator::Mangle);
aoqi@0 495 young_gen->swap_spaces();
aoqi@0 496
aoqi@0 497 size_t survived = young_gen->from_space()->used_in_bytes();
aoqi@0 498 size_t promoted = old_gen->used_in_bytes() - old_gen_used_before;
aoqi@0 499 size_policy->update_averages(_survivor_overflow, survived, promoted);
aoqi@0 500
aoqi@0 501 // A successful scavenge should restart the GC time limit count which is
aoqi@0 502 // for full GC's.
aoqi@0 503 size_policy->reset_gc_overhead_limit_count();
aoqi@0 504 if (UseAdaptiveSizePolicy) {
aoqi@0 505 // Calculate the new survivor size and tenuring threshold
aoqi@0 506
aoqi@0 507 if (PrintAdaptiveSizePolicy) {
aoqi@0 508 gclog_or_tty->print("AdaptiveSizeStart: ");
aoqi@0 509 gclog_or_tty->stamp();
aoqi@0 510 gclog_or_tty->print_cr(" collection: %d ",
aoqi@0 511 heap->total_collections());
aoqi@0 512
aoqi@0 513 if (Verbose) {
aoqi@0 514 gclog_or_tty->print("old_gen_capacity: %d young_gen_capacity: %d",
aoqi@0 515 old_gen->capacity_in_bytes(), young_gen->capacity_in_bytes());
aoqi@0 516 }
aoqi@0 517 }
aoqi@0 518
aoqi@0 519
aoqi@0 520 if (UsePerfData) {
aoqi@0 521 PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();
aoqi@0 522 counters->update_old_eden_size(
aoqi@0 523 size_policy->calculated_eden_size_in_bytes());
aoqi@0 524 counters->update_old_promo_size(
aoqi@0 525 size_policy->calculated_promo_size_in_bytes());
aoqi@0 526 counters->update_old_capacity(old_gen->capacity_in_bytes());
aoqi@0 527 counters->update_young_capacity(young_gen->capacity_in_bytes());
aoqi@0 528 counters->update_survived(survived);
aoqi@0 529 counters->update_promoted(promoted);
aoqi@0 530 counters->update_survivor_overflowed(_survivor_overflow);
aoqi@0 531 }
aoqi@0 532
aoqi@0 533 size_t max_young_size = young_gen->max_size();
aoqi@0 534
aoqi@0 535 // Deciding a free ratio in the young generation is tricky, so if
aoqi@0 536 // MinHeapFreeRatio or MaxHeapFreeRatio are in use (implicating
aoqi@0 537 // that the old generation size may have been limited because of them) we
aoqi@0 538 // should then limit our young generation size using NewRatio to have it
aoqi@0 539 // follow the old generation size.
aoqi@0 540 if (MinHeapFreeRatio != 0 || MaxHeapFreeRatio != 100) {
aoqi@0 541 max_young_size = MIN2(old_gen->capacity_in_bytes() / NewRatio, young_gen->max_size());
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 size_t survivor_limit =
aoqi@0 545 size_policy->max_survivor_size(max_young_size);
aoqi@0 546 _tenuring_threshold =
aoqi@0 547 size_policy->compute_survivor_space_size_and_threshold(
aoqi@0 548 _survivor_overflow,
aoqi@0 549 _tenuring_threshold,
aoqi@0 550 survivor_limit);
aoqi@0 551
aoqi@0 552 if (PrintTenuringDistribution) {
aoqi@0 553 gclog_or_tty->cr();
aoqi@0 554 gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u (max %u)",
aoqi@0 555 size_policy->calculated_survivor_size_in_bytes(),
aoqi@0 556 _tenuring_threshold, MaxTenuringThreshold);
aoqi@0 557 }
aoqi@0 558
aoqi@0 559 if (UsePerfData) {
aoqi@0 560 PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();
aoqi@0 561 counters->update_tenuring_threshold(_tenuring_threshold);
aoqi@0 562 counters->update_survivor_size_counters();
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 // Do call at minor collections?
aoqi@0 566 // Don't check if the size_policy is ready at this
aoqi@0 567 // level. Let the size_policy check that internally.
aoqi@0 568 if (UseAdaptiveGenerationSizePolicyAtMinorCollection &&
aoqi@0 569 ((gc_cause != GCCause::_java_lang_system_gc) ||
aoqi@0 570 UseAdaptiveSizePolicyWithSystemGC)) {
aoqi@0 571
aoqi@0 572 // Calculate optimial free space amounts
aoqi@0 573 assert(young_gen->max_size() >
aoqi@0 574 young_gen->from_space()->capacity_in_bytes() +
aoqi@0 575 young_gen->to_space()->capacity_in_bytes(),
aoqi@0 576 "Sizes of space in young gen are out-of-bounds");
aoqi@0 577
aoqi@0 578 size_t young_live = young_gen->used_in_bytes();
aoqi@0 579 size_t eden_live = young_gen->eden_space()->used_in_bytes();
aoqi@0 580 size_t cur_eden = young_gen->eden_space()->capacity_in_bytes();
aoqi@0 581 size_t max_old_gen_size = old_gen->max_gen_size();
aoqi@0 582 size_t max_eden_size = max_young_size -
aoqi@0 583 young_gen->from_space()->capacity_in_bytes() -
aoqi@0 584 young_gen->to_space()->capacity_in_bytes();
aoqi@0 585
aoqi@0 586 // Used for diagnostics
aoqi@0 587 size_policy->clear_generation_free_space_flags();
aoqi@0 588
aoqi@0 589 size_policy->compute_eden_space_size(young_live,
aoqi@0 590 eden_live,
aoqi@0 591 cur_eden,
aoqi@0 592 max_eden_size,
aoqi@0 593 false /* not full gc*/);
aoqi@0 594
aoqi@0 595 size_policy->check_gc_overhead_limit(young_live,
aoqi@0 596 eden_live,
aoqi@0 597 max_old_gen_size,
aoqi@0 598 max_eden_size,
aoqi@0 599 false /* not full gc*/,
aoqi@0 600 gc_cause,
aoqi@0 601 heap->collector_policy());
aoqi@0 602
aoqi@0 603 size_policy->decay_supplemental_growth(false /* not full gc*/);
aoqi@0 604 }
aoqi@0 605 // Resize the young generation at every collection
aoqi@0 606 // even if new sizes have not been calculated. This is
aoqi@0 607 // to allow resizes that may have been inhibited by the
aoqi@0 608 // relative location of the "to" and "from" spaces.
aoqi@0 609
aoqi@0 610 // Resizing the old gen at minor collects can cause increases
aoqi@0 611 // that don't feed back to the generation sizing policy until
aoqi@0 612 // a major collection. Don't resize the old gen here.
aoqi@0 613
aoqi@0 614 heap->resize_young_gen(size_policy->calculated_eden_size_in_bytes(),
aoqi@0 615 size_policy->calculated_survivor_size_in_bytes());
aoqi@0 616
aoqi@0 617 if (PrintAdaptiveSizePolicy) {
aoqi@0 618 gclog_or_tty->print_cr("AdaptiveSizeStop: collection: %d ",
aoqi@0 619 heap->total_collections());
aoqi@0 620 }
aoqi@0 621 }
aoqi@0 622
aoqi@0 623 // Update the structure of the eden. With NUMA-eden CPU hotplugging or offlining can
aoqi@0 624 // cause the change of the heap layout. Make sure eden is reshaped if that's the case.
aoqi@0 625 // Also update() will case adaptive NUMA chunk resizing.
aoqi@0 626 assert(young_gen->eden_space()->is_empty(), "eden space should be empty now");
aoqi@0 627 young_gen->eden_space()->update();
aoqi@0 628
aoqi@0 629 heap->gc_policy_counters()->update_counters();
aoqi@0 630
aoqi@0 631 heap->resize_all_tlabs();
aoqi@0 632
aoqi@0 633 assert(young_gen->to_space()->is_empty(), "to space should be empty now");
aoqi@0 634 }
aoqi@0 635
aoqi@0 636 COMPILER2_PRESENT(DerivedPointerTable::update_pointers());
aoqi@0 637
aoqi@0 638 NOT_PRODUCT(reference_processor()->verify_no_references_recorded());
aoqi@0 639
aoqi@0 640 {
aoqi@0 641 GCTraceTime tm("Prune Scavenge Root Methods", false, false, &_gc_timer);
aoqi@0 642
aoqi@0 643 CodeCache::prune_scavenge_root_nmethods();
aoqi@0 644 }
aoqi@0 645
aoqi@0 646 // Re-verify object start arrays
aoqi@0 647 if (VerifyObjectStartArray &&
aoqi@0 648 VerifyAfterGC) {
aoqi@0 649 old_gen->verify_object_start_array();
aoqi@0 650 }
aoqi@0 651
aoqi@0 652 // Verify all old -> young cards are now precise
aoqi@0 653 if (VerifyRememberedSets) {
aoqi@0 654 // Precise verification will give false positives. Until this is fixed,
aoqi@0 655 // use imprecise verification.
aoqi@0 656 // CardTableExtension::verify_all_young_refs_precise();
aoqi@0 657 CardTableExtension::verify_all_young_refs_imprecise();
aoqi@0 658 }
aoqi@0 659
aoqi@0 660 if (TraceGen0Time) accumulated_time()->stop();
aoqi@0 661
aoqi@0 662 if (PrintGC) {
aoqi@0 663 if (PrintGCDetails) {
aoqi@0 664 // Don't print a GC timestamp here. This is after the GC so
aoqi@0 665 // would be confusing.
aoqi@0 666 young_gen->print_used_change(young_gen_used_before);
aoqi@0 667 }
aoqi@0 668 heap->print_heap_change(prev_used);
aoqi@0 669 }
aoqi@0 670
aoqi@0 671 // Track memory usage and detect low memory
aoqi@0 672 MemoryService::track_memory_usage();
aoqi@0 673 heap->update_counters();
aoqi@0 674
aoqi@0 675 gc_task_manager()->release_idle_workers();
aoqi@0 676 }
aoqi@0 677
aoqi@0 678 if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
aoqi@0 679 HandleMark hm; // Discard invalid handles created during verification
aoqi@0 680 Universe::verify(" VerifyAfterGC:");
aoqi@0 681 }
aoqi@0 682
aoqi@0 683 heap->print_heap_after_gc();
aoqi@0 684 heap->trace_heap_after_gc(&_gc_tracer);
aoqi@0 685 _gc_tracer.report_tenuring_threshold(tenuring_threshold());
aoqi@0 686
aoqi@0 687 if (ZapUnusedHeapArea) {
aoqi@0 688 young_gen->eden_space()->check_mangled_unused_area_complete();
aoqi@0 689 young_gen->from_space()->check_mangled_unused_area_complete();
aoqi@0 690 young_gen->to_space()->check_mangled_unused_area_complete();
aoqi@0 691 }
aoqi@0 692
aoqi@0 693 scavenge_exit.update();
aoqi@0 694
aoqi@0 695 if (PrintGCTaskTimeStamps) {
aoqi@0 696 tty->print_cr("VM-Thread " INT64_FORMAT " " INT64_FORMAT " " INT64_FORMAT,
aoqi@0 697 scavenge_entry.ticks(), scavenge_midpoint.ticks(),
aoqi@0 698 scavenge_exit.ticks());
aoqi@0 699 gc_task_manager()->print_task_time_stamps();
aoqi@0 700 }
aoqi@0 701
aoqi@0 702 #ifdef TRACESPINNING
aoqi@0 703 ParallelTaskTerminator::print_termination_counts();
aoqi@0 704 #endif
aoqi@0 705
aoqi@0 706
aoqi@0 707 _gc_timer.register_gc_end();
aoqi@0 708
aoqi@0 709 _gc_tracer.report_gc_end(_gc_timer.gc_end(), _gc_timer.time_partitions());
aoqi@0 710
aoqi@0 711 return !promotion_failure_occurred;
aoqi@0 712 }
aoqi@0 713
aoqi@0 714 // This method iterates over all objects in the young generation,
aoqi@0 715 // unforwarding markOops. It then restores any preserved mark oops,
aoqi@0 716 // and clears the _preserved_mark_stack.
aoqi@0 717 void PSScavenge::clean_up_failed_promotion() {
aoqi@0 718 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 719 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 720
aoqi@0 721 PSYoungGen* young_gen = heap->young_gen();
aoqi@0 722
aoqi@0 723 {
aoqi@0 724 ResourceMark rm;
aoqi@0 725
aoqi@0 726 // Unforward all pointers in the young gen.
aoqi@0 727 PSPromotionFailedClosure unforward_closure;
aoqi@0 728 young_gen->object_iterate(&unforward_closure);
aoqi@0 729
aoqi@0 730 if (PrintGC && Verbose) {
aoqi@0 731 gclog_or_tty->print_cr("Restoring %d marks", _preserved_oop_stack.size());
aoqi@0 732 }
aoqi@0 733
aoqi@0 734 // Restore any saved marks.
aoqi@0 735 while (!_preserved_oop_stack.is_empty()) {
aoqi@0 736 oop obj = _preserved_oop_stack.pop();
aoqi@0 737 markOop mark = _preserved_mark_stack.pop();
aoqi@0 738 obj->set_mark(mark);
aoqi@0 739 }
aoqi@0 740
aoqi@0 741 // Clear the preserved mark and oop stack caches.
aoqi@0 742 _preserved_mark_stack.clear(true);
aoqi@0 743 _preserved_oop_stack.clear(true);
aoqi@0 744 }
aoqi@0 745
aoqi@0 746 // Reset the PromotionFailureALot counters.
aoqi@0 747 NOT_PRODUCT(Universe::heap()->reset_promotion_should_fail();)
aoqi@0 748 }
aoqi@0 749
aoqi@0 750 // This method is called whenever an attempt to promote an object
aoqi@0 751 // fails. Some markOops will need preservation, some will not. Note
aoqi@0 752 // that the entire eden is traversed after a failed promotion, with
aoqi@0 753 // all forwarded headers replaced by the default markOop. This means
aoqi@0 754 // it is not necessary to preserve most markOops.
aoqi@0 755 void PSScavenge::oop_promotion_failed(oop obj, markOop obj_mark) {
aoqi@0 756 if (obj_mark->must_be_preserved_for_promotion_failure(obj)) {
aoqi@0 757 // Should use per-worker private stacks here rather than
aoqi@0 758 // locking a common pair of stacks.
aoqi@0 759 ThreadCritical tc;
aoqi@0 760 _preserved_oop_stack.push(obj);
aoqi@0 761 _preserved_mark_stack.push(obj_mark);
aoqi@0 762 }
aoqi@0 763 }
aoqi@0 764
aoqi@0 765 bool PSScavenge::should_attempt_scavenge() {
aoqi@0 766 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 767 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 768 PSGCAdaptivePolicyCounters* counters = heap->gc_policy_counters();
aoqi@0 769
aoqi@0 770 if (UsePerfData) {
aoqi@0 771 counters->update_scavenge_skipped(not_skipped);
aoqi@0 772 }
aoqi@0 773
aoqi@0 774 PSYoungGen* young_gen = heap->young_gen();
aoqi@0 775 PSOldGen* old_gen = heap->old_gen();
aoqi@0 776
aoqi@0 777 if (!ScavengeWithObjectsInToSpace) {
aoqi@0 778 // Do not attempt to promote unless to_space is empty
aoqi@0 779 if (!young_gen->to_space()->is_empty()) {
aoqi@0 780 _consecutive_skipped_scavenges++;
aoqi@0 781 if (UsePerfData) {
aoqi@0 782 counters->update_scavenge_skipped(to_space_not_empty);
aoqi@0 783 }
aoqi@0 784 return false;
aoqi@0 785 }
aoqi@0 786 }
aoqi@0 787
aoqi@0 788 // Test to see if the scavenge will likely fail.
aoqi@0 789 PSAdaptiveSizePolicy* policy = heap->size_policy();
aoqi@0 790
aoqi@0 791 // A similar test is done in the policy's should_full_GC(). If this is
aoqi@0 792 // changed, decide if that test should also be changed.
aoqi@0 793 size_t avg_promoted = (size_t) policy->padded_average_promoted_in_bytes();
aoqi@0 794 size_t promotion_estimate = MIN2(avg_promoted, young_gen->used_in_bytes());
aoqi@0 795 bool result = promotion_estimate < old_gen->free_in_bytes();
aoqi@0 796
aoqi@0 797 if (PrintGCDetails && Verbose) {
aoqi@0 798 gclog_or_tty->print(result ? " do scavenge: " : " skip scavenge: ");
aoqi@0 799 gclog_or_tty->print_cr(" average_promoted " SIZE_FORMAT
aoqi@0 800 " padded_average_promoted " SIZE_FORMAT
aoqi@0 801 " free in old gen " SIZE_FORMAT,
aoqi@0 802 (size_t) policy->average_promoted_in_bytes(),
aoqi@0 803 (size_t) policy->padded_average_promoted_in_bytes(),
aoqi@0 804 old_gen->free_in_bytes());
aoqi@0 805 if (young_gen->used_in_bytes() <
aoqi@0 806 (size_t) policy->padded_average_promoted_in_bytes()) {
aoqi@0 807 gclog_or_tty->print_cr(" padded_promoted_average is greater"
aoqi@0 808 " than maximum promotion = " SIZE_FORMAT, young_gen->used_in_bytes());
aoqi@0 809 }
aoqi@0 810 }
aoqi@0 811
aoqi@0 812 if (result) {
aoqi@0 813 _consecutive_skipped_scavenges = 0;
aoqi@0 814 } else {
aoqi@0 815 _consecutive_skipped_scavenges++;
aoqi@0 816 if (UsePerfData) {
aoqi@0 817 counters->update_scavenge_skipped(promoted_too_large);
aoqi@0 818 }
aoqi@0 819 }
aoqi@0 820 return result;
aoqi@0 821 }
aoqi@0 822
aoqi@0 823 // Used to add tasks
aoqi@0 824 GCTaskManager* const PSScavenge::gc_task_manager() {
aoqi@0 825 assert(ParallelScavengeHeap::gc_task_manager() != NULL,
aoqi@0 826 "shouldn't return NULL");
aoqi@0 827 return ParallelScavengeHeap::gc_task_manager();
aoqi@0 828 }
aoqi@0 829
aoqi@0 830 void PSScavenge::initialize() {
aoqi@0 831 // Arguments must have been parsed
aoqi@0 832
aoqi@0 833 if (AlwaysTenure) {
aoqi@0 834 _tenuring_threshold = 0;
aoqi@0 835 } else if (NeverTenure) {
aoqi@0 836 _tenuring_threshold = markOopDesc::max_age + 1;
aoqi@0 837 } else {
aoqi@0 838 // We want to smooth out our startup times for the AdaptiveSizePolicy
aoqi@0 839 _tenuring_threshold = (UseAdaptiveSizePolicy) ? InitialTenuringThreshold :
aoqi@0 840 MaxTenuringThreshold;
aoqi@0 841 }
aoqi@0 842
aoqi@0 843 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
aoqi@0 844 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
aoqi@0 845
aoqi@0 846 PSYoungGen* young_gen = heap->young_gen();
aoqi@0 847 PSOldGen* old_gen = heap->old_gen();
aoqi@0 848
aoqi@0 849 // Set boundary between young_gen and old_gen
aoqi@0 850 assert(old_gen->reserved().end() <= young_gen->eden_space()->bottom(),
aoqi@0 851 "old above young");
aoqi@0 852 set_young_generation_boundary(young_gen->eden_space()->bottom());
aoqi@0 853
aoqi@0 854 // Initialize ref handling object for scavenging.
aoqi@0 855 MemRegion mr = young_gen->reserved();
aoqi@0 856
aoqi@0 857 _ref_processor =
aoqi@0 858 new ReferenceProcessor(mr, // span
aoqi@0 859 ParallelRefProcEnabled && (ParallelGCThreads > 1), // mt processing
aoqi@0 860 (int) ParallelGCThreads, // mt processing degree
aoqi@0 861 true, // mt discovery
aoqi@0 862 (int) ParallelGCThreads, // mt discovery degree
aoqi@0 863 true, // atomic_discovery
aoqi@0 864 NULL); // header provides liveness info
aoqi@0 865
aoqi@0 866 // Cache the cardtable
aoqi@0 867 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 868 assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
aoqi@0 869 _card_table = (CardTableExtension*)bs;
aoqi@0 870
aoqi@0 871 _counters = new CollectorCounters("PSScavenge", 0);
aoqi@0 872 }

mercurial