g1MMUTracker.hpp 4.3 KB
Newer Older
1
/*
X
xdono 已提交
2
 * Copyright 2001-2009 Sun Microsystems, Inc.  All Rights Reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * 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.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

// 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"
31
class G1MMUTracker: public CHeapObj {
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
protected:
  double          _time_slice;
  double          _max_gc_time; // this is per time slice

  double          _conc_overhead_time_sec;

public:
  G1MMUTracker(double time_slice, double max_gc_time);

  void update_conc_overhead(double conc_overhead);

  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() {
    return _max_gc_time - _conc_overhead_time_sec;
  }

  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);
  }
};

70
class G1MMUTrackerQueueElem VALUE_OBJ_CLASS_SPEC {
71 72 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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
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
  // the shortest gap between them and concolidate them.

  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);
};