1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/trace/traceEvent.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,159 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_TRACE_TRACEEVENT_HPP 1.29 +#define SHARE_VM_TRACE_TRACEEVENT_HPP 1.30 + 1.31 +#include "utilities/macros.hpp" 1.32 + 1.33 +enum EventStartTime { 1.34 + UNTIMED, 1.35 + TIMED 1.36 +}; 1.37 + 1.38 +#if INCLUDE_TRACE 1.39 + 1.40 +#include "trace/traceBackend.hpp" 1.41 +#include "trace/tracing.hpp" 1.42 +#include "tracefiles/traceEventIds.hpp" 1.43 +#include "tracefiles/traceTypes.hpp" 1.44 +#include "utilities/ticks.hpp" 1.45 + 1.46 +template<typename T> 1.47 +class TraceEvent : public StackObj { 1.48 + private: 1.49 + bool _started; 1.50 +#ifdef ASSERT 1.51 + bool _committed; 1.52 + bool _cancelled; 1.53 + protected: 1.54 + bool _ignore_check; 1.55 +#endif 1.56 + 1.57 + protected: 1.58 + jlong _startTime; 1.59 + jlong _endTime; 1.60 + 1.61 + void set_starttime(const TracingTime& time) { 1.62 + _startTime = time; 1.63 + } 1.64 + 1.65 + void set_endtime(const TracingTime& time) { 1.66 + _endTime = time; 1.67 + } 1.68 + 1.69 + public: 1.70 + TraceEvent(EventStartTime timing=TIMED) : 1.71 + _startTime(0), 1.72 + _endTime(0), 1.73 + _started(false) 1.74 +#ifdef ASSERT 1.75 + , 1.76 + _committed(false), 1.77 + _cancelled(false), 1.78 + _ignore_check(false) 1.79 +#endif 1.80 + { 1.81 + if (T::is_enabled()) { 1.82 + _started = true; 1.83 + if (timing == TIMED && !T::isInstant) { 1.84 + static_cast<T *>(this)->set_starttime(Tracing::time()); 1.85 + } 1.86 + } 1.87 + } 1.88 + 1.89 + static bool is_enabled() { 1.90 + return Tracing::is_event_enabled(T::eventId); 1.91 + } 1.92 + 1.93 + bool should_commit() { 1.94 + return _started; 1.95 + } 1.96 + 1.97 + void ignoreCheck() { 1.98 + DEBUG_ONLY(_ignore_check = true); 1.99 + } 1.100 + 1.101 + void commit() { 1.102 + if (!should_commit()) { 1.103 + cancel(); 1.104 + return; 1.105 + } 1.106 + if (_endTime == 0) { 1.107 + static_cast<T*>(this)->set_endtime(Tracing::time()); 1.108 + } 1.109 + if (static_cast<T*>(this)->should_write()) { 1.110 + static_cast<T*>(this)->writeEvent(); 1.111 + } 1.112 + set_commited(); 1.113 + } 1.114 + 1.115 + void set_starttime(const Ticks& time) { 1.116 + _startTime = time.value(); 1.117 + } 1.118 + 1.119 + void set_endtime(const Ticks& time) { 1.120 + _endTime = time.value(); 1.121 + } 1.122 + 1.123 + TraceEventId id() const { 1.124 + return T::eventId; 1.125 + } 1.126 + 1.127 + bool is_instant() const { 1.128 + return T::isInstant; 1.129 + } 1.130 + 1.131 + bool is_requestable() const { 1.132 + return T::isRequestable; 1.133 + } 1.134 + 1.135 + bool has_thread() const { 1.136 + return T::hasThread; 1.137 + } 1.138 + 1.139 + bool has_stacktrace() const { 1.140 + return T::hasStackTrace; 1.141 + } 1.142 + 1.143 + void cancel() { 1.144 + assert(!_committed && !_cancelled, "event was already committed/cancelled"); 1.145 + DEBUG_ONLY(_cancelled = true); 1.146 + } 1.147 + 1.148 + void set_commited() { 1.149 + assert(!_committed, "event has already been committed"); 1.150 + DEBUG_ONLY(_committed = true); 1.151 + } 1.152 + 1.153 + ~TraceEvent() { 1.154 + if (_started) { 1.155 + assert(_ignore_check || _committed || _cancelled, "event was not committed/cancelled"); 1.156 + } 1.157 + } 1.158 +}; 1.159 + 1.160 +#endif /* INCLUDE_TRACE */ 1.161 + 1.162 +#endif /* SHARE_VM_TRACE_TRACEEVENT_HPP */