21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
|
26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" |
26 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp" |
27 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp" |
27 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp" |
28 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp" |
28 #include "gc_implementation/parallelScavenge/psScavenge.hpp" |
29 #include "gc_implementation/parallelScavenge/psScavenge.hpp" |
29 #include "gc_implementation/shared/gcPolicyCounters.hpp" |
30 #include "gc_implementation/shared/gcPolicyCounters.hpp" |
30 #include "gc_interface/gcCause.hpp" |
31 #include "gc_interface/gcCause.hpp" |
72 |
73 |
73 // Start the timers |
74 // Start the timers |
74 _major_timer.start(); |
75 _major_timer.start(); |
75 |
76 |
76 _old_gen_policy_is_ready = false; |
77 _old_gen_policy_is_ready = false; |
|
78 } |
|
79 |
|
80 size_t PSAdaptiveSizePolicy::calculate_free_based_on_live(size_t live, uintx ratio_as_percentage) { |
|
81 // We want to calculate how much free memory there can be based on the |
|
82 // amount of live data currently in the old gen. Using the formula: |
|
83 // ratio * (free + live) = free |
|
84 // Some equation solving later we get: |
|
85 // free = (live * ratio) / (1 - ratio) |
|
86 |
|
87 const double ratio = ratio_as_percentage / 100.0; |
|
88 const double ratio_inverse = 1.0 - ratio; |
|
89 const double tmp = live * ratio; |
|
90 size_t free = (size_t)(tmp / ratio_inverse); |
|
91 |
|
92 return free; |
|
93 } |
|
94 |
|
95 size_t PSAdaptiveSizePolicy::calculated_old_free_size_in_bytes() const { |
|
96 size_t free_size = (size_t)(_promo_size + avg_promoted()->padded_average()); |
|
97 size_t live = ParallelScavengeHeap::heap()->old_gen()->used_in_bytes(); |
|
98 |
|
99 if (MinHeapFreeRatio != 0) { |
|
100 size_t min_free = calculate_free_based_on_live(live, MinHeapFreeRatio); |
|
101 free_size = MAX2(free_size, min_free); |
|
102 } |
|
103 |
|
104 if (MaxHeapFreeRatio != 100) { |
|
105 size_t max_free = calculate_free_based_on_live(live, MaxHeapFreeRatio); |
|
106 free_size = MIN2(max_free, free_size); |
|
107 } |
|
108 |
|
109 return free_size; |
77 } |
110 } |
78 |
111 |
79 void PSAdaptiveSizePolicy::major_collection_begin() { |
112 void PSAdaptiveSizePolicy::major_collection_begin() { |
80 // Update the interval time |
113 // Update the interval time |
81 _major_timer.stop(); |
114 _major_timer.stop(); |
1290 |
1323 |
1291 return AdaptiveSizePolicy::print_adaptive_size_policy_on( |
1324 return AdaptiveSizePolicy::print_adaptive_size_policy_on( |
1292 st, |
1325 st, |
1293 PSScavenge::tenuring_threshold()); |
1326 PSScavenge::tenuring_threshold()); |
1294 } |
1327 } |
|
1328 |
|
1329 #ifndef PRODUCT |
|
1330 |
|
1331 void TestOldFreeSpaceCalculation_test() { |
|
1332 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 20) == 25, "Calculation of free memory failed"); |
|
1333 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 50) == 100, "Calculation of free memory failed"); |
|
1334 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 60) == 150, "Calculation of free memory failed"); |
|
1335 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 75) == 300, "Calculation of free memory failed"); |
|
1336 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 20) == 100, "Calculation of free memory failed"); |
|
1337 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 50) == 400, "Calculation of free memory failed"); |
|
1338 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 60) == 600, "Calculation of free memory failed"); |
|
1339 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 75) == 1200, "Calculation of free memory failed"); |
|
1340 } |
|
1341 |
|
1342 #endif /* !PRODUCT */ |