Print this page
G1: Use SoftMaxHeapSize to guide GC heuristics


2409 }
2410 
2411 // For G1 TLABs should not contain humongous objects, so the maximum TLAB size
2412 // must be equal to the humongous object limit.
2413 size_t G1CollectedHeap::max_tlab_size() const {
2414   return align_down(_humongous_object_threshold_in_words, MinObjAlignment);
2415 }
2416 
2417 size_t G1CollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const {
2418   return _allocator->unsafe_max_tlab_alloc();
2419 }
2420 
2421 size_t G1CollectedHeap::max_capacity() const {
2422   return _hrm->max_expandable_length() * HeapRegion::GrainBytes;
2423 }
2424 
2425 size_t G1CollectedHeap::max_reserved_capacity() const {
2426   return _hrm->max_length() * HeapRegion::GrainBytes;
2427 }
2428 




2429 jlong G1CollectedHeap::millis_since_last_gc() {
2430   // See the notes in GenCollectedHeap::millis_since_last_gc()
2431   // for more information about the implementation.
2432   jlong ret_val = (os::javaTimeNanos() / NANOSECS_PER_MILLISEC) -
2433                   _policy->collection_pause_end_millis();
2434   if (ret_val < 0) {
2435     log_warning(gc)("millis_since_last_gc() would return : " JLONG_FORMAT
2436       ". returning zero instead.", ret_val);
2437     return 0;
2438   }
2439   return ret_val;
2440 }
2441 
2442 void G1CollectedHeap::deduplicate_string(oop str) {
2443   assert(java_lang_String::is_instance(str), "invariant");
2444 
2445   if (G1StringDedup::is_enabled()) {
2446     G1StringDedup::deduplicate(str);
2447   }
2448 }


2935     log_info(gc, verify)("[Verifying RemSets before GC]");
2936     VerifyRegionRemSetClosure v_cl;
2937     heap_region_iterate(&v_cl);
2938   }
2939   _verifier->verify_before_gc(type);
2940   _verifier->check_bitmaps("GC Start");
2941   verify_numa_regions("GC Start");
2942 }
2943 
2944 void G1CollectedHeap::verify_after_young_collection(G1HeapVerifier::G1VerifyType type) {
2945   if (VerifyRememberedSets) {
2946     log_info(gc, verify)("[Verifying RemSets after GC]");
2947     VerifyRegionRemSetClosure v_cl;
2948     heap_region_iterate(&v_cl);
2949   }
2950   _verifier->verify_after_gc(type);
2951   _verifier->check_bitmaps("GC End");
2952   verify_numa_regions("GC End");
2953 }
2954 
2955 void G1CollectedHeap::expand_heap_after_young_collection(){
2956   size_t expand_bytes = _heap_sizing_policy->expansion_amount();









2957   if (expand_bytes > 0) {
2958     // No need for an ergo logging here,
2959     // expansion_amount() does this when it returns a value > 0.
2960     double expand_ms;
2961     if (!expand(expand_bytes, _workers, &expand_ms)) {
2962       // We failed to expand the heap. Cannot do anything about it.
2963     }
2964     phase_times()->record_expand_heap_time(expand_ms);



















2965   }
2966 }
2967 
2968 const char* G1CollectedHeap::young_gc_name() const {
2969   if (collector_state()->in_initial_mark_gc()) {
2970     return "Pause Young (Concurrent Start)";
2971   } else if (collector_state()->in_young_only_phase()) {
2972     if (collector_state()->in_young_gc_before_mixed()) {
2973       return "Pause Young (Prepare Mixed)";
2974     } else {
2975       return "Pause Young (Normal)";
2976     }
2977   } else {
2978     return "Pause Young (Mixed)";
2979   }
2980 }
2981 
2982 bool G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) {
2983   assert_at_safepoint_on_vm_thread();
2984   guarantee(!is_gc_active(), "collection is not reentrant");


3100 
3101         start_new_collection_set();
3102 
3103         _survivor_evac_stats.adjust_desired_plab_sz();
3104         _old_evac_stats.adjust_desired_plab_sz();
3105 
3106         if (should_start_conc_mark) {
3107           // We have to do this before we notify the CM threads that
3108           // they can start working to make sure that all the
3109           // appropriate initialization is done on the CM object.
3110           concurrent_mark()->post_initial_mark();
3111           // Note that we don't actually trigger the CM thread at
3112           // this point. We do that later when we're sure that
3113           // the current thread has completed its logging output.
3114         }
3115 
3116         allocate_dummy_regions();
3117 
3118         _allocator->init_mutator_alloc_regions();
3119 
3120         expand_heap_after_young_collection();
3121 
3122         double sample_end_time_sec = os::elapsedTime();
3123         double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS;
3124         policy()->record_collection_pause_end(pause_time_ms);
3125       }
3126 
3127       verify_after_young_collection(verify_type);
3128 
3129 #ifdef TRACESPINNING
3130       ParallelTaskTerminator::print_termination_counts();
3131 #endif
3132 
3133       gc_epilogue(false);
3134     }
3135 
3136     // Print the remainder of the GC log output.
3137     if (evacuation_failed()) {
3138       log_info(gc)("To-space exhausted");
3139     }
3140 




2409 }
2410 
2411 // For G1 TLABs should not contain humongous objects, so the maximum TLAB size
2412 // must be equal to the humongous object limit.
2413 size_t G1CollectedHeap::max_tlab_size() const {
2414   return align_down(_humongous_object_threshold_in_words, MinObjAlignment);
2415 }
2416 
2417 size_t G1CollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const {
2418   return _allocator->unsafe_max_tlab_alloc();
2419 }
2420 
2421 size_t G1CollectedHeap::max_capacity() const {
2422   return _hrm->max_expandable_length() * HeapRegion::GrainBytes;
2423 }
2424 
2425 size_t G1CollectedHeap::max_reserved_capacity() const {
2426   return _hrm->max_length() * HeapRegion::GrainBytes;
2427 }
2428 
2429 size_t G1CollectedHeap::soft_max_capacity() const {
2430   return clamp(align_up(SoftMaxHeapSize, HeapAlignment), MinHeapSize, max_capacity());
2431 }
2432 
2433 jlong G1CollectedHeap::millis_since_last_gc() {
2434   // See the notes in GenCollectedHeap::millis_since_last_gc()
2435   // for more information about the implementation.
2436   jlong ret_val = (os::javaTimeNanos() / NANOSECS_PER_MILLISEC) -
2437                   _policy->collection_pause_end_millis();
2438   if (ret_val < 0) {
2439     log_warning(gc)("millis_since_last_gc() would return : " JLONG_FORMAT
2440       ". returning zero instead.", ret_val);
2441     return 0;
2442   }
2443   return ret_val;
2444 }
2445 
2446 void G1CollectedHeap::deduplicate_string(oop str) {
2447   assert(java_lang_String::is_instance(str), "invariant");
2448 
2449   if (G1StringDedup::is_enabled()) {
2450     G1StringDedup::deduplicate(str);
2451   }
2452 }


2939     log_info(gc, verify)("[Verifying RemSets before GC]");
2940     VerifyRegionRemSetClosure v_cl;
2941     heap_region_iterate(&v_cl);
2942   }
2943   _verifier->verify_before_gc(type);
2944   _verifier->check_bitmaps("GC Start");
2945   verify_numa_regions("GC Start");
2946 }
2947 
2948 void G1CollectedHeap::verify_after_young_collection(G1HeapVerifier::G1VerifyType type) {
2949   if (VerifyRememberedSets) {
2950     log_info(gc, verify)("[Verifying RemSets after GC]");
2951     VerifyRegionRemSetClosure v_cl;
2952     heap_region_iterate(&v_cl);
2953   }
2954   _verifier->verify_after_gc(type);
2955   _verifier->check_bitmaps("GC End");
2956   verify_numa_regions("GC End");
2957 }
2958 
2959 void G1CollectedHeap::resize_heap_after_young_collection() {
2960   Ticks start = Ticks::now();
2961   if (!expand_heap_after_young_collection()) {
2962     // If we don't attempt to expand heap, try if we need to shrink the heap
2963     shrink_heap_after_young_collection();
2964   }
2965   phase_times()->record_resize_heap_time((Ticks::now() - start).seconds() * 1000.0);
2966 }
2967 
2968 bool G1CollectedHeap::expand_heap_after_young_collection(){
2969   size_t expand_bytes = _heap_sizing_policy->expansion_amount_after_young_collection();
2970   if (expand_bytes > 0) {
2971     if (expand(expand_bytes, _workers, NULL)) {



2972       // We failed to expand the heap. Cannot do anything about it.
2973     }
2974     return true;
2975   }
2976   return false;
2977 }
2978 
2979 void G1CollectedHeap::shrink_heap_after_young_collection() {
2980   if (!collector_state()->finish_of_mixed_gc()) {
2981     // Do the shrink only after finish of mixed gc
2982     return;
2983   }
2984   size_t shrink_bytes = _heap_sizing_policy->shrink_amount_after_mixed_collections();
2985   if (shrink_bytes > 0) {
2986     shrink(shrink_bytes);
2987   }
2988 }
2989 
2990 void G1CollectedHeap::expand_heap_after_concurrent_mark() {
2991   size_t expand_bytes = _heap_sizing_policy->expansion_amount_after_concurrent_mark();
2992   if (expand_bytes > 0) {
2993     expand(expand_bytes, _workers, NULL);
2994   }
2995 }
2996 
2997 const char* G1CollectedHeap::young_gc_name() const {
2998   if (collector_state()->in_initial_mark_gc()) {
2999     return "Pause Young (Concurrent Start)";
3000   } else if (collector_state()->in_young_only_phase()) {
3001     if (collector_state()->in_young_gc_before_mixed()) {
3002       return "Pause Young (Prepare Mixed)";
3003     } else {
3004       return "Pause Young (Normal)";
3005     }
3006   } else {
3007     return "Pause Young (Mixed)";
3008   }
3009 }
3010 
3011 bool G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) {
3012   assert_at_safepoint_on_vm_thread();
3013   guarantee(!is_gc_active(), "collection is not reentrant");


3129 
3130         start_new_collection_set();
3131 
3132         _survivor_evac_stats.adjust_desired_plab_sz();
3133         _old_evac_stats.adjust_desired_plab_sz();
3134 
3135         if (should_start_conc_mark) {
3136           // We have to do this before we notify the CM threads that
3137           // they can start working to make sure that all the
3138           // appropriate initialization is done on the CM object.
3139           concurrent_mark()->post_initial_mark();
3140           // Note that we don't actually trigger the CM thread at
3141           // this point. We do that later when we're sure that
3142           // the current thread has completed its logging output.
3143         }
3144 
3145         allocate_dummy_regions();
3146 
3147         _allocator->init_mutator_alloc_regions();
3148 
3149         resize_heap_after_young_collection();
3150 
3151         double sample_end_time_sec = os::elapsedTime();
3152         double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS;
3153         policy()->record_collection_pause_end(pause_time_ms);
3154       }
3155 
3156       verify_after_young_collection(verify_type);
3157 
3158 #ifdef TRACESPINNING
3159       ParallelTaskTerminator::print_termination_counts();
3160 #endif
3161 
3162       gc_epilogue(false);
3163     }
3164 
3165     // Print the remainder of the GC log output.
3166     if (evacuation_failed()) {
3167       log_info(gc)("To-space exhausted");
3168     }
3169