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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4153
b9a9ed0f8eeb
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2012, 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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1MMUTRACKER_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1MMUTRACKER_HPP
aoqi@0 27
aoqi@0 28 #include "memory/allocation.hpp"
aoqi@0 29 #include "utilities/debug.hpp"
aoqi@0 30
aoqi@0 31 // Keeps track of the GC work and decides when it is OK to do GC work
aoqi@0 32 // and for how long so that the MMU invariants are maintained.
aoqi@0 33
aoqi@0 34 /***** ALL TIMES ARE IN SECS!!!!!!! *****/
aoqi@0 35
aoqi@0 36 // this is the "interface"
aoqi@0 37 class G1MMUTracker: public CHeapObj<mtGC> {
aoqi@0 38 protected:
aoqi@0 39 double _time_slice;
aoqi@0 40 double _max_gc_time; // this is per time slice
aoqi@0 41
aoqi@0 42 public:
aoqi@0 43 G1MMUTracker(double time_slice, double max_gc_time);
aoqi@0 44
aoqi@0 45 virtual void add_pause(double start, double end, bool gc_thread) = 0;
aoqi@0 46 virtual double longest_pause(double current_time) = 0;
aoqi@0 47 virtual double when_sec(double current_time, double pause_time) = 0;
aoqi@0 48
aoqi@0 49 double max_gc_time() {
aoqi@0 50 return _max_gc_time;
aoqi@0 51 }
aoqi@0 52
aoqi@0 53 inline bool now_max_gc(double current_time) {
aoqi@0 54 return when_sec(current_time, max_gc_time()) < 0.00001;
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 inline double when_max_gc_sec(double current_time) {
aoqi@0 58 return when_sec(current_time, max_gc_time());
aoqi@0 59 }
aoqi@0 60
aoqi@0 61 inline jlong when_max_gc_ms(double current_time) {
aoqi@0 62 double when = when_max_gc_sec(current_time);
aoqi@0 63 return (jlong) (when * 1000.0);
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 inline jlong when_ms(double current_time, double pause_time) {
aoqi@0 67 double when = when_sec(current_time, pause_time);
aoqi@0 68 return (jlong) (when * 1000.0);
aoqi@0 69 }
aoqi@0 70 };
aoqi@0 71
aoqi@0 72 class G1MMUTrackerQueueElem VALUE_OBJ_CLASS_SPEC {
aoqi@0 73 private:
aoqi@0 74 double _start_time;
aoqi@0 75 double _end_time;
aoqi@0 76
aoqi@0 77 public:
aoqi@0 78 inline double start_time() { return _start_time; }
aoqi@0 79 inline double end_time() { return _end_time; }
aoqi@0 80 inline double duration() { return _end_time - _start_time; }
aoqi@0 81
aoqi@0 82 G1MMUTrackerQueueElem() {
aoqi@0 83 _start_time = 0.0;
aoqi@0 84 _end_time = 0.0;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 G1MMUTrackerQueueElem(double start_time, double end_time) {
aoqi@0 88 _start_time = start_time;
aoqi@0 89 _end_time = end_time;
aoqi@0 90 }
aoqi@0 91 };
aoqi@0 92
aoqi@0 93 // this is an implementation of the MMUTracker using a (fixed-size) queue
aoqi@0 94 // that keeps track of all the recent pause times
aoqi@0 95 class G1MMUTrackerQueue: public G1MMUTracker {
aoqi@0 96 private:
aoqi@0 97 enum PrivateConstants {
aoqi@0 98 QueueLength = 64
aoqi@0 99 };
aoqi@0 100
aoqi@0 101 // The array keeps track of all the pauses that fall within a time
aoqi@0 102 // slice (the last time slice during which pauses took place).
aoqi@0 103 // The data structure implemented is a circular queue.
aoqi@0 104 // Head "points" to the most recent addition, tail to the oldest one.
aoqi@0 105 // The array is of fixed size and I don't think we'll need more than
aoqi@0 106 // two or three entries with the current behaviour of G1 pauses.
aoqi@0 107 // If the array is full, an easy fix is to look for the pauses with
aoqi@0 108 // the shortest gap between them and consolidate them.
aoqi@0 109 // For now, we have taken the expedient alternative of forgetting
aoqi@0 110 // the oldest entry in the event that +G1UseFixedWindowMMUTracker, thus
aoqi@0 111 // potentially violating MMU specs for some time thereafter.
aoqi@0 112
aoqi@0 113 G1MMUTrackerQueueElem _array[QueueLength];
aoqi@0 114 int _head_index;
aoqi@0 115 int _tail_index;
aoqi@0 116 int _no_entries;
aoqi@0 117
aoqi@0 118 inline int trim_index(int index) {
aoqi@0 119 return (index + QueueLength) % QueueLength;
aoqi@0 120 }
aoqi@0 121
aoqi@0 122 void remove_expired_entries(double current_time);
aoqi@0 123 double calculate_gc_time(double current_time);
aoqi@0 124
aoqi@0 125 double longest_pause_internal(double current_time);
aoqi@0 126 double when_internal(double current_time, double pause_time);
aoqi@0 127
aoqi@0 128 public:
aoqi@0 129 G1MMUTrackerQueue(double time_slice, double max_gc_time);
aoqi@0 130
aoqi@0 131 virtual void add_pause(double start, double end, bool gc_thread);
aoqi@0 132
aoqi@0 133 virtual double longest_pause(double current_time);
aoqi@0 134 virtual double when_sec(double current_time, double pause_time);
aoqi@0 135 };
aoqi@0 136
aoqi@0 137 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MMUTRACKER_HPP

mercurial