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