g1MMUTracker.hpp 4.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
22 23 24
 *
 */

25 26 27 28 29 30
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1MMUTRACKER_HPP
#define SHARE_VM_GC_IMPLEMENTATION_G1_G1MMUTRACKER_HPP

#include "memory/allocation.hpp"
#include "utilities/debug.hpp"

31 32 33 34 35 36
// Keeps track of the GC work and decides when it is OK to do GC work
// and for how long so that the MMU invariants are maintained.

/***** ALL TIMES ARE IN SECS!!!!!!! *****/

// this is the "interface"
Z
zgu 已提交
37
class G1MMUTracker: public CHeapObj<mtGC> {
38 39 40 41 42 43 44 45 46 47 48 49
protected:
  double          _time_slice;
  double          _max_gc_time; // this is per time slice

public:
  G1MMUTracker(double time_slice, double max_gc_time);

  virtual void add_pause(double start, double end, bool gc_thread) = 0;
  virtual double longest_pause(double current_time) = 0;
  virtual double when_sec(double current_time, double pause_time) = 0;

  double max_gc_time() {
50
    return _max_gc_time;
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  }

  inline bool now_max_gc(double current_time) {
    return when_sec(current_time, max_gc_time()) < 0.00001;
  }

  inline double when_max_gc_sec(double current_time) {
    return when_sec(current_time, max_gc_time());
  }

  inline jlong when_max_gc_ms(double current_time) {
    double when = when_max_gc_sec(current_time);
    return (jlong) (when * 1000.0);
  }

  inline jlong when_ms(double current_time, double pause_time) {
    double when = when_sec(current_time, pause_time);
    return (jlong) (when * 1000.0);
  }
};

72
class G1MMUTrackerQueueElem VALUE_OBJ_CLASS_SPEC {
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
private:
  double _start_time;
  double _end_time;

public:
  inline double start_time() { return _start_time; }
  inline double end_time()   { return _end_time; }
  inline double duration()   { return _end_time - _start_time; }

  G1MMUTrackerQueueElem() {
    _start_time = 0.0;
    _end_time   = 0.0;
  }

  G1MMUTrackerQueueElem(double start_time, double end_time) {
    _start_time = start_time;
    _end_time   = end_time;
  }
};

// this is an implementation of the MMUTracker using a (fixed-size) queue
// that keeps track of all the recent pause times
class G1MMUTrackerQueue: public G1MMUTracker {
private:
  enum PrivateConstants {
    QueueLength = 64
  };

  // The array keeps track of all the pauses that fall within a time
  // slice (the last time slice during which pauses took place).
  // The data structure implemented is a circular queue.
  // Head "points" to the most recent addition, tail to the oldest one.
  // The array is of fixed size and I don't think we'll need more than
  // two or three entries with the current behaviour of G1 pauses.
  // If the array is full, an easy fix is to look for the pauses with
108 109
  // the shortest gap between them and consolidate them.
  // For now, we have taken the expedient alternative of forgetting
110
  // the oldest entry in the event that +G1UseFixedWindowMMUTracker, thus
111
  // potentially violating MMU specs for some time thereafter.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

  G1MMUTrackerQueueElem _array[QueueLength];
  int                   _head_index;
  int                   _tail_index;
  int                   _no_entries;

  inline int trim_index(int index) {
    return (index + QueueLength) % QueueLength;
  }

  void remove_expired_entries(double current_time);
  double calculate_gc_time(double current_time);

  double longest_pause_internal(double current_time);
  double when_internal(double current_time, double pause_time);

public:
  G1MMUTrackerQueue(double time_slice, double max_gc_time);

  virtual void add_pause(double start, double end, bool gc_thread);

  virtual double longest_pause(double current_time);
  virtual double when_sec(double current_time, double pause_time);
};
136 137

#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MMUTRACKER_HPP