equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 */ |
23 */ |
24 |
24 |
25 #ifndef SHARE_VM_TRACE_TRACEEVENT_HPP |
25 #ifndef SHARE_VM_TRACE_TRACEEVENT_HPP |
26 #define SHARE_VM_TRACE_TRACEEVENT_HPP |
26 #define SHARE_VM_TRACE_TRACEEVENT_HPP |
27 |
27 |
|
28 #include "trace/traceTime.hpp" |
28 #include "utilities/macros.hpp" |
29 #include "utilities/macros.hpp" |
29 |
30 |
30 enum EventStartTime { |
31 enum EventStartTime { |
31 UNTIMED, |
32 UNTIMED, |
32 TIMED |
33 TIMED |
33 }; |
34 }; |
34 |
35 |
35 #if INCLUDE_TRACE |
36 #if INCLUDE_TRACE |
36 #include "trace/traceBackend.hpp" |
37 #include "trace/traceBackend.hpp" |
37 #include "trace/tracing.hpp" |
|
38 #include "tracefiles/traceEventIds.hpp" |
38 #include "tracefiles/traceEventIds.hpp" |
39 #include "tracefiles/traceTypes.hpp" |
|
40 #include "utilities/ticks.hpp" |
39 #include "utilities/ticks.hpp" |
41 |
40 |
42 template<typename T> |
41 template<typename T> |
43 class TraceEvent : public StackObj { |
42 class TraceEvent { |
44 private: |
43 private: |
45 bool _started; |
44 bool _started; |
46 #ifdef ASSERT |
|
47 bool _committed; |
|
48 bool _cancelled; |
|
49 protected: |
|
50 bool _ignore_check; |
|
51 #endif |
|
52 |
45 |
53 protected: |
46 protected: |
54 jlong _startTime; |
47 jlong _startTime; |
55 jlong _endTime; |
48 jlong _endTime; |
|
49 DEBUG_ONLY(bool _committed;) |
56 |
50 |
57 void set_starttime(const TracingTime& time) { |
51 void set_starttime(const TracingTime& time) { |
58 _startTime = time; |
52 _startTime = time; |
59 } |
53 } |
60 |
54 |
65 TraceEvent(EventStartTime timing=TIMED) : |
59 TraceEvent(EventStartTime timing=TIMED) : |
66 _startTime(0), |
60 _startTime(0), |
67 _endTime(0), |
61 _endTime(0), |
68 _started(false) |
62 _started(false) |
69 #ifdef ASSERT |
63 #ifdef ASSERT |
70 , |
64 , _committed(false) |
71 _committed(false), |
|
72 _cancelled(false), |
|
73 _ignore_check(false) |
|
74 #endif |
65 #endif |
75 { |
66 { |
76 if (T::is_enabled()) { |
67 if (T::is_enabled()) { |
77 _started = true; |
68 _started = true; |
78 if (TIMED == timing && !T::isInstant) { |
69 if (TIMED == timing && !T::isInstant) { |
98 return _started; |
89 return _started; |
99 } |
90 } |
100 |
91 |
101 void commit() { |
92 void commit() { |
102 if (!should_commit()) { |
93 if (!should_commit()) { |
103 DEBUG_ONLY(cancel()); |
|
104 return; |
94 return; |
105 } |
95 } |
106 assert(!_cancelled, "Committing an event that has already been cancelled"); |
96 assert(!_committed, "event already committed"); |
107 if (_startTime == 0) { |
97 if (_startTime == 0) { |
108 static_cast<T*>(this)->set_starttime(Tracing::time()); |
98 static_cast<T*>(this)->set_starttime(Tracing::time()); |
109 } else if (_endTime == 0) { |
99 } else if (_endTime == 0) { |
110 static_cast<T*>(this)->set_endtime(Tracing::time()); |
100 static_cast<T*>(this)->set_endtime(Tracing::time()); |
111 } |
101 } |
112 if (static_cast<T*>(this)->should_write()) { |
102 if (static_cast<T*>(this)->should_write()) { |
113 static_cast<T*>(this)->writeEvent(); |
103 static_cast<T*>(this)->writeEvent(); |
|
104 DEBUG_ONLY(_committed = true;) |
114 } |
105 } |
115 DEBUG_ONLY(set_commited()); |
|
116 } |
106 } |
117 |
107 |
118 static TraceEventId id() { |
108 static TraceEventId id() { |
119 return T::eventId; |
109 return T::eventId; |
120 } |
110 } |
132 } |
122 } |
133 |
123 |
134 static bool has_stacktrace() { |
124 static bool has_stacktrace() { |
135 return T::hasStackTrace; |
125 return T::hasStackTrace; |
136 } |
126 } |
137 |
|
138 void cancel() { |
|
139 assert(!_committed && !_cancelled, |
|
140 "event was already committed/cancelled"); |
|
141 DEBUG_ONLY(_cancelled = true); |
|
142 } |
|
143 |
|
144 ~TraceEvent() { |
|
145 if (_started) { |
|
146 assert(_ignore_check || _committed || _cancelled, |
|
147 "event was not committed/cancelled"); |
|
148 } |
|
149 } |
|
150 |
|
151 #ifdef ASSERT |
|
152 protected: |
|
153 void ignoreCheck() { |
|
154 _ignore_check = true; |
|
155 } |
|
156 |
|
157 private: |
|
158 void set_commited() { |
|
159 assert(!_committed, "event has already been committed"); |
|
160 _committed = true; |
|
161 } |
|
162 #endif // ASSERT |
|
163 }; |
127 }; |
164 |
128 |
165 #endif // INCLUDE_TRACE |
129 #endif // INCLUDE_TRACE |
166 #endif // SHARE_VM_TRACE_TRACEEVENT_HPP |
130 #endif // SHARE_VM_TRACE_TRACEEVENT_HPP |