annotate src/share/vm/gc_implementation/g1/g1MMUTracker.cpp @ 948:89e0543e1737

6884624: Update copyright year Summary: Update copyright for files that have been modified in 2009 through Septermber Reviewed-by: tbell, ohair
author xdono
date Tue, 22 Sep 2009 14:06:10 -0700
parents e1fdf4fd34dc
children 3fc996d4edd2
rev   line source
ysr@342 1 /*
xdono@948 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
ysr@342 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@342 4 *
ysr@342 5 * This code is free software; you can redistribute it and/or modify it
ysr@342 6 * under the terms of the GNU General Public License version 2 only, as
ysr@342 7 * published by the Free Software Foundation.
ysr@342 8 *
ysr@342 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@342 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@342 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@342 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@342 13 * accompanied this code).
ysr@342 14 *
ysr@342 15 * You should have received a copy of the GNU General Public License version
ysr@342 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@342 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@342 18 *
ysr@342 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@342 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@342 21 * have any questions.
ysr@342 22 *
ysr@342 23 */
ysr@342 24
ysr@342 25 #include "incls/_precompiled.incl"
ysr@342 26 #include "incls/_g1MMUTracker.cpp.incl"
ysr@342 27
ysr@342 28 #define _DISABLE_MMU 0
ysr@342 29
ysr@342 30 // can't rely on comparing doubles with tolerating a small margin for error
ysr@342 31 #define SMALL_MARGIN 0.0000001
ysr@342 32 #define is_double_leq_0(_value) ( (_value) < SMALL_MARGIN )
ysr@342 33 #define is_double_leq(_val1, _val2) is_double_leq_0((_val1) - (_val2))
ysr@342 34 #define is_double_geq(_val1, _val2) is_double_leq_0((_val2) - (_val1))
ysr@342 35
ysr@342 36 /***** ALL TIMES ARE IN SECS!!!!!!! *****/
ysr@342 37
ysr@342 38 G1MMUTracker::G1MMUTracker(double time_slice, double max_gc_time) :
ysr@342 39 _time_slice(time_slice),
tonyp@936 40 _max_gc_time(max_gc_time) { }
ysr@342 41
ysr@342 42 G1MMUTrackerQueue::G1MMUTrackerQueue(double time_slice, double max_gc_time) :
ysr@342 43 G1MMUTracker(time_slice, max_gc_time),
ysr@342 44 _head_index(0),
ysr@342 45 _tail_index(trim_index(_head_index+1)),
ysr@342 46 _no_entries(0) { }
ysr@342 47
ysr@342 48 void G1MMUTrackerQueue::remove_expired_entries(double current_time) {
ysr@342 49 double limit = current_time - _time_slice;
ysr@342 50 while (_no_entries > 0) {
ysr@342 51 if (is_double_geq(limit, _array[_tail_index].end_time())) {
ysr@342 52 _tail_index = trim_index(_tail_index + 1);
ysr@342 53 --_no_entries;
ysr@342 54 } else
ysr@342 55 return;
ysr@342 56 }
ysr@342 57 guarantee(_no_entries == 0, "should have no entries in the array");
ysr@342 58 }
ysr@342 59
ysr@342 60 double G1MMUTrackerQueue::calculate_gc_time(double current_time) {
ysr@342 61 double gc_time = 0.0;
ysr@342 62 double limit = current_time - _time_slice;
ysr@342 63 for (int i = 0; i < _no_entries; ++i) {
ysr@342 64 int index = trim_index(_tail_index + i);
ysr@342 65 G1MMUTrackerQueueElem *elem = &_array[index];
ysr@342 66 if (elem->end_time() > limit) {
ysr@342 67 if (elem->start_time() > limit)
ysr@342 68 gc_time += elem->duration();
ysr@342 69 else
ysr@342 70 gc_time += elem->end_time() - limit;
ysr@342 71 }
ysr@342 72 }
ysr@342 73 return gc_time;
ysr@342 74 }
ysr@342 75
ysr@342 76 void G1MMUTrackerQueue::add_pause(double start, double end, bool gc_thread) {
ysr@342 77 double longest_allowed = longest_pause_internal(start);
ysr@342 78 if (longest_allowed < 0.0)
ysr@342 79 longest_allowed = 0.0;
ysr@342 80 double duration = end - start;
ysr@342 81
ysr@342 82 remove_expired_entries(end);
ysr@342 83 if (_no_entries == QueueLength) {
ysr@342 84 // OK, right now when we fill up we bomb out
ysr@342 85 // there are a few ways of dealing with this "gracefully"
ysr@342 86 // increase the array size (:-)
ysr@342 87 // remove the oldest entry (this might allow more GC time for
ysr@342 88 // the time slice than what's allowed)
ysr@342 89 // concolidate the two entries with the minimum gap between them
ysr@342 90 // (this mighte allow less GC time than what's allowed)
ysr@342 91 guarantee(0, "array full, currently we can't recover");
ysr@342 92 }
ysr@342 93 _head_index = trim_index(_head_index + 1);
ysr@342 94 ++_no_entries;
ysr@342 95 _array[_head_index] = G1MMUTrackerQueueElem(start, end);
ysr@342 96 }
ysr@342 97
ysr@342 98 // basically the _internal call does not remove expired entries
ysr@342 99 // this is for trying things out in the future and a couple
ysr@342 100 // of other places (debugging)
ysr@342 101
ysr@342 102 double G1MMUTrackerQueue::longest_pause(double current_time) {
ysr@342 103 if (_DISABLE_MMU)
ysr@342 104 return _max_gc_time;
ysr@342 105
ysr@342 106 MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag);
ysr@342 107 remove_expired_entries(current_time);
ysr@342 108
ysr@342 109 return longest_pause_internal(current_time);
ysr@342 110 }
ysr@342 111
ysr@342 112 double G1MMUTrackerQueue::longest_pause_internal(double current_time) {
ysr@342 113 double target_time = _max_gc_time;
ysr@342 114
ysr@342 115 while( 1 ) {
ysr@342 116 double gc_time =
tonyp@936 117 calculate_gc_time(current_time + target_time);
ysr@342 118 double diff = target_time + gc_time - _max_gc_time;
ysr@342 119 if (!is_double_leq_0(diff)) {
ysr@342 120 target_time -= diff;
ysr@342 121 if (is_double_leq_0(target_time)) {
ysr@342 122 target_time = -1.0;
ysr@342 123 break;
ysr@342 124 }
ysr@342 125 } else {
ysr@342 126 break;
ysr@342 127 }
ysr@342 128 }
ysr@342 129
ysr@342 130 return target_time;
ysr@342 131 }
ysr@342 132
ysr@342 133 // basically the _internal call does not remove expired entries
ysr@342 134 // this is for trying things out in the future and a couple
ysr@342 135 // of other places (debugging)
ysr@342 136
ysr@342 137 double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) {
ysr@342 138 if (_DISABLE_MMU)
ysr@342 139 return 0.0;
ysr@342 140
ysr@342 141 MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag);
ysr@342 142 remove_expired_entries(current_time);
ysr@342 143
ysr@342 144 return when_internal(current_time, pause_time);
ysr@342 145 }
ysr@342 146
ysr@342 147 double G1MMUTrackerQueue::when_internal(double current_time,
ysr@342 148 double pause_time) {
ysr@342 149 // if the pause is over the maximum, just assume that it's the maximum
ysr@342 150 double adjusted_pause_time =
ysr@342 151 (pause_time > max_gc_time()) ? max_gc_time() : pause_time;
ysr@342 152 double earliest_end = current_time + adjusted_pause_time;
ysr@342 153 double limit = earliest_end - _time_slice;
ysr@342 154 double gc_time = calculate_gc_time(earliest_end);
ysr@342 155 double diff = gc_time + adjusted_pause_time - max_gc_time();
ysr@342 156 if (is_double_leq_0(diff))
ysr@342 157 return 0.0;
ysr@342 158
ysr@342 159 int index = _tail_index;
ysr@342 160 while ( 1 ) {
ysr@342 161 G1MMUTrackerQueueElem *elem = &_array[index];
ysr@342 162 if (elem->end_time() > limit) {
ysr@342 163 if (elem->start_time() > limit)
ysr@342 164 diff -= elem->duration();
ysr@342 165 else
ysr@342 166 diff -= elem->end_time() - limit;
ysr@342 167 if (is_double_leq_0(diff))
ysr@342 168 return elem->end_time() + diff + _time_slice - adjusted_pause_time - current_time;
ysr@342 169 }
ysr@342 170 index = trim_index(index+1);
ysr@342 171 guarantee(index != trim_index(_head_index + 1), "should not go past head");
ysr@342 172 }
ysr@342 173 }