3706 #endif // YOUNG_LIST_VERBOSE
3707
3708 init_mutator_alloc_region();
3709
3710 {
3711 size_t expand_bytes = g1_policy()->expansion_amount();
3712 if (expand_bytes > 0) {
3713 size_t bytes_before = capacity();
3714 if (!expand(expand_bytes)) {
3715 // We failed to expand the heap so let's verify that
3716 // committed/uncommitted amount match the backing store
3717 assert(capacity() == _g1_storage.committed_size(), "committed size mismatch");
3718 assert(max_capacity() == _g1_storage.reserved_size(), "reserved size mismatch");
3719 }
3720 }
3721 }
3722
3723 double end_time_sec = os::elapsedTime();
3724 double pause_time_ms = (end_time_sec - start_time_sec) * MILLIUNITS;
3725 g1_policy()->record_pause_time_ms(pause_time_ms);
3726 int active_gc_threads = workers()->active_workers();
3727 g1_policy()->record_collection_pause_end(active_gc_threads);
3728
3729 MemoryService::track_memory_usage();
3730
3731 // In prepare_for_verify() below we'll need to scan the deferred
3732 // update buffers to bring the RSets up-to-date if
3733 // G1HRRSFlushLogBuffersOnVerify has been set. While scanning
3734 // the update buffers we'll probably need to scan cards on the
3735 // regions we just allocated to (i.e., the GC alloc
3736 // regions). However, during the last GC we called
3737 // set_saved_mark() on all the GC alloc regions, so card
3738 // scanning might skip the [saved_mark_word()...top()] area of
3739 // those regions (i.e., the area we allocated objects into
3740 // during the last GC). But it shouldn't. Given that
3741 // saved_mark_word() is conditional on whether the GC time stamp
3742 // on the region is current or not, by incrementing the GC time
3743 // stamp here we invalidate all the GC time stamps on all the
3744 // regions and saved_mark_word() will simply return top() for
3745 // all the regions. This is a nicer way of ensuring this rather
3746 // than iterating over the regions and fixing them. In fact, the
3747 // GC time stamp increment here also ensures that
5231 //
5232 // But some of the referents, that are in the collection set, that these
5233 // reference objects point to may not have been copied: the STW ref
5234 // processor would have seen that the reference object had already
5235 // been 'discovered' and would have skipped discovering the reference,
5236 // but would not have treated the reference object as a regular oop.
5237 // As a reult the copy closure would not have been applied to the
5238 // referent object.
5239 //
5240 // We need to explicitly copy these referent objects - the references
5241 // will be processed at the end of remarking.
5242 //
5243 // We also need to do this copying before we process the reference
5244 // objects discovered by the STW ref processor in case one of these
5245 // referents points to another object which is also referenced by an
5246 // object discovered by the STW ref processor.
5247
5248 int active_workers = (G1CollectedHeap::use_parallel_gc_threads() ?
5249 workers()->active_workers() : 1);
5250
5251 assert(active_workers == workers()->active_workers(),
5252 "Need to reset active_workers");
5253 set_par_threads(active_workers);
5254 G1ParPreserveCMReferentsTask keep_cm_referents(this, active_workers, _task_queues);
5255
5256 if (G1CollectedHeap::use_parallel_gc_threads()) {
5257 workers()->run_task(&keep_cm_referents);
5258 } else {
5259 keep_cm_referents.work(0);
5260 }
5261
5262 set_par_threads(0);
5263
5264 // Closure to test whether a referent is alive.
5265 G1STWIsAliveClosure is_alive(this);
5266
5267 // Even when parallel reference processing is enabled, the processing
5268 // of JNI refs is serial and performed serially by the current thread
5269 // rather than by a worker. The following PSS will be used for processing
5270 // JNI refs.
5271
5272 // Use only a single queue for this PSS.
5370 double ref_enq_time = os::elapsedTime() - ref_enq_start;
5371 g1_policy()->record_ref_enq_time(ref_enq_time * 1000.0);
5372 }
5373
5374 void G1CollectedHeap::evacuate_collection_set() {
5375 set_evacuation_failed(false);
5376
5377 g1_rem_set()->prepare_for_oops_into_collection_set_do();
5378 concurrent_g1_refine()->set_use_cache(false);
5379 concurrent_g1_refine()->clear_hot_cache_claimed_index();
5380
5381 int n_workers;
5382 if (G1CollectedHeap::use_parallel_gc_threads()) {
5383 n_workers =
5384 AdaptiveSizePolicy::calc_active_workers(workers()->total_workers(),
5385 workers()->active_workers(),
5386 Threads::number_of_non_daemon_threads());
5387 assert(UseDynamicNumberOfGCThreads ||
5388 n_workers == workers()->total_workers(),
5389 "If not dynamic should be using all the workers");
5390 set_par_threads(n_workers);
5391 } else {
5392 assert(n_par_threads() == 0,
5393 "Should be the original non-parallel value");
5394 n_workers = 1;
5395 }
5396 workers()->set_active_workers(n_workers);
5397
5398 G1ParTask g1_par_task(this, _task_queues);
5399
5400 init_for_evac_failure(NULL);
5401
5402 rem_set()->prepare_for_younger_refs_iterate(true);
5403
5404 assert(dirty_card_queue_set().completed_buffers_num() == 0, "Should be empty");
5405 double start_par = os::elapsedTime();
5406
5407 if (G1CollectedHeap::use_parallel_gc_threads()) {
5408 // The individual threads will set their evac-failure closures.
5409 StrongRootsScope srs(this);
5410 if (ParallelGCVerbose) G1ParScanThreadState::print_termination_stats_hdr();
5411 // These tasks use ShareHeap::_process_strong_tasks
5412 assert(UseDynamicNumberOfGCThreads ||
5413 workers()->active_workers() == workers()->total_workers(),
5414 "If not dynamic should be using all the workers");
5415 workers()->run_task(&g1_par_task);
5416 } else {
5417 StrongRootsScope srs(this);
5418 g1_par_task.work(0);
5419 }
5420
5421 double par_time = (os::elapsedTime() - start_par) * 1000.0;
5422 g1_policy()->record_par_time(par_time);
5423
5424 set_par_threads(0);
5425
5426 // Process any discovered reference objects - we have
5427 // to do this _before_ we retire the GC alloc regions
5428 // as we may have to copy some 'reachable' referent
5429 // objects (and their reachable sub-graphs) that were
5430 // not copied during the pause.
5431 process_discovered_references();
5432
5433 // Weak root processing.
5434 // Note: when JSR 292 is enabled and code blobs can contain
5435 // non-perm oops then we will need to process the code blobs
5436 // here too.
5437 {
6055 assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
6056 assert(alloc_region->is_young(), "all mutator alloc regions should be young");
6057
6058 g1_policy()->add_region_to_incremental_cset_lhs(alloc_region);
6059 _summary_bytes_used += allocated_bytes;
6060 _hr_printer.retire(alloc_region);
6061 // We update the eden sizes here, when the region is retired,
6062 // instead of when it's allocated, since this is the point that its
6063 // used space has been recored in _summary_bytes_used.
6064 g1mm()->update_eden_size();
6065 }
6066
6067 HeapRegion* MutatorAllocRegion::allocate_new_region(size_t word_size,
6068 bool force) {
6069 return _g1h->new_mutator_alloc_region(word_size, force);
6070 }
6071
6072 void G1CollectedHeap::set_par_threads() {
6073 // Don't change the number of workers. Use the value previously set
6074 // in the workgroup.
6075 int n_workers = workers()->active_workers();
6076 assert(UseDynamicNumberOfGCThreads ||
6077 n_workers == workers()->total_workers(),
6078 "Otherwise should be using the total number of workers");
6079 if (n_workers == 0) {
6080 assert(false, "Should have been set in prior evacuation pause.");
6081 n_workers = ParallelGCThreads;
6082 workers()->set_active_workers(n_workers);
6083 }
6084 set_par_threads(n_workers);
6085 }
6086
6087 void MutatorAllocRegion::retire_region(HeapRegion* alloc_region,
6088 size_t allocated_bytes) {
6089 _g1h->retire_mutator_alloc_region(alloc_region, allocated_bytes);
6090 }
6091
6092 // Methods for the GC alloc regions
6093
6094 HeapRegion* G1CollectedHeap::new_gc_alloc_region(size_t word_size,
|
3706 #endif // YOUNG_LIST_VERBOSE
3707
3708 init_mutator_alloc_region();
3709
3710 {
3711 size_t expand_bytes = g1_policy()->expansion_amount();
3712 if (expand_bytes > 0) {
3713 size_t bytes_before = capacity();
3714 if (!expand(expand_bytes)) {
3715 // We failed to expand the heap so let's verify that
3716 // committed/uncommitted amount match the backing store
3717 assert(capacity() == _g1_storage.committed_size(), "committed size mismatch");
3718 assert(max_capacity() == _g1_storage.reserved_size(), "reserved size mismatch");
3719 }
3720 }
3721 }
3722
3723 double end_time_sec = os::elapsedTime();
3724 double pause_time_ms = (end_time_sec - start_time_sec) * MILLIUNITS;
3725 g1_policy()->record_pause_time_ms(pause_time_ms);
3726 int active_workers = (G1CollectedHeap::use_parallel_gc_threads() ?
3727 workers()->active_workers() : 1);
3728 g1_policy()->record_collection_pause_end(active_workers);
3729
3730 MemoryService::track_memory_usage();
3731
3732 // In prepare_for_verify() below we'll need to scan the deferred
3733 // update buffers to bring the RSets up-to-date if
3734 // G1HRRSFlushLogBuffersOnVerify has been set. While scanning
3735 // the update buffers we'll probably need to scan cards on the
3736 // regions we just allocated to (i.e., the GC alloc
3737 // regions). However, during the last GC we called
3738 // set_saved_mark() on all the GC alloc regions, so card
3739 // scanning might skip the [saved_mark_word()...top()] area of
3740 // those regions (i.e., the area we allocated objects into
3741 // during the last GC). But it shouldn't. Given that
3742 // saved_mark_word() is conditional on whether the GC time stamp
3743 // on the region is current or not, by incrementing the GC time
3744 // stamp here we invalidate all the GC time stamps on all the
3745 // regions and saved_mark_word() will simply return top() for
3746 // all the regions. This is a nicer way of ensuring this rather
3747 // than iterating over the regions and fixing them. In fact, the
3748 // GC time stamp increment here also ensures that
5232 //
5233 // But some of the referents, that are in the collection set, that these
5234 // reference objects point to may not have been copied: the STW ref
5235 // processor would have seen that the reference object had already
5236 // been 'discovered' and would have skipped discovering the reference,
5237 // but would not have treated the reference object as a regular oop.
5238 // As a reult the copy closure would not have been applied to the
5239 // referent object.
5240 //
5241 // We need to explicitly copy these referent objects - the references
5242 // will be processed at the end of remarking.
5243 //
5244 // We also need to do this copying before we process the reference
5245 // objects discovered by the STW ref processor in case one of these
5246 // referents points to another object which is also referenced by an
5247 // object discovered by the STW ref processor.
5248
5249 int active_workers = (G1CollectedHeap::use_parallel_gc_threads() ?
5250 workers()->active_workers() : 1);
5251
5252 assert(!G1CollectedHeap::use_parallel_gc_threads() ||
5253 active_workers == workers()->active_workers(),
5254 "Need to reset active_workers");
5255
5256 set_par_threads(active_workers);
5257 G1ParPreserveCMReferentsTask keep_cm_referents(this, active_workers, _task_queues);
5258
5259 if (G1CollectedHeap::use_parallel_gc_threads()) {
5260 workers()->run_task(&keep_cm_referents);
5261 } else {
5262 keep_cm_referents.work(0);
5263 }
5264
5265 set_par_threads(0);
5266
5267 // Closure to test whether a referent is alive.
5268 G1STWIsAliveClosure is_alive(this);
5269
5270 // Even when parallel reference processing is enabled, the processing
5271 // of JNI refs is serial and performed serially by the current thread
5272 // rather than by a worker. The following PSS will be used for processing
5273 // JNI refs.
5274
5275 // Use only a single queue for this PSS.
5373 double ref_enq_time = os::elapsedTime() - ref_enq_start;
5374 g1_policy()->record_ref_enq_time(ref_enq_time * 1000.0);
5375 }
5376
5377 void G1CollectedHeap::evacuate_collection_set() {
5378 set_evacuation_failed(false);
5379
5380 g1_rem_set()->prepare_for_oops_into_collection_set_do();
5381 concurrent_g1_refine()->set_use_cache(false);
5382 concurrent_g1_refine()->clear_hot_cache_claimed_index();
5383
5384 int n_workers;
5385 if (G1CollectedHeap::use_parallel_gc_threads()) {
5386 n_workers =
5387 AdaptiveSizePolicy::calc_active_workers(workers()->total_workers(),
5388 workers()->active_workers(),
5389 Threads::number_of_non_daemon_threads());
5390 assert(UseDynamicNumberOfGCThreads ||
5391 n_workers == workers()->total_workers(),
5392 "If not dynamic should be using all the workers");
5393 workers()->set_active_workers(n_workers);
5394 set_par_threads(n_workers);
5395 } else {
5396 assert(n_par_threads() == 0,
5397 "Should be the original non-parallel value");
5398 n_workers = 1;
5399 }
5400
5401 G1ParTask g1_par_task(this, _task_queues);
5402
5403 init_for_evac_failure(NULL);
5404
5405 rem_set()->prepare_for_younger_refs_iterate(true);
5406
5407 assert(dirty_card_queue_set().completed_buffers_num() == 0, "Should be empty");
5408 double start_par = os::elapsedTime();
5409
5410 if (G1CollectedHeap::use_parallel_gc_threads()) {
5411 // The individual threads will set their evac-failure closures.
5412 StrongRootsScope srs(this);
5413 if (ParallelGCVerbose) G1ParScanThreadState::print_termination_stats_hdr();
5414 // These tasks use ShareHeap::_process_strong_tasks
5415 assert(UseDynamicNumberOfGCThreads ||
5416 workers()->active_workers() == workers()->total_workers(),
5417 "If not dynamic should be using all the workers");
5418 workers()->run_task(&g1_par_task);
5419 } else {
5420 StrongRootsScope srs(this);
5421 g1_par_task.set_for_termination(n_workers);
5422 g1_par_task.work(0);
5423 }
5424
5425 double par_time = (os::elapsedTime() - start_par) * 1000.0;
5426 g1_policy()->record_par_time(par_time);
5427
5428 set_par_threads(0);
5429
5430 // Process any discovered reference objects - we have
5431 // to do this _before_ we retire the GC alloc regions
5432 // as we may have to copy some 'reachable' referent
5433 // objects (and their reachable sub-graphs) that were
5434 // not copied during the pause.
5435 process_discovered_references();
5436
5437 // Weak root processing.
5438 // Note: when JSR 292 is enabled and code blobs can contain
5439 // non-perm oops then we will need to process the code blobs
5440 // here too.
5441 {
6059 assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
6060 assert(alloc_region->is_young(), "all mutator alloc regions should be young");
6061
6062 g1_policy()->add_region_to_incremental_cset_lhs(alloc_region);
6063 _summary_bytes_used += allocated_bytes;
6064 _hr_printer.retire(alloc_region);
6065 // We update the eden sizes here, when the region is retired,
6066 // instead of when it's allocated, since this is the point that its
6067 // used space has been recored in _summary_bytes_used.
6068 g1mm()->update_eden_size();
6069 }
6070
6071 HeapRegion* MutatorAllocRegion::allocate_new_region(size_t word_size,
6072 bool force) {
6073 return _g1h->new_mutator_alloc_region(word_size, force);
6074 }
6075
6076 void G1CollectedHeap::set_par_threads() {
6077 // Don't change the number of workers. Use the value previously set
6078 // in the workgroup.
6079 assert(G1CollectedHeap::use_parallel_gc_threads(), "shouldn't be here otherwise");
6080 int n_workers = workers()->active_workers();
6081 assert(UseDynamicNumberOfGCThreads ||
6082 n_workers == workers()->total_workers(),
6083 "Otherwise should be using the total number of workers");
6084 if (n_workers == 0) {
6085 assert(false, "Should have been set in prior evacuation pause.");
6086 n_workers = ParallelGCThreads;
6087 workers()->set_active_workers(n_workers);
6088 }
6089 set_par_threads(n_workers);
6090 }
6091
6092 void MutatorAllocRegion::retire_region(HeapRegion* alloc_region,
6093 size_t allocated_bytes) {
6094 _g1h->retire_mutator_alloc_region(alloc_region, allocated_bytes);
6095 }
6096
6097 // Methods for the GC alloc regions
6098
6099 HeapRegion* G1CollectedHeap::new_gc_alloc_region(size_t word_size,
|