1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/shared/gcOverheadReporter.hpp Thu Jun 05 15:57:56 2008 -0700 1.3 @@ -0,0 +1,141 @@ 1.4 +/* 1.5 + * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Keeps track of the GC overhead (both concurrent and STW). It stores 1.29 +// it in a large array and then prints it to tty at the end of the 1.30 +// execution. 1.31 + 1.32 +// See coTracker.hpp for the explanation on what groups are. 1.33 + 1.34 +// Let's set a maximum number of concurrent overhead groups, to 1.35 +// statically allocate any arrays we need and not to have to 1.36 +// malloc/free them. This is just a bit more convenient. 1.37 +enum { 1.38 + MaxGCOverheadGroupNum = 4 1.39 +}; 1.40 + 1.41 +typedef struct { 1.42 + double _start_sec; 1.43 + double _end_sec; 1.44 + 1.45 + double _conc_overhead[MaxGCOverheadGroupNum]; 1.46 + double _stw_overhead; 1.47 +} GCOverheadReporterEntry; 1.48 + 1.49 +class GCOverheadReporter { 1.50 + friend class COReportingThread; 1.51 + 1.52 +private: 1.53 + enum PrivateConstants { 1.54 + DefaultReporterLength = 128 * 1024 1.55 + }; 1.56 + 1.57 + // Reference to the single instance of this class. 1.58 + static GCOverheadReporter* _reporter; 1.59 + 1.60 + // These three references point to the array that contains the GC 1.61 + // overhead entries (_base is the base of the array, _top is the 1.62 + // address passed the last entry of the array, _curr is the next 1.63 + // entry to be used). 1.64 + GCOverheadReporterEntry* _base; 1.65 + GCOverheadReporterEntry* _top; 1.66 + GCOverheadReporterEntry* _curr; 1.67 + 1.68 + // The number of concurrent overhead groups. 1.69 + size_t _group_num; 1.70 + 1.71 + // The wall-clock time of the end of the last recorded period of GC 1.72 + // overhead. 1.73 + double _prev_end_sec; 1.74 + 1.75 + // Names for the concurrent overhead groups. 1.76 + const char* _group_names[MaxGCOverheadGroupNum]; 1.77 + 1.78 + // Add a new entry to the large array. conc_overhead being NULL is 1.79 + // equivalent to an array full of 0.0s. conc_overhead should have a 1.80 + // length of at least _group_num. 1.81 + void add(double start_sec, double end_sec, 1.82 + double* conc_overhead, 1.83 + double stw_overhead); 1.84 + 1.85 + // Add an entry that represents concurrent GC overhead. 1.86 + // conc_overhead must be at least of length _group_num. 1.87 + // conc_overhead being NULL is equivalent to an array full of 0.0s. 1.88 + void add_conc_overhead(double start_sec, double end_sec, 1.89 + double* conc_overhead) { 1.90 + add(start_sec, end_sec, conc_overhead, 0.0); 1.91 + } 1.92 + 1.93 + // Add an entry that represents STW GC overhead. 1.94 + void add_stw_overhead(double start_sec, double end_sec, 1.95 + double stw_overhead) { 1.96 + add(start_sec, end_sec, NULL, stw_overhead); 1.97 + } 1.98 + 1.99 + // It records the start of a STW pause (i.e. it records the 1.100 + // concurrent overhead up to that point) 1.101 + void record_stw_start(double start_sec); 1.102 + 1.103 + // It records the end of a STW pause (i.e. it records the overhead 1.104 + // associated with the pause and adjusts all the trackers to reflect 1.105 + // the pause) 1.106 + void record_stw_end(double end_sec); 1.107 + 1.108 + // It queries all the trackers of their concurrent overhead and 1.109 + // records it. 1.110 + void collect_and_record_conc_overhead(double end_sec); 1.111 + 1.112 + // It prints the contents of the GC overhead array 1.113 + void print() const; 1.114 + 1.115 + 1.116 + // Constructor. The same preconditions for group_num and group_names 1.117 + // from initGCOverheadReporter apply here too. 1.118 + GCOverheadReporter(size_t group_num, 1.119 + const char* group_names[], 1.120 + size_t length = DefaultReporterLength); 1.121 + 1.122 +public: 1.123 + 1.124 + // statics 1.125 + 1.126 + // It initialises the GCOverheadReporter and launches the concurrent 1.127 + // overhead reporting thread. Both actions happen only if the 1.128 + // GCOverheadReporting parameter is set. The length of the 1.129 + // group_names array should be >= group_num and group_num should be 1.130 + // <= MaxGCOverheadGroupNum. Entries group_namnes[0..group_num-1] 1.131 + // should not be NULL. 1.132 + static void initGCOverheadReporter(size_t group_num, 1.133 + const char* group_names[]); 1.134 + 1.135 + // The following three are provided for convenience and they are 1.136 + // wrappers around record_stw_start(start_sec), record_stw_end(end_sec), 1.137 + // and print(). Each of these checks whether GC overhead reporting 1.138 + // is on (i.e. _reporter != NULL) and, if it is, calls the 1.139 + // corresponding method. Saves from repeating this pattern again and 1.140 + // again from the places where they need to be called. 1.141 + static void recordSTWStart(double start_sec); 1.142 + static void recordSTWEnd(double end_sec); 1.143 + static void printGCOverhead(); 1.144 +};