src/share/vm/trace/traceEvent.hpp

Wed, 26 Mar 2014 14:15:02 +0100

author
ehelin
date
Wed, 26 Mar 2014 14:15:02 +0100
changeset 6608
fa21c9537e6e
parent 6131
86e6d691f2e1
child 6876
710a3c8b516e
child 7367
82d3e7b5277a
permissions
-rw-r--r--

8035667: EventMetaspaceSummary doesn't report committed Metaspace memory
Reviewed-by: jmasa, stefank

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

mercurial