59 } 60 guarantee(_no_entries == 0, "should have no entries in the array"); 61 } 62 63 double G1MMUTrackerQueue::calculate_gc_time(double current_time) { 64 double gc_time = 0.0; 65 double limit = current_time - _time_slice; 66 for (int i = 0; i < _no_entries; ++i) { 67 int index = trim_index(_tail_index + i); 68 G1MMUTrackerQueueElem *elem = &_array[index]; 69 if (elem->end_time() > limit) { 70 if (elem->start_time() > limit) 71 gc_time += elem->duration(); 72 else 73 gc_time += elem->end_time() - limit; 74 } 75 } 76 return gc_time; 77 } 78 79 void G1MMUTrackerQueue::add_pause(double start, double end, const GCId& gcId) { 80 double duration = end - start; 81 82 remove_expired_entries(end); 83 if (_no_entries == QueueLength) { 84 // OK, we've filled up the queue. There are a few ways 85 // of dealing with this "gracefully" 86 // increase the array size (:-) 87 // remove the oldest entry (this might allow more GC time for 88 // the time slice than what's allowed) - this is what we 89 // currently do 90 // consolidate the two entries with the minimum gap between them 91 // (this might allow less GC time than what's allowed) 92 93 // In the case where ScavengeALot is true, such overflow is not 94 // uncommon; in such cases, we can, without much loss of precision 95 // or performance (we are GC'ing most of the time anyway!), 96 // simply overwrite the oldest entry in the tracker. 97 98 _head_index = trim_index(_head_index + 1); 99 assert(_head_index == _tail_index, "Because we have a full circular buffer"); 100 _tail_index = trim_index(_tail_index + 1); 101 } else { 102 _head_index = trim_index(_head_index + 1); 103 ++_no_entries; 104 } 105 _array[_head_index] = G1MMUTrackerQueueElem(start, end); 106 107 // Current entry needs to be added before calculating the value 108 double slice_time = calculate_gc_time(end); 109 G1MMUTracer::report_mmu(gcId, _time_slice, slice_time, _max_gc_time); 110 } 111 112 // basically the _internal call does not remove expired entries 113 // this is for trying things out in the future and a couple 114 // of other places (debugging) 115 116 double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) { 117 if (_DISABLE_MMU) 118 return 0.0; 119 120 MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag); 121 remove_expired_entries(current_time); 122 123 return when_internal(current_time, pause_time); 124 } 125 126 double G1MMUTrackerQueue::when_internal(double current_time, 127 double pause_time) { 128 // if the pause is over the maximum, just assume that it's the maximum 129 double adjusted_pause_time = | 59 } 60 guarantee(_no_entries == 0, "should have no entries in the array"); 61 } 62 63 double G1MMUTrackerQueue::calculate_gc_time(double current_time) { 64 double gc_time = 0.0; 65 double limit = current_time - _time_slice; 66 for (int i = 0; i < _no_entries; ++i) { 67 int index = trim_index(_tail_index + i); 68 G1MMUTrackerQueueElem *elem = &_array[index]; 69 if (elem->end_time() > limit) { 70 if (elem->start_time() > limit) 71 gc_time += elem->duration(); 72 else 73 gc_time += elem->end_time() - limit; 74 } 75 } 76 return gc_time; 77 } 78 79 void G1MMUTrackerQueue::add_pause(double start, double end) { 80 double duration = end - start; 81 82 remove_expired_entries(end); 83 if (_no_entries == QueueLength) { 84 // OK, we've filled up the queue. There are a few ways 85 // of dealing with this "gracefully" 86 // increase the array size (:-) 87 // remove the oldest entry (this might allow more GC time for 88 // the time slice than what's allowed) - this is what we 89 // currently do 90 // consolidate the two entries with the minimum gap between them 91 // (this might allow less GC time than what's allowed) 92 93 // In the case where ScavengeALot is true, such overflow is not 94 // uncommon; in such cases, we can, without much loss of precision 95 // or performance (we are GC'ing most of the time anyway!), 96 // simply overwrite the oldest entry in the tracker. 97 98 _head_index = trim_index(_head_index + 1); 99 assert(_head_index == _tail_index, "Because we have a full circular buffer"); 100 _tail_index = trim_index(_tail_index + 1); 101 } else { 102 _head_index = trim_index(_head_index + 1); 103 ++_no_entries; 104 } 105 _array[_head_index] = G1MMUTrackerQueueElem(start, end); 106 107 // Current entry needs to be added before calculating the value 108 double slice_time = calculate_gc_time(end); 109 G1MMUTracer::report_mmu(_time_slice, slice_time, _max_gc_time); 110 } 111 112 // basically the _internal call does not remove expired entries 113 // this is for trying things out in the future and a couple 114 // of other places (debugging) 115 116 double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) { 117 if (_DISABLE_MMU) 118 return 0.0; 119 120 MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag); 121 remove_expired_entries(current_time); 122 123 return when_internal(current_time, pause_time); 124 } 125 126 double G1MMUTrackerQueue::when_internal(double current_time, 127 double pause_time) { 128 // if the pause is over the maximum, just assume that it's the maximum 129 double adjusted_pause_time = |