1 <?xml version="1.0" encoding="utf-8"?>
   2 <!--
   3  Copyright (c) 2012, 2014, 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 "memory/resourceArea.hpp"
  40 #include "tracefiles/traceTypes.hpp"
  41 #include "trace/traceEvent.hpp"
  42 #include "utilities/macros.hpp"
  43 #include "utilities/ticks.hpp"
  44 #if INCLUDE_TRACE
  45 #include "trace/traceStream.hpp"
  46 #include "utilities/ostream.hpp"
  47 
  48   <xsl:apply-templates select="trace/events/struct" mode="trace"/>
  49   <xsl:apply-templates select="trace/events/event" mode="trace"/>
  50 
  51 #else // !INCLUDE_TRACE
  52 
  53 class TraceEvent {
  54 public:
  55   TraceEvent() {}
  56   void set_starttime(const Ticks&amp; time) {}
  57   void set_endtime(const Ticks&amp; time) {}
  58   bool should_commit() const { return false; }
  59   static bool is_enabled() { return false; }
  60   void commit() const {}
  61 };
  62 
  63   <xsl:apply-templates select="trace/events/struct" mode="empty"/>
  64   <xsl:apply-templates select="trace/events/event" mode="empty"/>
  65 
  66 #endif // INCLUDE_TRACE
  67 #endif // TRACEFILES_TRACEEVENTCLASSES_HPP
  68 </xsl:template>
  69 
  70 <xsl:template match="struct" mode="trace">
  71 struct TraceStruct<xsl:value-of select="@id"/>
  72 {
  73 private:
  74 <xsl:apply-templates select="value" mode="write-fields"/>
  75 public:
  76 <xsl:apply-templates select="value" mode="write-setters"/>
  77 
  78   void writeStruct(TraceStream&amp; ts) {
  79 <xsl:apply-templates select="value" mode="write-data"/>
  80   }
  81 };
  82 
  83 </xsl:template>
  84 
  85 <xsl:template match="struct" mode="empty">
  86 struct TraceStruct<xsl:value-of select="@id"/> 
  87 {
  88 public:
  89 <xsl:apply-templates select="value" mode="write-empty-setters"/>
  90 };
  91 </xsl:template>
  92 
  93 
  94 <xsl:template match="event" mode="empty">
  95   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent')"/>
  96 {
  97  public:
  98 <xsl:value-of select="concat('  Event', @id, '(bool ignore=true) {}')"/>
  99 <xsl:text>
 100 </xsl:text>
 101 
 102 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-empty-setters"/>
 103 };
 104 
 105 </xsl:template>
 106 
 107 
 108 <xsl:template match="event" mode="trace">
 109   <xsl:value-of select="concat('class Event', @id, ' : public TraceEvent&lt;Event', @id, '&gt;')"/>
 110 {
 111  public:
 112   static const bool hasThread = <xsl:value-of select="@has_thread"/>;
 113   static const bool hasStackTrace = <xsl:value-of select="@has_stacktrace"/>;
 114   static const bool isInstant = <xsl:value-of select="@is_instant"/>;
 115   static const bool isRequestable = <xsl:value-of select="@is_requestable"/>;
 116   static const TraceEventId eventId = <xsl:value-of select="concat('Trace', @id, 'Event')"/>;
 117 
 118  private:
 119 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-fields"/>
 120 
 121   void writeEventContent(void) {
 122     TraceStream ts(*tty);
 123     ts.print("<xsl:value-of select="@label"/>: [");
 124 <xsl:apply-templates select="value|structvalue" mode="write-data"/>
 125     ts.print("]\n");
 126   }
 127 
 128  public:
 129 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-setters"/>
 130 
 131   bool should_write(void) {
 132     return true;
 133   }
 134 <xsl:text>
 135 
 136 </xsl:text>
 137   <xsl:value-of select="concat('  Event', @id, '(EventStartTime timing=TIMED) : TraceEvent&lt;Event', @id, '&gt;(timing) {}', $newline)"/>
 138   void writeEvent(void) {
 139     bool thread_has_resource = Thread::current() != NULL;
 140     ResourceArea *area = thread_has_resource
 141                            ? Thread::current()->resource_area()
 142                            : new (mtTracing)ResourceArea(Chunk::non_pool_size);
 143     ResourceMark rm(area);
 144     if (UseLockedTracing) {
 145       ttyLocker lock;
 146       writeEventContent();
 147     } else {
 148       writeEventContent();
 149     }
 150 
 151     if (!thread_has_resource) {
 152       delete area;
 153     }
 154   }
 155 };
 156 
 157 </xsl:template>
 158 
 159 <xsl:template match="value|transition_value|relation" mode="write-empty-setters">
 160   <xsl:param name="cls"/>
 161   <xsl:variable name="type" select="@type"/>
 162   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 163   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { }')"/>
 164   <xsl:if test="position() != last()">
 165     <xsl:text>
 166 </xsl:text>
 167   </xsl:if>
 168 </xsl:template>
 169 
 170 <xsl:template match="structvalue" mode="write-empty-setters">
 171   <xsl:param name="cls"/>
 172   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { }')"/>
 173   <xsl:if test="position() != last()">
 174     <xsl:text>
 175 </xsl:text>
 176   </xsl:if>
 177 </xsl:template>
 178 
 179 <xsl:template match="value[@type='TICKS']" mode="write-setters">
 180 #if INCLUDE_TRACE
 181 <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; time) { _', @field, ' = time; }')"/>
 182 #else
 183 <xsl:value-of select="concat('  void set_', @field, '(const Ticks&amp; ignore) {}')"/>
 184 #endif
 185 </xsl:template>
 186 
 187 <xsl:template match="value[@type='TICKSPAN']" mode="write-setters">
 188 #if INCLUDE_TRACE
 189   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; time) { _', @field, ' = time; }')"/>
 190 #else
 191   <xsl:value-of select="concat('  void set_', @field, '(const Tickspan&amp; ignore) {}')"/>
 192 #endif
 193 </xsl:template>
 194 
 195 
 196 <xsl:template match="value" mode="write-fields">
 197   <xsl:variable name="type" select="@type"/>
 198   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 199   <xsl:value-of select="concat('  ', $wt, ' _', @field, ';')"/>
 200   <xsl:if test="position() != last()">
 201     <xsl:text> 
 202 </xsl:text>
 203   </xsl:if>
 204 </xsl:template>
 205 
 206 <xsl:template match="structvalue" mode="write-fields">
 207   <xsl:value-of select="concat('  TraceStruct', @type, ' _', @field, ';')"/>
 208   <xsl:text>
 209 </xsl:text>
 210 </xsl:template>
 211 
 212 <xsl:template match="value|transition_value|relation" mode="write-setters">
 213   <xsl:param name="cls"/>
 214   <xsl:variable name="type" select="@type"/>
 215   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 216   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { this->_', @field, ' = value; }')"/>
 217   <xsl:if test="position() != last()">
 218     <xsl:text>
 219 </xsl:text>
 220   </xsl:if>
 221 </xsl:template>
 222 
 223 <xsl:template match="structvalue" mode="write-setters">
 224   <xsl:param name="cls"/>
 225   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { this->_', @field, ' = value; }')"/>
 226   <xsl:if test="position() != last()">
 227     <xsl:text>
 228 </xsl:text>
 229   </xsl:if>
 230 </xsl:template>
 231 
 232 <xsl:template match="value" mode="write-data">
 233   <xsl:variable name="type" select="@type"/>
 234   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@writetype"/>
 235   <xsl:choose>
 236     <xsl:when test="@type='TICKSPAN'">
 237       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, '.value());')"/>
 238     </xsl:when>
 239     <xsl:when test="@type='TICKS'">
 240       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, '.value());')"/>
 241     </xsl:when>
 242     <xsl:otherwise>
 243       <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, ');')"/>
 244     </xsl:otherwise>
 245   </xsl:choose>
 246   <xsl:if test="position() != last()">
 247     <xsl:text>
 248     ts.print(", ");
 249 </xsl:text>
 250   </xsl:if>
 251 </xsl:template>
 252 
 253 <xsl:template match="structvalue" mode="write-data">
 254   <xsl:value-of select="concat('    _', @field, '.writeStruct(ts);')"/>
 255   <xsl:if test="position() != last()">
 256     <xsl:text>
 257     ts.print(", ");
 258 </xsl:text>
 259   </xsl:if>
 260 </xsl:template>
 261 
 262 </xsl:stylesheet>