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