1 <?xml version="1.0" encoding="utf-8"?>
   2 <!--
   3  Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   4  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 
   6  This code is free software; you can redistribute it and/or modify it
   7  under the terms of the GNU General Public License version 2 only, as
   8  published by the Free Software Foundation.
   9 
  10  This code is distributed in the hope that it will be useful, but WITHOUT
  11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  version 2 for more details (a copy is included in the LICENSE file that
  14  accompanied this code).
  15 
  16  You should have received a copy of the GNU General Public License version
  17  2 along with this work; if not, write to the Free Software Foundation,
  18  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 
  20  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  or visit www.oracle.com if you need additional information or have any
  22  questions.
  23 -->
  24 
  25 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  26 <xsl:import href="xsl_util.xsl"/>
  27 <xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
  28 
  29 <xsl:template match="/">
  30   <xsl:call-template name="file-header"/>
  31 
  32 #ifndef TRACEFILES_TRACEEVENTCLASSES_HPP
  33 #define TRACEFILES_TRACEEVENTCLASSES_HPP
  34 
  35 // On purpose outside the INCLUDE_TRACE
  36 // Some parts of traceEvent.hpp are used outside of
  37 // INCLUDE_TRACE
  38 
  39 #include "trace/traceEvent.hpp"
  40 #include "tracefiles/traceTypes.hpp"
  41 #include "utilities/macros.hpp"
  42 #if INCLUDE_TRACE
  43 #include "jfr/recorder/service/jfrEvent.hpp"
  44 /*
  45  * Each event class has an assert member function verify() which is invoked
  46  * just before the engine writes the event and its fields to the data stream.
  47  * The purpose of verify() is to ensure that all fields in the event are initialized
  48  * and set before attempting to commit.
  49  *
  50  * We enforce this requirement because events are generally stack allocated and therefore
  51  * *not* initialized to default values. This prevents us from inadvertently committing
  52  * uninitialized values to the data stream.
  53  *
  54  * The assert message contains both the index (zero based) as well as the name of the field.
  55  */
  56 
  57 <xsl:apply-templates select="trace/events/struct" mode="jfr"/>
  58 <xsl:apply-templates select="trace/events/event" mode="jfr"/>
  59 
  60 #else // !INCLUDE_TRACE
  61 
  62 class TraceEvent {
  63  public:
  64   TraceEvent() {}
  65   void set_starttime(const JfrTraceTime&amp; ignore) const {}
  66   void set_endtime(const JfrTraceTime&amp; ignore) const {}
  67   void set_starttime(const Ticks&amp; ignore) const {}
  68   void set_endtime(const Ticks&amp; ignore) const {}
  69   bool should_commit() const { return false; }
  70   static bool is_enabled() { return false; }
  71   void commit() {}
  72 };
  73 
  74   <xsl:apply-templates select="trace/events/struct" mode="empty"/>
  75   <xsl:apply-templates select="trace/events/event" mode="empty"/>
  76 
  77 #endif // INCLUDE_TRACE
  78 #endif // JFRFILES_JFREVENTCLASSES_HPP
  79 </xsl:template>
  80 
  81 <xsl:template match="struct" mode="jfr">
  82 struct TraceStruct<xsl:value-of select="@id"/>
  83 {
  84  private:
  85 <xsl:apply-templates select="value" mode="write-fields"/>
  86 
  87  public:
  88 <xsl:apply-templates select="value" mode="write-setters"/>
  89 
  90   template &lt;typename Writer&gt;
  91   void writeData(Writer&amp; w) {
  92 <xsl:apply-templates select="value" mode="write-data"/>
  93   }
  94 };
  95 
  96 </xsl:template>
  97 
  98 <xsl:template match="struct" mode="empty">
  99 struct TraceStruct<xsl:value-of select="@id"/>
 100 {
 101  public:
 102 <xsl:apply-templates select="value" mode="write-empty-setters"/>
 103 };
 104 
 105 </xsl:template>
 106 
 107 <xsl:template match="event" mode="empty">
 108   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent')"/>
 109 {
 110  public:
 111 <xsl:value-of select="concat('  Event', @id, '(EventStartTime ignore=TIMED) {}')"/>
 112   <xsl:text>
 113 </xsl:text>
 114 
 115 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-empty-setters">
 116   <xsl:with-param name="cls" select="concat('Event',@id)"/>
 117 </xsl:apply-templates>
 118 };
 119 
 120 </xsl:template>
 121 
 122 <xsl:template match="event" mode="jfr">
 123   <xsl:value-of select="concat('class Event', @id, ' : public JfrTraceEvent&lt;Event', @id, '&gt;')"/>
 124 {
 125  private:
 126 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-fields"/>
 127 
 128  public:
 129   static const bool hasThread = <xsl:value-of select="@has_thread"/>;
 130   static const bool hasStackTrace = <xsl:value-of select="@has_stacktrace"/>;
 131   static const bool isInstant = <xsl:value-of select="@is_instant"/>;
 132   static const bool hasCutoff = <xsl:value-of select="@cutoff"/>;
 133   static const bool isRequestable = <xsl:value-of select="@is_requestable"/>;
 134   static const TraceEventId eventId = <xsl:value-of select="concat('Trace', @id, 'Event')"/>;
 135 
 136 <xsl:value-of select="concat('  Event', @id, '(EventStartTime timing=TIMED) : JfrTraceEvent&lt;Event', @id, '&gt;(timing) {}

')"/>
 137 
 138 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-setters-with-verification"/>
 139 
 140   template &lt;typename Writer&gt;
 141   void writeData(Writer&amp; w) {
 142 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-data"/>
 143   }
 144 
 145   using TraceEvent::commit; // else commit() is hidden by overloaded versions in this class
 146 
 147 <xsl:variable name="instant" select="@is_instant"/>
 148 
 149 <!-- non static method (only for non instant events)-->
 150 <xsl:if test="$instant='false'">
 151   <xsl:value-of select="concat('  Event', @id)"/>(
 152     <xsl:for-each select="value|structvalue|transition_value|relation">
 153     <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/>
 154     <xsl:if test="position() != last()">,
 155     </xsl:if></xsl:for-each>) : JfrTraceEvent&lt;<xsl:value-of select="concat('Event', @id)"/>&gt;(TIMED) {
 156     if (should_commit()) {<xsl:for-each select="value|structvalue|transition_value|relation">
 157       set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);</xsl:for-each>
 158     }
 159   }
 160 
 161   void commit(<xsl:for-each select="value|structvalue|transition_value|relation">
 162     <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/>
 163     <xsl:if test="position() != last()">,
 164               </xsl:if></xsl:for-each>) {
 165     if (should_commit()) {
 166       <xsl:for-each select="value|structvalue|transition_value|relation">set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);
 167       </xsl:for-each>commit();
 168     }
 169   }</xsl:if>
 170 <!-- static method (for all events) -->
 171   static void commit(<xsl:if test="$instant='false'">const Ticks&amp; startTicks,
 172                      const Ticks&amp; endTicks<xsl:choose><xsl:when test="value|structvalue|transition_value|relation">,
 173                      </xsl:when></xsl:choose></xsl:if>
 174                      <xsl:for-each select="value|structvalue|transition_value|relation">
 175     <xsl:apply-templates select="." mode="cpp-type"/><xsl:value-of select="concat(' ', @field)"/>
 176     <xsl:if test="position() != last()">,
 177                      </xsl:if></xsl:for-each>) {
 178     <xsl:value-of select="concat('Event', @id)"/> me(UNTIMED);
 179 
 180     if (me.should_commit()) {
 181       <xsl:if test="$instant='false'">me.set_starttime(startTicks);
 182       me.set_endtime(endTicks);
 183       </xsl:if>
 184       <xsl:for-each select="value|structvalue|transition_value|relation">me.set_<xsl:value-of select="@field"/>(<xsl:value-of select="@field"/>);
 185       </xsl:for-each>me.commit();
 186     }
 187   }
 188 
 189 #ifdef ASSERT
 190   void verify() const {
 191 <xsl:apply-templates select="value" mode="write-verify"/>
 192   }
 193 #endif
 194 };
 195 <xsl:text>
 196 </xsl:text>
 197 </xsl:template>
 198 
 199 <xsl:template match="value|transition_value|relation" mode="write-empty-setters">
 200   <xsl:param name="cls"/>
 201   <xsl:variable name="type" select="@type"/>
 202   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 203   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' ignore) { }')"/>
 204   <xsl:if test="position() != last()">
 205     <xsl:text>
 206 </xsl:text>
 207   </xsl:if>
 208 </xsl:template>
 209 
 210 <xsl:template match="structvalue" mode="write-empty-setters">
 211   <xsl:param name="cls"/>
 212   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; ignore) { }')"/>
 213   <xsl:if test="position() != last()">
 214     <xsl:text>
 215 </xsl:text>
 216   </xsl:if>
 217 </xsl:template>
 218 
 219 <xsl:template match="value[@type='TICKS']" mode="write-setters">
 220   <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; time) {
    this->_', @field, ' = time; }')"/>
 221   <xsl:text>
</xsl:text>
 222 </xsl:template>
 223 
 224 <xsl:template match="value[@type='TICKS']" mode="write-setters-with-verification">
 225   <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; time) {
    this->_', @field, ' = time;
')"/>
 226   <xsl:value-of select="concat('    DEBUG_ONLY(set_field_bit(', position() - 1, '));
  }')"/>
 227   <xsl:text>
</xsl:text>
 228 </xsl:template>
 229 
 230 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters">
 231   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; time) {
    this->_', @field, ' = time; }')"/>
 232   <xsl:text>
</xsl:text>
 233 </xsl:template>
 234 
 235 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters-with-verification">
 236   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; time) {
    this->_', @field, ' = time;
')"/>
 237   <xsl:value-of select="concat('    DEBUG_ONLY(set_field_bit(', position() - 1, '));
  }')"/>
 238   <xsl:text>
</xsl:text>
 239 </xsl:template>
 240 
 241 <xsl:template match="value|transition_value|relation" mode="write-setters">
 242   <xsl:param name="cls"/>
 243   <xsl:variable name="type" select="@type"/>
 244   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 245   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' new_value) { this->_', @field, ' = new_value; }')"/>
 246   <xsl:if test="position() != last()">
 247     <xsl:text>
 248 </xsl:text>
 249   </xsl:if>
 250 </xsl:template>
 251 
 252 <xsl:template match="value|transition|relation" mode="write-setters-with-verification">
 253   <xsl:param name="cls"/>
 254   <xsl:variable name="type" select="@type"/>
 255   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 256   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' new_value) {
    this->_', @field, ' = new_value;
')"/>
 257   <xsl:value-of select="concat('    DEBUG_ONLY(set_field_bit(', position() - 1, '));
  }')"/>
 258   <xsl:if test="position() != last()">
 259     <xsl:text>
 260 </xsl:text>
 261   </xsl:if>
 262 </xsl:template>
 263 
 264 <xsl:template match="structvalue" mode="write-setters">
 265   <xsl:param name="cls"/>
 266   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { this->_', @field, ' = value; }')"/>
 267   <xsl:if test="position() != last()">
 268     <xsl:text>
 269 </xsl:text>
 270   </xsl:if>
 271 </xsl:template>
 272 
 273 <xsl:template match="structvalue" mode="write-setters-with-verification">
 274   <xsl:param name="cls"/>
 275   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) {
    this->_', @field, ' = value;
')"/>
 276   <xsl:value-of select="concat('    DEBUG_ONLY(set_field_bit(', position() - 1, '));
')"/>
 277   <xsl:text>  }</xsl:text>
 278   <xsl:if test="position() != last()">
 279     <xsl:text>
 280 </xsl:text>
 281   </xsl:if>
 282 </xsl:template>
 283 
 284 <xsl:template match="value|transition_value|relation" mode="write-fields">
 285   <xsl:variable name="type" select="@type"/>
 286   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 287   <xsl:value-of select="concat('  ', $wt, ' _', @field, ';')"/>
 288   <xsl:if test="position() != last()">
 289     <xsl:text>
 290 </xsl:text>
 291   </xsl:if>
 292 </xsl:template>
 293 
 294 <xsl:template match="structvalue" mode="write-fields">
 295   <xsl:value-of select="concat('  TraceStruct', @type, ' _', @field, ';')"/>
 296   <xsl:if test="position() != last()">
 297     <xsl:text>
 298 </xsl:text>
 299   </xsl:if>
 300 </xsl:template>
 301 
 302 <xsl:template match="value" mode="write-verify">
 303   <xsl:param name="cls"/>
 304   <xsl:text>    </xsl:text>
 305   <xsl:value-of select="concat('assert(verify_field_bit(', position() - 1, '), ' , $quote, 'Attempting to write an uninitialized event field: %s', $quote,', ', $quote, '_', @field, $quote, ');')"/>
 306   <xsl:if test="position() != last()">
 307     <xsl:text>
 308 </xsl:text>
 309   </xsl:if>
 310 </xsl:template>
 311 
 312 <xsl:template match="value|transition_value|relation" mode="write-data">
 313   <xsl:variable name="type" select="@type"/>
 314   <xsl:value-of select="concat('    w.write(_', @field, ');')"/>
 315   <xsl:if test="position() != last()">
 316     <xsl:text>
 317 </xsl:text>
 318   </xsl:if>
 319 </xsl:template>
 320 
 321 <xsl:template match="structvalue" mode="write-data">
 322   <xsl:variable name="structtype" select="@type"/>
 323   <xsl:variable name="structname" select="@field"/>
 324   <xsl:value-of select="concat('    _', @field, '.writeData(w);')"/>
 325     <xsl:if test="position() != last()">
 326       <xsl:text>
 327 </xsl:text>
 328     </xsl:if>
 329 </xsl:template>
 330 
 331 
 332 <xsl:template match="value|transition_value|relation" mode="cpp-type">
 333   <xsl:variable name="type" select="@type"/>
 334   <xsl:value-of select="//primary_type[@symbol=$type]/@type"/>
 335 </xsl:template>
 336 <xsl:template match="structvalue" mode="cpp-type">
 337   <xsl:value-of select="concat('const TraceStruct', @type, '&amp;')"/>
 338 </xsl:template>
 339 
 340 </xsl:stylesheet>