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 "tracefiles/traceTypes.hpp"
  41 #include "trace/traceEvent.hpp"
  42 
  43 #if INCLUDE_TRACE
  44 
  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
  52 
  53 class TraceEvent {
  54 public:
  55   TraceEvent() {}
  56   void set_starttime(jlong time) const {}
  57   void set_endtime(jlong time) const {}
  58   bool should_commit() const { return false; }
  59   void commit() const {}
  60 };
  61 
  62   <xsl:apply-templates select="trace/events/struct" mode="empty"/>
  63   <xsl:apply-templates select="trace/events/event" mode="empty"/>
  64 
  65 #endif
  66 
  67 #endif
  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  public:
 122 <xsl:apply-templates select="value|structvalue|transition_value|relation" mode="write-setters"/>
 123 
 124   bool should_write(void) {
 125     return true;
 126   }
 127 <xsl:text>
 128 
 129 </xsl:text>
 130   <xsl:value-of select="concat('  Event', @id, '(EventStartTime timing=TIMED) : TraceEvent&lt;Event', @id, '&gt;(timing) {}', $newline)"/>
 131   void writeEvent(void) {
 132     ResourceMark rm;
 133     TraceStream ts(*tty);
 134     ts.print("<xsl:value-of select="@label"/>: [");
 135 <xsl:apply-templates select="value|structvalue" mode="write-data"/>
 136     ts.print("]\n");
 137   }
 138 };
 139 
 140 </xsl:template>
 141 
 142 <xsl:template match="value|transition_value|relation" mode="write-empty-setters">
 143   <xsl:param name="cls"/>
 144   <xsl:variable name="type" select="@type"/>
 145   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 146   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { }')"/>
 147   <xsl:if test="position() != last()">
 148     <xsl:text>
 149 </xsl:text>
 150   </xsl:if>
 151 </xsl:template>
 152 
 153 <xsl:template match="structvalue" mode="write-empty-setters">
 154   <xsl:param name="cls"/>
 155   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { }')"/>
 156   <xsl:if test="position() != last()">
 157     <xsl:text>
 158 </xsl:text>
 159   </xsl:if>
 160 </xsl:template>
 161 
 162 
 163 <xsl:template match="value[@type='TICKS']" mode="write-setters">
 164 #if INCLUDE_TRACE
 165   <xsl:value-of select="concat('void set_', @field, '(jlong time) { _', @field, ' = time; }')"/>
 166 #else
 167   <xsl:value-of select="concat('void set_', @field, '(jlong ignore) {}')"/>
 168 #endif
 169 </xsl:template>
 170 
 171 <xsl:template match="value" mode="write-fields">
 172   <xsl:variable name="type" select="@type"/>
 173   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 174   <xsl:value-of select="concat('  ', $wt, ' _', @field, ';')"/>
 175   <xsl:if test="position() != last()">
 176     <xsl:text> 
 177 </xsl:text>
 178   </xsl:if>
 179 </xsl:template>
 180 
 181 <xsl:template match="structvalue" mode="write-fields">
 182   <xsl:value-of select="concat('  TraceStruct', @type, ' _', @field, ';')"/>
 183   <xsl:text>
 184 </xsl:text>
 185 </xsl:template>
 186 
 187 <xsl:template match="value|transition_value|relation" mode="write-setters">
 188   <xsl:param name="cls"/>
 189   <xsl:variable name="type" select="@type"/>
 190   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@type"/>
 191   <xsl:value-of select="concat('  void set_', @field, '(', $wt, ' value) { this->_', @field, ' = value; }')"/>
 192   <xsl:if test="position() != last()">
 193     <xsl:text>
 194 </xsl:text>
 195   </xsl:if>
 196 </xsl:template>
 197 
 198 <xsl:template match="structvalue" mode="write-setters">
 199   <xsl:param name="cls"/>
 200   <xsl:value-of select="concat('  void set_', @field, '(const TraceStruct', @type, '&amp; value) { this->_', @field, ' = value; }')"/>
 201   <xsl:if test="position() != last()">
 202     <xsl:text>
 203 </xsl:text>
 204   </xsl:if>
 205 </xsl:template>
 206 
 207 <xsl:template match="value" mode="write-data">
 208   <xsl:variable name="type" select="@type"/>
 209   <xsl:variable name="wt" select="//primary_type[@symbol=$type]/@writetype"/>
 210   <xsl:value-of select="concat('    ts.print_val(&quot;', @label, '&quot;, _', @field, ');')"/>
 211   <xsl:if test="position() != last()">
 212     <xsl:text>
 213     ts.print(", ");
 214 </xsl:text>
 215   </xsl:if>
 216 </xsl:template>
 217 
 218 <xsl:template match="structvalue" mode="write-data">
 219   <xsl:value-of select="concat('    _', @field, '.writeStruct(ts);')"/>
 220   <xsl:if test="position() != last()">
 221     <xsl:text>
 222     ts.print(", ");
 223 </xsl:text>
 224   </xsl:if>
 225 </xsl:template>
 226 
 227 </xsl:stylesheet>