annotate src/share/vm/trace/traceEvent.hpp @ 13616:ecebbbda267a

8179040: Avoid Ticks::now calls when EventClassLoad is not enabled Reviewed-by: ehelin, mgronlun, dholmes, iklam Contributed-by: claes.redestad@oracle.com, markus.gronlund@oracle.com
author redestad
date Mon, 28 Aug 2017 00:20:35 +0200
parents 56fbd5c60c96
children
rev   line source
sla@4802 1 /*
redestad@13616 2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
sla@4802 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sla@4802 4 *
sla@4802 5 * This code is free software; you can redistribute it and/or modify it
sla@4802 6 * under the terms of the GNU General Public License version 2 only, as
sla@4802 7 * published by the Free Software Foundation.
sla@4802 8 *
sla@4802 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sla@4802 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sla@4802 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sla@4802 12 * version 2 for more details (a copy is included in the LICENSE file that
sla@4802 13 * accompanied this code).
sla@4802 14 *
sla@4802 15 * You should have received a copy of the GNU General Public License version
sla@4802 16 * 2 along with this work; if not, write to the Free Software Foundation,
sla@4802 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sla@4802 18 *
sla@4802 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sla@4802 20 * or visit www.oracle.com if you need additional information or have any
sla@4802 21 * questions.
sla@4802 22 *
sla@4802 23 */
sla@4802 24
sla@4802 25 #ifndef SHARE_VM_TRACE_TRACEEVENT_HPP
sla@4802 26 #define SHARE_VM_TRACE_TRACEEVENT_HPP
sla@4802 27
redestad@13616 28 #include "trace/traceTime.hpp"
mgronlun@5696 29 #include "utilities/macros.hpp"
mgronlun@5696 30
sla@4802 31 enum EventStartTime {
sla@4802 32 UNTIMED,
sla@4802 33 TIMED
sla@4802 34 };
sla@4802 35
sla@4802 36 #if INCLUDE_TRACE
sla@4802 37 #include "trace/traceBackend.hpp"
sla@4802 38 #include "tracefiles/traceEventIds.hpp"
mgronlun@5696 39 #include "utilities/ticks.hpp"
sla@4802 40
sla@4802 41 template<typename T>
redestad@13616 42 class TraceEvent {
sla@4802 43 private:
sla@4802 44 bool _started;
sla@4802 45
mgronlun@5696 46 protected:
mgronlun@5696 47 jlong _startTime;
mgronlun@5696 48 jlong _endTime;
redestad@13616 49 DEBUG_ONLY(bool _committed;)
mgronlun@5696 50
mgronlun@5696 51 void set_starttime(const TracingTime& time) {
mgronlun@5696 52 _startTime = time;
mgronlun@5696 53 }
mgronlun@5696 54
mgronlun@5696 55 void set_endtime(const TracingTime& time) {
mgronlun@5696 56 _endTime = time;
mgronlun@5696 57 }
mgronlun@5696 58
sla@4802 59 TraceEvent(EventStartTime timing=TIMED) :
sla@4802 60 _startTime(0),
sla@4802 61 _endTime(0),
sla@4802 62 _started(false)
sla@4802 63 #ifdef ASSERT
redestad@13616 64 , _committed(false)
sla@4802 65 #endif
sla@4802 66 {
sla@4802 67 if (T::is_enabled()) {
sla@4802 68 _started = true;
mgronlun@10397 69 if (TIMED == timing && !T::isInstant) {
mgronlun@10397 70 static_cast<T*>(this)->set_starttime(Tracing::time());
sla@4802 71 }
sla@4802 72 }
sla@4802 73 }
sla@4802 74
mgronlun@10397 75 public:
mgronlun@10397 76 void set_starttime(const Ticks& time) {
mgronlun@10397 77 _startTime = time.value();
mgronlun@10397 78 }
mgronlun@10397 79
mgronlun@10397 80 void set_endtime(const Ticks& time) {
mgronlun@10397 81 _endTime = time.value();
mgronlun@10397 82 }
mgronlun@10397 83
sla@4802 84 static bool is_enabled() {
sla@4802 85 return Tracing::is_event_enabled(T::eventId);
sla@4802 86 }
sla@4802 87
sla@4802 88 bool should_commit() {
sla@4802 89 return _started;
sla@4802 90 }
sla@4802 91
sla@4802 92 void commit() {
sla@4802 93 if (!should_commit()) {
mgronlun@10397 94 return;
sla@4802 95 }
redestad@13616 96 assert(!_committed, "event already committed");
mgronlun@10396 97 if (_startTime == 0) {
mgronlun@10396 98 static_cast<T*>(this)->set_starttime(Tracing::time());
mgronlun@10397 99 } else if (_endTime == 0) {
mgronlun@10397 100 static_cast<T*>(this)->set_endtime(Tracing::time());
sla@4802 101 }
sla@4802 102 if (static_cast<T*>(this)->should_write()) {
sla@4802 103 static_cast<T*>(this)->writeEvent();
redestad@13616 104 DEBUG_ONLY(_committed = true;)
sla@4802 105 }
sla@4802 106 }
sla@4802 107
mgronlun@10397 108 static TraceEventId id() {
sla@4802 109 return T::eventId;
sla@4802 110 }
sla@4802 111
mgronlun@10397 112 static bool is_instant() {
sla@4802 113 return T::isInstant;
sla@4802 114 }
sla@4802 115
mgronlun@10397 116 static bool is_requestable() {
sla@4802 117 return T::isRequestable;
sla@4802 118 }
sla@4802 119
mgronlun@10397 120 static bool has_thread() {
sla@4802 121 return T::hasThread;
sla@4802 122 }
sla@4802 123
mgronlun@10397 124 static bool has_stacktrace() {
sla@4802 125 return T::hasStackTrace;
sla@4802 126 }
sla@4802 127 };
sla@4802 128
mgronlun@7414 129 #endif // INCLUDE_TRACE
mgronlun@7414 130 #endif // SHARE_VM_TRACE_TRACEEVENT_HPP