src/share/vm/runtime/timer.cpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, 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 #include "precompiled.hpp"
aoqi@0 26 #include "oops/oop.inline.hpp"
aoqi@0 27 #include "runtime/timer.hpp"
aoqi@0 28 #include "utilities/ostream.hpp"
aoqi@0 29 #ifdef TARGET_OS_FAMILY_linux
aoqi@0 30 # include "os_linux.inline.hpp"
aoqi@0 31 #endif
aoqi@0 32 #ifdef TARGET_OS_FAMILY_solaris
aoqi@0 33 # include "os_solaris.inline.hpp"
aoqi@0 34 #endif
aoqi@0 35 #ifdef TARGET_OS_FAMILY_windows
aoqi@0 36 # include "os_windows.inline.hpp"
aoqi@0 37 #endif
aoqi@0 38 #ifdef TARGET_OS_FAMILY_aix
aoqi@0 39 # include "os_aix.inline.hpp"
aoqi@0 40 #endif
aoqi@0 41 #ifdef TARGET_OS_FAMILY_bsd
aoqi@0 42 # include "os_bsd.inline.hpp"
aoqi@0 43 #endif
aoqi@0 44
aoqi@0 45 double TimeHelper::counter_to_seconds(jlong counter) {
aoqi@0 46 double count = (double) counter;
aoqi@0 47 double freq = (double) os::elapsed_frequency();
aoqi@0 48 return counter/freq;
aoqi@0 49 }
aoqi@0 50
aoqi@0 51 void elapsedTimer::add(elapsedTimer t) {
aoqi@0 52 _counter += t._counter;
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 void elapsedTimer::start() {
aoqi@0 56 if (!_active) {
aoqi@0 57 _active = true;
aoqi@0 58 _start_counter = os::elapsed_counter();
aoqi@0 59 }
aoqi@0 60 }
aoqi@0 61
aoqi@0 62 void elapsedTimer::stop() {
aoqi@0 63 if (_active) {
aoqi@0 64 _counter += os::elapsed_counter() - _start_counter;
aoqi@0 65 _active = false;
aoqi@0 66 }
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 double elapsedTimer::seconds() const {
aoqi@0 70 return TimeHelper::counter_to_seconds(_counter);
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 jlong elapsedTimer::milliseconds() const {
aoqi@0 74 jlong ticks_per_ms = os::elapsed_frequency() / 1000;
aoqi@0 75 return _counter / ticks_per_ms;
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 jlong elapsedTimer::active_ticks() const {
aoqi@0 79 if (!_active) {
aoqi@0 80 return ticks();
aoqi@0 81 }
aoqi@0 82 jlong counter = _counter + os::elapsed_counter() - _start_counter;
aoqi@0 83 return counter;
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 void TimeStamp::update_to(jlong ticks) {
aoqi@0 87 _counter = ticks;
aoqi@0 88 if (_counter == 0) _counter = 1;
aoqi@0 89 assert(is_updated(), "must not look clear");
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 void TimeStamp::update() {
aoqi@0 93 update_to(os::elapsed_counter());
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 double TimeStamp::seconds() const {
aoqi@0 97 assert(is_updated(), "must not be clear");
aoqi@0 98 jlong new_count = os::elapsed_counter();
aoqi@0 99 return TimeHelper::counter_to_seconds(new_count - _counter);
aoqi@0 100 }
aoqi@0 101
aoqi@0 102 jlong TimeStamp::milliseconds() const {
aoqi@0 103 assert(is_updated(), "must not be clear");
aoqi@0 104
aoqi@0 105 jlong new_count = os::elapsed_counter();
aoqi@0 106 jlong count = new_count - _counter;
aoqi@0 107 jlong ticks_per_ms = os::elapsed_frequency() / 1000;
aoqi@0 108 return count / ticks_per_ms;
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 jlong TimeStamp::ticks_since_update() const {
aoqi@0 112 assert(is_updated(), "must not be clear");
aoqi@0 113 return os::elapsed_counter() - _counter;
aoqi@0 114 }
aoqi@0 115
aoqi@0 116 TraceTime::TraceTime(const char* title,
aoqi@0 117 bool doit) {
aoqi@0 118 _active = doit;
aoqi@0 119 _verbose = true;
aoqi@0 120
aoqi@0 121 if (_active) {
aoqi@0 122 _accum = NULL;
aoqi@0 123 tty->stamp(PrintGCTimeStamps);
aoqi@0 124 tty->print("[%s", title);
aoqi@0 125 tty->flush();
aoqi@0 126 _t.start();
aoqi@0 127 }
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 TraceTime::TraceTime(const char* title,
aoqi@0 131 elapsedTimer* accumulator,
aoqi@0 132 bool doit,
aoqi@0 133 bool verbose) {
aoqi@0 134 _active = doit;
aoqi@0 135 _verbose = verbose;
aoqi@0 136 if (_active) {
aoqi@0 137 if (_verbose) {
aoqi@0 138 tty->stamp(PrintGCTimeStamps);
aoqi@0 139 tty->print("[%s", title);
aoqi@0 140 tty->flush();
aoqi@0 141 }
aoqi@0 142 _accum = accumulator;
aoqi@0 143 _t.start();
aoqi@0 144 }
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 TraceTime::~TraceTime() {
aoqi@0 148 if (_active) {
aoqi@0 149 _t.stop();
aoqi@0 150 if (_accum!=NULL) _accum->add(_t);
aoqi@0 151 if (_verbose) {
aoqi@0 152 tty->print_cr(", %3.7f secs]", _t.seconds());
aoqi@0 153 tty->flush();
aoqi@0 154 }
aoqi@0 155 }
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 TraceCPUTime::TraceCPUTime(bool doit,
aoqi@0 159 bool print_cr,
aoqi@0 160 outputStream *logfile) :
aoqi@0 161 _active(doit),
aoqi@0 162 _print_cr(print_cr),
aoqi@0 163 _starting_user_time(0.0),
aoqi@0 164 _starting_system_time(0.0),
aoqi@0 165 _starting_real_time(0.0),
aoqi@0 166 _logfile(logfile),
aoqi@0 167 _error(false) {
aoqi@0 168 if (_active) {
aoqi@0 169 if (logfile != NULL) {
aoqi@0 170 _logfile = logfile;
aoqi@0 171 } else {
aoqi@0 172 _logfile = tty;
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 _error = !os::getTimesSecs(&_starting_real_time,
aoqi@0 176 &_starting_user_time,
aoqi@0 177 &_starting_system_time);
aoqi@0 178 }
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 TraceCPUTime::~TraceCPUTime() {
aoqi@0 182 if (_active) {
aoqi@0 183 bool valid = false;
aoqi@0 184 if (!_error) {
aoqi@0 185 double real_secs; // walk clock time
aoqi@0 186 double system_secs; // system time
aoqi@0 187 double user_secs; // user time for all threads
aoqi@0 188
aoqi@0 189 double real_time, user_time, system_time;
aoqi@0 190 valid = os::getTimesSecs(&real_time, &user_time, &system_time);
aoqi@0 191 if (valid) {
aoqi@0 192
aoqi@0 193 user_secs = user_time - _starting_user_time;
aoqi@0 194 system_secs = system_time - _starting_system_time;
aoqi@0 195 real_secs = real_time - _starting_real_time;
aoqi@0 196
aoqi@0 197 _logfile->print(" [Times: user=%3.2f sys=%3.2f, real=%3.2f secs] ",
aoqi@0 198 user_secs, system_secs, real_secs);
aoqi@0 199
aoqi@0 200 } else {
aoqi@0 201 _logfile->print("[Invalid result in TraceCPUTime]");
aoqi@0 202 }
aoqi@0 203 } else {
aoqi@0 204 _logfile->print("[Error in TraceCPUTime]");
aoqi@0 205 }
aoqi@0 206 if (_print_cr) {
aoqi@0 207 _logfile->cr();
aoqi@0 208 }
aoqi@0 209 _logfile->flush();
aoqi@0 210 }
aoqi@0 211 }

mercurial