ysr@777: /* xdono@1014: * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * ysr@777: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, ysr@777: * CA 95054 USA or visit www.sun.com if you need additional information or ysr@777: * have any questions. ysr@777: * ysr@777: */ ysr@777: ysr@777: // Keeps track of the GC work and decides when it is OK to do GC work ysr@777: // and for how long so that the MMU invariants are maintained. ysr@777: ysr@777: /***** ALL TIMES ARE IN SECS!!!!!!! *****/ ysr@777: ysr@777: // this is the "interface" apetrusenko@984: class G1MMUTracker: public CHeapObj { ysr@777: protected: ysr@777: double _time_slice; ysr@777: double _max_gc_time; // this is per time slice ysr@777: ysr@777: public: ysr@777: G1MMUTracker(double time_slice, double max_gc_time); ysr@777: ysr@777: virtual void add_pause(double start, double end, bool gc_thread) = 0; ysr@777: virtual double longest_pause(double current_time) = 0; ysr@777: virtual double when_sec(double current_time, double pause_time) = 0; ysr@777: ysr@777: double max_gc_time() { tonyp@1371: return _max_gc_time; ysr@777: } ysr@777: ysr@777: inline bool now_max_gc(double current_time) { ysr@777: return when_sec(current_time, max_gc_time()) < 0.00001; ysr@777: } ysr@777: ysr@777: inline double when_max_gc_sec(double current_time) { ysr@777: return when_sec(current_time, max_gc_time()); ysr@777: } ysr@777: ysr@777: inline jlong when_max_gc_ms(double current_time) { ysr@777: double when = when_max_gc_sec(current_time); ysr@777: return (jlong) (when * 1000.0); ysr@777: } ysr@777: ysr@777: inline jlong when_ms(double current_time, double pause_time) { ysr@777: double when = when_sec(current_time, pause_time); ysr@777: return (jlong) (when * 1000.0); ysr@777: } ysr@777: }; ysr@777: apetrusenko@984: class G1MMUTrackerQueueElem VALUE_OBJ_CLASS_SPEC { ysr@777: private: ysr@777: double _start_time; ysr@777: double _end_time; ysr@777: ysr@777: public: ysr@777: inline double start_time() { return _start_time; } ysr@777: inline double end_time() { return _end_time; } ysr@777: inline double duration() { return _end_time - _start_time; } ysr@777: ysr@777: G1MMUTrackerQueueElem() { ysr@777: _start_time = 0.0; ysr@777: _end_time = 0.0; ysr@777: } ysr@777: ysr@777: G1MMUTrackerQueueElem(double start_time, double end_time) { ysr@777: _start_time = start_time; ysr@777: _end_time = end_time; ysr@777: } ysr@777: }; ysr@777: ysr@777: // this is an implementation of the MMUTracker using a (fixed-size) queue ysr@777: // that keeps track of all the recent pause times ysr@777: class G1MMUTrackerQueue: public G1MMUTracker { ysr@777: private: ysr@777: enum PrivateConstants { ysr@777: QueueLength = 64 ysr@777: }; ysr@777: ysr@777: // The array keeps track of all the pauses that fall within a time ysr@777: // slice (the last time slice during which pauses took place). ysr@777: // The data structure implemented is a circular queue. ysr@777: // Head "points" to the most recent addition, tail to the oldest one. ysr@777: // The array is of fixed size and I don't think we'll need more than ysr@777: // two or three entries with the current behaviour of G1 pauses. ysr@777: // If the array is full, an easy fix is to look for the pauses with ysr@1523: // the shortest gap between them and consolidate them. ysr@1523: // For now, we have taken the expedient alternative of forgetting tonyp@1717: // the oldest entry in the event that +G1UseFixedWindowMMUTracker, thus ysr@1523: // potentially violating MMU specs for some time thereafter. ysr@777: ysr@777: G1MMUTrackerQueueElem _array[QueueLength]; ysr@777: int _head_index; ysr@777: int _tail_index; ysr@777: int _no_entries; ysr@777: ysr@777: inline int trim_index(int index) { ysr@777: return (index + QueueLength) % QueueLength; ysr@777: } ysr@777: ysr@777: void remove_expired_entries(double current_time); ysr@777: double calculate_gc_time(double current_time); ysr@777: ysr@777: double longest_pause_internal(double current_time); ysr@777: double when_internal(double current_time, double pause_time); ysr@777: ysr@777: public: ysr@777: G1MMUTrackerQueue(double time_slice, double max_gc_time); ysr@777: ysr@777: virtual void add_pause(double start, double end, bool gc_thread); ysr@777: ysr@777: virtual double longest_pause(double current_time); ysr@777: virtual double when_sec(double current_time, double pause_time); ysr@777: };