src/share/vm/gc_implementation/g1/g1MMUTracker.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 6876
710a3c8b516e
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "gc_implementation/g1/g1MMUTracker.hpp"
aoqi@0 27 #include "runtime/mutexLocker.hpp"
aoqi@0 28 #include "utilities/ostream.hpp"
aoqi@0 29
aoqi@0 30 #define _DISABLE_MMU 0
aoqi@0 31
aoqi@0 32 // can't rely on comparing doubles with tolerating a small margin for error
aoqi@0 33 #define SMALL_MARGIN 0.0000001
aoqi@0 34 #define is_double_leq_0(_value) ( (_value) < SMALL_MARGIN )
aoqi@0 35 #define is_double_leq(_val1, _val2) is_double_leq_0((_val1) - (_val2))
aoqi@0 36 #define is_double_geq(_val1, _val2) is_double_leq_0((_val2) - (_val1))
aoqi@0 37
aoqi@0 38 /***** ALL TIMES ARE IN SECS!!!!!!! *****/
aoqi@0 39
aoqi@0 40 G1MMUTracker::G1MMUTracker(double time_slice, double max_gc_time) :
aoqi@0 41 _time_slice(time_slice),
aoqi@0 42 _max_gc_time(max_gc_time) { }
aoqi@0 43
aoqi@0 44 G1MMUTrackerQueue::G1MMUTrackerQueue(double time_slice, double max_gc_time) :
aoqi@0 45 G1MMUTracker(time_slice, max_gc_time),
aoqi@0 46 _head_index(0),
aoqi@0 47 _tail_index(trim_index(_head_index+1)),
aoqi@0 48 _no_entries(0) { }
aoqi@0 49
aoqi@0 50 void G1MMUTrackerQueue::remove_expired_entries(double current_time) {
aoqi@0 51 double limit = current_time - _time_slice;
aoqi@0 52 while (_no_entries > 0) {
aoqi@0 53 if (is_double_geq(limit, _array[_tail_index].end_time())) {
aoqi@0 54 _tail_index = trim_index(_tail_index + 1);
aoqi@0 55 --_no_entries;
aoqi@0 56 } else
aoqi@0 57 return;
aoqi@0 58 }
aoqi@0 59 guarantee(_no_entries == 0, "should have no entries in the array");
aoqi@0 60 }
aoqi@0 61
aoqi@0 62 double G1MMUTrackerQueue::calculate_gc_time(double current_time) {
aoqi@0 63 double gc_time = 0.0;
aoqi@0 64 double limit = current_time - _time_slice;
aoqi@0 65 for (int i = 0; i < _no_entries; ++i) {
aoqi@0 66 int index = trim_index(_tail_index + i);
aoqi@0 67 G1MMUTrackerQueueElem *elem = &_array[index];
aoqi@0 68 if (elem->end_time() > limit) {
aoqi@0 69 if (elem->start_time() > limit)
aoqi@0 70 gc_time += elem->duration();
aoqi@0 71 else
aoqi@0 72 gc_time += elem->end_time() - limit;
aoqi@0 73 }
aoqi@0 74 }
aoqi@0 75 return gc_time;
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 void G1MMUTrackerQueue::add_pause(double start, double end, bool gc_thread) {
aoqi@0 79 double longest_allowed = longest_pause_internal(start);
aoqi@0 80 if (longest_allowed < 0.0)
aoqi@0 81 longest_allowed = 0.0;
aoqi@0 82 double duration = end - start;
aoqi@0 83
aoqi@0 84 remove_expired_entries(end);
aoqi@0 85 if (_no_entries == QueueLength) {
aoqi@0 86 // OK, we've filled up the queue. There are a few ways
aoqi@0 87 // of dealing with this "gracefully"
aoqi@0 88 // increase the array size (:-)
aoqi@0 89 // remove the oldest entry (this might allow more GC time for
aoqi@0 90 // the time slice than what's allowed) - this is what we
aoqi@0 91 // currently do
aoqi@0 92 // consolidate the two entries with the minimum gap between them
aoqi@0 93 // (this might allow less GC time than what's allowed)
aoqi@0 94
aoqi@0 95 // In the case where ScavengeALot is true, such overflow is not
aoqi@0 96 // uncommon; in such cases, we can, without much loss of precision
aoqi@0 97 // or performance (we are GC'ing most of the time anyway!),
aoqi@0 98 // simply overwrite the oldest entry in the tracker.
aoqi@0 99
aoqi@0 100 _head_index = trim_index(_head_index + 1);
aoqi@0 101 assert(_head_index == _tail_index, "Because we have a full circular buffer");
aoqi@0 102 _tail_index = trim_index(_tail_index + 1);
aoqi@0 103 } else {
aoqi@0 104 _head_index = trim_index(_head_index + 1);
aoqi@0 105 ++_no_entries;
aoqi@0 106 }
aoqi@0 107 _array[_head_index] = G1MMUTrackerQueueElem(start, end);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 // basically the _internal call does not remove expired entries
aoqi@0 111 // this is for trying things out in the future and a couple
aoqi@0 112 // of other places (debugging)
aoqi@0 113
aoqi@0 114 double G1MMUTrackerQueue::longest_pause(double current_time) {
aoqi@0 115 if (_DISABLE_MMU)
aoqi@0 116 return _max_gc_time;
aoqi@0 117
aoqi@0 118 MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 119 remove_expired_entries(current_time);
aoqi@0 120
aoqi@0 121 return longest_pause_internal(current_time);
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 double G1MMUTrackerQueue::longest_pause_internal(double current_time) {
aoqi@0 125 double target_time = _max_gc_time;
aoqi@0 126
aoqi@0 127 while( 1 ) {
aoqi@0 128 double gc_time =
aoqi@0 129 calculate_gc_time(current_time + target_time);
aoqi@0 130 double diff = target_time + gc_time - _max_gc_time;
aoqi@0 131 if (!is_double_leq_0(diff)) {
aoqi@0 132 target_time -= diff;
aoqi@0 133 if (is_double_leq_0(target_time)) {
aoqi@0 134 target_time = -1.0;
aoqi@0 135 break;
aoqi@0 136 }
aoqi@0 137 } else {
aoqi@0 138 break;
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141
aoqi@0 142 return target_time;
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 // basically the _internal call does not remove expired entries
aoqi@0 146 // this is for trying things out in the future and a couple
aoqi@0 147 // of other places (debugging)
aoqi@0 148
aoqi@0 149 double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) {
aoqi@0 150 if (_DISABLE_MMU)
aoqi@0 151 return 0.0;
aoqi@0 152
aoqi@0 153 MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 154 remove_expired_entries(current_time);
aoqi@0 155
aoqi@0 156 return when_internal(current_time, pause_time);
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 double G1MMUTrackerQueue::when_internal(double current_time,
aoqi@0 160 double pause_time) {
aoqi@0 161 // if the pause is over the maximum, just assume that it's the maximum
aoqi@0 162 double adjusted_pause_time =
aoqi@0 163 (pause_time > max_gc_time()) ? max_gc_time() : pause_time;
aoqi@0 164 double earliest_end = current_time + adjusted_pause_time;
aoqi@0 165 double limit = earliest_end - _time_slice;
aoqi@0 166 double gc_time = calculate_gc_time(earliest_end);
aoqi@0 167 double diff = gc_time + adjusted_pause_time - max_gc_time();
aoqi@0 168 if (is_double_leq_0(diff))
aoqi@0 169 return 0.0;
aoqi@0 170
aoqi@0 171 int index = _tail_index;
aoqi@0 172 while ( 1 ) {
aoqi@0 173 G1MMUTrackerQueueElem *elem = &_array[index];
aoqi@0 174 if (elem->end_time() > limit) {
aoqi@0 175 if (elem->start_time() > limit)
aoqi@0 176 diff -= elem->duration();
aoqi@0 177 else
aoqi@0 178 diff -= elem->end_time() - limit;
aoqi@0 179 if (is_double_leq_0(diff))
aoqi@0 180 return elem->end_time() + diff + _time_slice - adjusted_pause_time - current_time;
aoqi@0 181 }
aoqi@0 182 index = trim_index(index+1);
aoqi@0 183 guarantee(index != trim_index(_head_index + 1), "should not go past head");
aoqi@0 184 }
aoqi@0 185 }

mercurial