1 <?xml version="1.0" encoding="utf-8"?>
   2 <!--
   3  Copyright (c) 2002, 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 
  26 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  27                 version="1.0">
  28 
  29   <xsl:import href="jvmtiLib.xsl"/>
  30 
  31   <xsl:output method="text" omit-xml-declaration="yes"/>
  32 
  33   <xsl:template match="/">
  34     <xsl:apply-templates select="specification"/>
  35   </xsl:template>
  36 
  37   <xsl:template match="specification">
  38 
  39     <xsl:call-template name="intro"/>
  40 
  41     <xsl:text>/* Derived Base Types */
  42 </xsl:text>
  43     <xsl:apply-templates select="//basetype"/>
  44 
  45     <xsl:text>
  46 
  47     /* Constants */
  48 </xsl:text>
  49     <xsl:apply-templates select="//constants"/>
  50 
  51     <xsl:text>
  52 
  53     /* Errors */
  54 
  55 typedef enum {
  56 </xsl:text>
  57      <xsl:for-each select="//errorid">
  58        <xsl:sort select="@num" data-type="number"/>
  59          <xsl:apply-templates select="." mode="enum"/>
  60          <xsl:text>,
  61 </xsl:text>
  62          <xsl:if test="position() = last()">
  63            <xsl:text>    JVMTI_ERROR_MAX = </xsl:text>
  64            <xsl:value-of select="@num"/>
  65          </xsl:if>
  66      </xsl:for-each>
  67     <xsl:text>
  68 } jvmtiError;
  69 </xsl:text>
  70     <xsl:apply-templates select="eventsection" mode="enum"/>
  71 
  72     <xsl:text>
  73     /* Pre-Declarations */
  74 </xsl:text>
  75 <xsl:apply-templates select="//typedef|//uniontypedef" mode="early"/>
  76 
  77     <xsl:text>
  78     /* Function Types */
  79 </xsl:text>
  80     <xsl:apply-templates select="//callback"/>
  81 
  82     <xsl:text>
  83 
  84     /* Structure Types */
  85 </xsl:text>
  86     <xsl:apply-templates select="//typedef|//uniontypedef" mode="body"/>
  87     <xsl:apply-templates select="//capabilitiestypedef"/>
  88 
  89     <xsl:apply-templates select="eventsection" mode="body"/>
  90 
  91     <xsl:apply-templates select="functionsection"/>
  92 
  93     <xsl:call-template name="outro"/>
  94 
  95   </xsl:template>
  96 
  97   <xsl:template name="intro">
  98   <xsl:call-template name="include_GPL_CP_Header"/>
  99   <xsl:text>
 100     /* Include file for the Java(tm) Virtual Machine Tool Interface */
 101 
 102 #ifndef _JAVA_JVMTI_H_
 103 #define _JAVA_JVMTI_H_
 104 
 105 #include "jni.h"
 106 
 107 #ifdef __cplusplus
 108 extern "C" {
 109 #endif
 110 
 111 enum {
 112     JVMTI_VERSION_1   = 0x30010000,
 113     JVMTI_VERSION_1_0 = 0x30010000,
 114     JVMTI_VERSION_1_1 = 0x30010100,
 115     JVMTI_VERSION_1_2 = 0x30010200,
 116     JVMTI_VERSION_9   = 0x30090000,
 117     JVMTI_VERSION_11  = 0x300B0000,
 118 
 119     JVMTI_VERSION = 0x30000000 + (</xsl:text>
 120   <xsl:value-of select="//specification/@majorversion"/>
 121   <xsl:text> * 0x10000) + (</xsl:text>
 122   <xsl:value-of select="//specification/@minorversion"/>
 123   <xsl:text> * 0x100)</xsl:text>
 124   <xsl:variable name="micro">
 125     <xsl:call-template name="microversion"/>
 126   </xsl:variable>
 127   <xsl:choose>
 128     <xsl:when test="string($micro)='dev'">
 129       <xsl:text>  /* checked out - </xsl:text>
 130     </xsl:when>
 131     <xsl:otherwise>
 132       <xsl:text> + </xsl:text>
 133       <xsl:value-of select="$micro"/>
 134       <xsl:text>  /* </xsl:text>
 135     </xsl:otherwise>
 136   </xsl:choose>
 137   <xsl:text>version: </xsl:text>
 138   <xsl:call-template name="showversion"/>
 139   <xsl:text> */
 140 };
 141 
 142 JNIEXPORT jint JNICALL
 143 Agent_OnLoad(JavaVM *vm, char *options, void *reserved);
 144 
 145 JNIEXPORT jint JNICALL
 146 Agent_OnAttach(JavaVM* vm, char* options, void* reserved);
 147 
 148 JNIEXPORT void JNICALL
 149 Agent_OnUnload(JavaVM *vm);
 150 
 151     /* Forward declaration of the environment */
 152 
 153 struct _jvmtiEnv;
 154 
 155 struct jvmtiInterface_1_;
 156 
 157 #ifdef __cplusplus
 158 typedef _jvmtiEnv jvmtiEnv;
 159 #else
 160 typedef const struct jvmtiInterface_1_ *jvmtiEnv;
 161 #endif /* __cplusplus */
 162 
 163 </xsl:text>
 164   </xsl:template>
 165 
 166   <xsl:template name="outro">
 167   <xsl:text>
 168 
 169 #ifdef __cplusplus
 170 } /* extern "C" */
 171 #endif /* __cplusplus */
 172 
 173 #endif /* !_JAVA_JVMTI_H_ */
 174 </xsl:text>
 175 </xsl:template>
 176 
 177 <xsl:template match="eventsection" mode="enum">
 178   <xsl:text>
 179     /* Event IDs */
 180 
 181 typedef enum {
 182 </xsl:text>
 183      <xsl:for-each select="event">
 184        <xsl:sort select="@num" data-type="number"/>
 185        <xsl:if test="position()=1">
 186          <xsl:text>    JVMTI_MIN_EVENT_TYPE_VAL = </xsl:text>
 187          <xsl:value-of select="@num"/>
 188          <xsl:text>,
 189 </xsl:text>
 190        </xsl:if>
 191        <xsl:apply-templates select="." mode="enum"/>
 192        <xsl:text>,
 193 </xsl:text>
 194        <xsl:if test="position()=last()">
 195          <xsl:text>    JVMTI_MAX_EVENT_TYPE_VAL = </xsl:text>
 196          <xsl:value-of select="@num"/>
 197        </xsl:if>
 198      </xsl:for-each>
 199     <xsl:text>
 200 } jvmtiEvent;
 201 
 202 </xsl:text>
 203 </xsl:template>
 204 
 205 <xsl:template match="eventsection" mode="body">
 206   <xsl:text>
 207 
 208     /* Event Definitions */
 209 
 210 typedef void (JNICALL *jvmtiEventReserved)(void);
 211 
 212 </xsl:text>
 213   <xsl:apply-templates select="event" mode="definition">
 214     <xsl:sort select="@id"/>
 215   </xsl:apply-templates>
 216 
 217   <xsl:text>
 218     /* Event Callback Structure */
 219 
 220 typedef struct {
 221 </xsl:text>
 222   <xsl:call-template name="eventStruct">
 223     <xsl:with-param name="events" select="event"/>
 224     <xsl:with-param name="index" select="0"/>
 225     <xsl:with-param name="started" select="false"/>
 226     <xsl:with-param name="comment" select="'Yes'"/>
 227   </xsl:call-template>
 228   <xsl:text>} jvmtiEventCallbacks;
 229 </xsl:text>
 230 
 231 </xsl:template>
 232 
 233 
 234 <xsl:template match="event" mode="definition">
 235   <xsl:text>
 236 typedef void (JNICALL *jvmtiEvent</xsl:text>
 237   <xsl:value-of select="@id"/>
 238   <xsl:text>)
 239     (jvmtiEnv *jvmti_env</xsl:text>
 240   <xsl:apply-templates select="parameters" mode="signature">
 241     <xsl:with-param name="comma">
 242       <xsl:text>,
 243      </xsl:text>
 244     </xsl:with-param>
 245    </xsl:apply-templates>
 246  <xsl:text>);
 247 </xsl:text>
 248 </xsl:template>
 249 
 250 <xsl:template match="functionsection">
 251    <xsl:text>
 252 
 253     /* Function Interface */
 254 
 255 typedef struct jvmtiInterface_1_ {
 256 
 257 </xsl:text>
 258   <xsl:call-template name="funcStruct">
 259     <xsl:with-param name="funcs" select="category/function[count(@hide)=0]"/>
 260     <xsl:with-param name="index" select="1"/>
 261   </xsl:call-template>
 262 
 263   <xsl:text>} jvmtiInterface_1;
 264 
 265 struct _jvmtiEnv {
 266     const struct jvmtiInterface_1_ *functions;
 267 #ifdef __cplusplus
 268 
 269 </xsl:text>
 270   <xsl:apply-templates select="category" mode="cppinline"/>
 271   <xsl:text>
 272 #endif /* __cplusplus */
 273 };
 274 </xsl:text>
 275 
 276 </xsl:template>
 277 
 278 <xsl:template name="funcStruct">
 279   <xsl:param name="funcs"/>
 280   <xsl:param name="index"/>
 281   <xsl:variable name="thisFunction" select="$funcs[@num=$index]"/>
 282   <xsl:text>  /* </xsl:text>
 283   <xsl:number value="$index" format="  1"/>
 284   <xsl:text> : </xsl:text>
 285   <xsl:choose>
 286     <xsl:when test="count($thisFunction)=1">
 287       <xsl:value-of select="$thisFunction/synopsis"/>
 288       <xsl:text> */
 289   jvmtiError (JNICALL *</xsl:text>
 290       <xsl:value-of select="$thisFunction/@id"/>
 291       <xsl:text>) (jvmtiEnv* env</xsl:text>
 292       <xsl:apply-templates select="$thisFunction/parameters" mode="signature">
 293         <xsl:with-param name="comma">
 294           <xsl:text>,
 295     </xsl:text>
 296         </xsl:with-param>
 297       </xsl:apply-templates>
 298       <xsl:text>)</xsl:text>
 299     </xsl:when>
 300     <xsl:otherwise>
 301       <xsl:text> RESERVED */
 302   void *reserved</xsl:text>
 303       <xsl:value-of select="$index"/>
 304     </xsl:otherwise>
 305   </xsl:choose>
 306   <xsl:text>;
 307 
 308 </xsl:text>
 309   <xsl:if test="count($funcs[@num &gt; $index]) &gt; 0">
 310     <xsl:call-template name="funcStruct">
 311       <xsl:with-param name="funcs" select="$funcs"/>
 312       <xsl:with-param name="index" select="1+$index"/>
 313     </xsl:call-template>
 314   </xsl:if>
 315 </xsl:template>
 316 
 317 
 318 <xsl:template match="function">
 319   <xsl:text>  jvmtiError (JNICALL *</xsl:text>
 320   <xsl:value-of select="@id"/>
 321   <xsl:text>) (jvmtiEnv* env</xsl:text>
 322   <xsl:apply-templates select="parameters" mode="signature"/>
 323   <xsl:text>);
 324 
 325 </xsl:text>
 326 </xsl:template>
 327 
 328 <xsl:template match="category" mode="cppinline">
 329     <xsl:apply-templates select="function[count(@hide)=0]" mode="cppinline"/>
 330 </xsl:template>
 331 
 332 <xsl:template match="function" mode="cppinline">
 333   <xsl:text>
 334   jvmtiError </xsl:text>
 335   <xsl:value-of select="@id"/>
 336   <xsl:text>(</xsl:text>
 337   <xsl:apply-templates select="parameters" mode="signaturenoleadcomma"/>
 338   <xsl:text>) {
 339     return functions-></xsl:text>
 340   <xsl:value-of select="@id"/>
 341   <xsl:text>(this</xsl:text>
 342   <xsl:for-each select="parameters">
 343     <xsl:for-each select="param">
 344       <xsl:if test="@id != '...' and count(jclass/@method) = 0">
 345         <xsl:text>, </xsl:text>
 346         <xsl:value-of select="@id"/>
 347       </xsl:if>
 348     </xsl:for-each>
 349   </xsl:for-each>
 350   <xsl:text>);
 351   }
 352 </xsl:text>
 353 </xsl:template>
 354 
 355 
 356   <xsl:template match="basetype">
 357     <xsl:if test="count(definition)!=0">
 358       <xsl:text>
 359 </xsl:text>
 360       <xsl:apply-templates select="definition"/>
 361     </xsl:if>
 362   </xsl:template>
 363 
 364   <xsl:template match="constants">
 365     <xsl:text>
 366 
 367     /* </xsl:text>
 368     <xsl:value-of select="@label"/>
 369     <xsl:text> */
 370 </xsl:text>
 371     <xsl:choose>
 372       <xsl:when test="@kind='enum'">
 373         <xsl:apply-templates select="." mode="enum"/>
 374       </xsl:when>
 375       <xsl:otherwise>
 376         <xsl:apply-templates select="." mode="constants"/>
 377       </xsl:otherwise>
 378     </xsl:choose>
 379   </xsl:template>
 380 
 381 <xsl:template match="callback">
 382       <xsl:text>
 383 typedef </xsl:text>
 384       <xsl:apply-templates select="child::*[position()=1]" mode="signature"/>
 385       <xsl:text> (JNICALL *</xsl:text>
 386       <xsl:value-of select="@id"/>
 387       <xsl:text>)
 388     (</xsl:text>
 389       <xsl:for-each select="parameters">
 390         <xsl:apply-templates select="param[position()=1]" mode="signature"/>
 391         <xsl:for-each select="param[position()>1]">
 392           <xsl:text>, </xsl:text>
 393           <xsl:apply-templates select="." mode="signature"/>
 394         </xsl:for-each>
 395       </xsl:for-each>
 396       <xsl:text>);
 397 </xsl:text>
 398 </xsl:template>
 399 
 400 <xsl:template match="capabilitiestypedef">
 401   <xsl:text>
 402 </xsl:text>
 403   <xsl:apply-templates select="." mode="genstruct"/>
 404   <xsl:text>
 405 </xsl:text>
 406 </xsl:template>
 407 
 408 <xsl:template match="typedef" mode="early">
 409   <xsl:text>struct _</xsl:text>
 410   <xsl:value-of select="@id"/>
 411   <xsl:text>;
 412 </xsl:text>
 413   <xsl:text>typedef struct _</xsl:text>
 414   <xsl:value-of select="@id"/>
 415   <xsl:text> </xsl:text>
 416   <xsl:value-of select="@id"/>
 417   <xsl:text>;
 418 </xsl:text>
 419 </xsl:template>
 420 
 421 <xsl:template match="typedef" mode="body">
 422   <xsl:text>struct _</xsl:text>
 423   <xsl:value-of select="@id"/>
 424   <xsl:text> {
 425 </xsl:text>
 426 <xsl:apply-templates select="field" mode="signature"/>
 427   <xsl:text>};
 428 </xsl:text>
 429 </xsl:template>
 430 
 431 <xsl:template match="uniontypedef" mode="early">
 432   <xsl:text>union _</xsl:text>
 433   <xsl:value-of select="@id"/>
 434   <xsl:text>;
 435 </xsl:text>
 436   <xsl:text>typedef union _</xsl:text>
 437   <xsl:value-of select="@id"/>
 438   <xsl:text> </xsl:text>
 439   <xsl:value-of select="@id"/>
 440   <xsl:text>;
 441 </xsl:text>
 442 </xsl:template>
 443 
 444 <xsl:template match="uniontypedef" mode="body">
 445   <xsl:text>union _</xsl:text>
 446   <xsl:value-of select="@id"/>
 447   <xsl:text> {
 448 </xsl:text>
 449 <xsl:apply-templates select="field" mode="signature"/>
 450   <xsl:text>};
 451 </xsl:text>
 452 </xsl:template>
 453 
 454 </xsl:stylesheet>