4141N/A/*
4141N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4141N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4141N/A *
4141N/A * This code is free software; you can redistribute it and/or modify it
4141N/A * under the terms of the GNU General Public License version 2 only, as
4141N/A * published by the Free Software Foundation.
4141N/A *
4141N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4141N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4141N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4141N/A * version 2 for more details (a copy is included in the LICENSE file that
4141N/A * accompanied this code).
4141N/A *
4141N/A * You should have received a copy of the GNU General Public License version
4141N/A * 2 along with this work; if not, write to the Free Software Foundation,
4141N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4141N/A *
4141N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4141N/A * or visit www.oracle.com if you need additional information or have any
4141N/A * questions.
4141N/A *
4141N/A */
4141N/A
4141N/A#ifndef SHARE_VM_TRACE_TRACEEVENT_HPP
4141N/A#define SHARE_VM_TRACE_TRACEEVENT_HPP
4141N/A
4141N/Aenum EventStartTime {
4141N/A UNTIMED,
4141N/A TIMED
4141N/A};
4141N/A
4141N/A#if INCLUDE_TRACE
4141N/A
4141N/A#include "trace/traceBackend.hpp"
4141N/A#include "trace/tracing.hpp"
4141N/A#include "tracefiles/traceEventIds.hpp"
4141N/A#include "tracefiles/traceTypes.hpp"
4141N/A
4141N/Atemplate<typename T>
4141N/Aclass TraceEvent : public StackObj {
4141N/A protected:
4141N/A jlong _startTime;
4141N/A jlong _endTime;
4141N/A
4141N/A private:
4141N/A bool _started;
4141N/A#ifdef ASSERT
4141N/A bool _committed;
4141N/A bool _cancelled;
4141N/A protected:
4141N/A bool _ignore_check;
4141N/A#endif
4141N/A
4141N/A public:
4141N/A TraceEvent(EventStartTime timing=TIMED) :
4141N/A _startTime(0),
4141N/A _endTime(0),
4141N/A _started(false)
4141N/A#ifdef ASSERT
4141N/A ,
4141N/A _committed(false),
4141N/A _cancelled(false),
4141N/A _ignore_check(false)
4141N/A#endif
4141N/A {
4141N/A if (T::is_enabled()) {
4141N/A _started = true;
4141N/A if (timing == TIMED && !T::isInstant) {
4141N/A static_cast<T *>(this)->set_starttime(Tracing::time());
4141N/A }
4141N/A }
4141N/A }
4141N/A
4141N/A static bool is_enabled() {
4423N/A return Tracing::is_event_enabled(T::eventId);
4141N/A }
4141N/A
4141N/A bool should_commit() {
4141N/A return _started;
4141N/A }
4141N/A
4141N/A void ignoreCheck() {
4141N/A DEBUG_ONLY(_ignore_check = true);
4141N/A }
4141N/A
4141N/A void commit() {
4141N/A if (!should_commit()) {
4141N/A cancel();
4141N/A return;
4141N/A }
4141N/A if (_endTime == 0) {
4141N/A static_cast<T *>(this)->set_endtime(Tracing::time());
4141N/A }
4141N/A if (static_cast<T*>(this)->should_write()) {
4141N/A static_cast<T*>(this)->writeEvent();
4141N/A }
4141N/A set_commited();
4141N/A }
4141N/A
4141N/A void set_starttime(jlong time) {
4141N/A _startTime = time;
4141N/A }
4141N/A
4141N/A void set_endtime(jlong time) {
4141N/A _endTime = time;
4141N/A }
4141N/A
4141N/A TraceEventId id() const {
4141N/A return T::eventId;
4141N/A }
4141N/A
4141N/A bool is_instant() const {
4141N/A return T::isInstant;
4141N/A }
4141N/A
4141N/A bool is_requestable() const {
4141N/A return T::isRequestable;
4141N/A }
4141N/A
4141N/A bool has_thread() const {
4141N/A return T::hasThread;
4141N/A }
4141N/A
4141N/A bool has_stacktrace() const {
4141N/A return T::hasStackTrace;
4141N/A }
4141N/A
4141N/A void cancel() {
4141N/A assert(!_committed && !_cancelled, "event was already committed/cancelled");
4141N/A DEBUG_ONLY(_cancelled = true);
4141N/A }
4141N/A
4141N/A void set_commited() {
4141N/A assert(!_committed, "event has already been committed");
4141N/A DEBUG_ONLY(_committed = true);
4141N/A }
4141N/A
4141N/A ~TraceEvent() {
4141N/A if (_started) {
4141N/A assert(_ignore_check || _committed || _cancelled, "event was not committed/cancelled");
4141N/A }
4141N/A }
4141N/A};
4141N/A
4141N/A#endif /* INCLUDE_TRACE */
4141N/A
4141N/A#endif /* SHARE_VM_TRACE_TRACEEVENT_HPP */