1 <?xml version="1.0" encoding="utf-8"?>
  2 <!--
  3  Copyright (c) 2002, 2020, 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     JVMTI_VERSION_19  = 0x30130000,
119     JVMTI_VERSION_21  = 0x30150000,
120 
121     JVMTI_VERSION = 0x30000000 + (</xsl:text>
122   <xsl:value-of select="$majorversion"/>
123   <xsl:text> * 0x10000) + (</xsl:text>
124   <!-- Now minorversion is always 0 -->
125   <xsl:text> 0 * 0x100)</xsl:text>
126   <xsl:variable name="micro">
127     <xsl:call-template name="microversion"/>
128   </xsl:variable>
129   <xsl:choose>
130     <xsl:when test="string($micro)='dev'">
131       <xsl:text>  /* checked out - </xsl:text>
132     </xsl:when>
133     <xsl:otherwise>
134       <xsl:text> + </xsl:text>
135       <xsl:value-of select="$micro"/>
136       <xsl:text>  /* </xsl:text>
137     </xsl:otherwise>
138   </xsl:choose>
139   <xsl:text>version: </xsl:text>
140   <xsl:call-template name="showversion"/>
141   <xsl:text> */
142 };
143 
144 JNIEXPORT jint JNICALL
145 Agent_OnLoad(JavaVM *vm, char *options, void *reserved);
146 
147 JNIEXPORT jint JNICALL
148 Agent_OnAttach(JavaVM* vm, char* options, void* reserved);
149 
150 JNIEXPORT void JNICALL
151 Agent_OnUnload(JavaVM *vm);
152 
153     /* Forward declaration of the environment */
154 
155 struct _jvmtiEnv;
156 
157 struct jvmtiInterface_1_;
158 
159 #ifdef __cplusplus
160 typedef _jvmtiEnv jvmtiEnv;
161 #else
162 typedef const struct jvmtiInterface_1_ *jvmtiEnv;
163 #endif /* __cplusplus */
164 
165 </xsl:text>
166   </xsl:template>
167 
168   <xsl:template name="outro">
169   <xsl:text>
170 
171 #ifdef __cplusplus
172 } /* extern "C" */
173 #endif /* __cplusplus */
174 
175 #endif /* !_JAVA_JVMTI_H_ */
176 </xsl:text>
177 </xsl:template>
178 
179 <xsl:template match="eventsection" mode="enum">
180   <xsl:text>
181     /* Event IDs */
182 
183 typedef enum {
184 </xsl:text>
185      <xsl:for-each select="event">
186        <xsl:sort select="@num" data-type="number"/>
187        <xsl:if test="position()=1">
188          <xsl:text>    JVMTI_MIN_EVENT_TYPE_VAL = </xsl:text>
189          <xsl:value-of select="@num"/>
190          <xsl:text>,
191 </xsl:text>
192        </xsl:if>
193        <xsl:apply-templates select="." mode="enum"/>
194        <xsl:text>,
195 </xsl:text>
196        <xsl:if test="position()=last()">
197          <xsl:text>    JVMTI_MAX_EVENT_TYPE_VAL = </xsl:text>
198          <xsl:value-of select="@num"/>
199        </xsl:if>
200      </xsl:for-each>
201     <xsl:text>
202 } jvmtiEvent;
203 
204 </xsl:text>
205 </xsl:template>
206 
207 <xsl:template match="eventsection" mode="body">
208   <xsl:text>
209 
210     /* Event Definitions */
211 
212 typedef void (JNICALL *jvmtiEventReserved)(void);
213 
214 </xsl:text>
215   <xsl:apply-templates select="event" mode="definition">
216     <xsl:sort select="@id"/>
217   </xsl:apply-templates>
218 
219   <xsl:text>
220     /* Event Callback Structure */
221 
222 typedef struct {
223 </xsl:text>
224   <xsl:call-template name="eventStruct">
225     <xsl:with-param name="events" select="event"/>
226     <xsl:with-param name="index" select="0"/>
227     <xsl:with-param name="started" select="false"/>
228     <xsl:with-param name="comment" select="'Yes'"/>
229   </xsl:call-template>
230   <xsl:text>} jvmtiEventCallbacks;
231 </xsl:text>
232 
233 </xsl:template>
234 
235 
236 <xsl:template match="event" mode="definition">
237   <xsl:text>
238 typedef void (JNICALL *jvmtiEvent</xsl:text>
239   <xsl:value-of select="@id"/>
240   <xsl:text>)
241     (jvmtiEnv *jvmti_env</xsl:text>
242   <xsl:apply-templates select="parameters" mode="signature">
243     <xsl:with-param name="comma">
244       <xsl:text>,
245      </xsl:text>
246     </xsl:with-param>
247    </xsl:apply-templates>
248  <xsl:text>);
249 </xsl:text>
250 </xsl:template>
251 
252 <xsl:template match="functionsection">
253    <xsl:text>
254 
255     /* Function Interface */
256 
257 typedef struct jvmtiInterface_1_ {
258 
259 </xsl:text>
260   <xsl:call-template name="funcStruct">
261     <xsl:with-param name="funcs" select="category/function[count(@hide)=0]"/>
262     <xsl:with-param name="index" select="1"/>
263   </xsl:call-template>
264 
265   <xsl:text>} jvmtiInterface_1;
266 
267 struct _jvmtiEnv {
268     const struct jvmtiInterface_1_ *functions;
269 #ifdef __cplusplus
270 
271 </xsl:text>
272   <xsl:apply-templates select="category" mode="cppinline"/>
273   <xsl:text>
274 #endif /* __cplusplus */
275 };
276 </xsl:text>
277 
278 </xsl:template>
279 
280 <xsl:template name="funcStruct">
281   <xsl:param name="funcs"/>
282   <xsl:param name="index"/>
283   <xsl:variable name="thisFunction" select="$funcs[@num=$index]"/>
284   <xsl:text>  /* </xsl:text>
285   <xsl:number value="$index" format="  1"/>
286   <xsl:text> : </xsl:text>
287   <xsl:choose>
288     <xsl:when test="count($thisFunction)=1">
289       <xsl:value-of select="$thisFunction/synopsis"/>
290       <xsl:text> */
291   jvmtiError (JNICALL *</xsl:text>
292       <xsl:value-of select="$thisFunction/@id"/>
293       <xsl:text>) (jvmtiEnv* env</xsl:text>
294       <xsl:apply-templates select="$thisFunction/parameters" mode="signature">
295         <xsl:with-param name="comma">
296           <xsl:text>,
297     </xsl:text>
298         </xsl:with-param>
299       </xsl:apply-templates>
300       <xsl:text>)</xsl:text>
301     </xsl:when>
302     <xsl:otherwise>
303       <xsl:text> RESERVED */
304   void *reserved</xsl:text>
305       <xsl:value-of select="$index"/>
306     </xsl:otherwise>
307   </xsl:choose>
308   <xsl:text>;
309 
310 </xsl:text>
311   <xsl:if test="count($funcs[@num &gt; $index]) &gt; 0">
312     <xsl:call-template name="funcStruct">
313       <xsl:with-param name="funcs" select="$funcs"/>
314       <xsl:with-param name="index" select="1+$index"/>
315     </xsl:call-template>
316   </xsl:if>
317 </xsl:template>
318 
319 
320 <xsl:template match="function">
321   <xsl:text>  jvmtiError (JNICALL *</xsl:text>
322   <xsl:value-of select="@id"/>
323   <xsl:text>) (jvmtiEnv* env</xsl:text>
324   <xsl:apply-templates select="parameters" mode="signature"/>
325   <xsl:text>);
326 
327 </xsl:text>
328 </xsl:template>
329 
330 <xsl:template match="category" mode="cppinline">
331     <xsl:apply-templates select="function[count(@hide)=0]" mode="cppinline"/>
332 </xsl:template>
333 
334 <xsl:template match="function" mode="cppinline">
335   <xsl:text>
336   jvmtiError </xsl:text>
337   <xsl:value-of select="@id"/>
338   <xsl:text>(</xsl:text>
339   <xsl:apply-templates select="parameters" mode="signaturenoleadcomma"/>
340   <xsl:text>) {
341     return functions-></xsl:text>
342   <xsl:value-of select="@id"/>
343   <xsl:text>(this</xsl:text>
344   <xsl:for-each select="parameters">
345     <xsl:for-each select="param">
346       <xsl:if test="@id != '...' and count(jclass/@method) = 0">
347         <xsl:text>, </xsl:text>
348         <xsl:value-of select="@id"/>
349       </xsl:if>
350     </xsl:for-each>
351   </xsl:for-each>
352   <xsl:text>);
353   }
354 </xsl:text>
355 </xsl:template>
356 
357 
358   <xsl:template match="basetype">
359     <xsl:if test="count(definition)!=0">
360       <xsl:text>
361 </xsl:text>
362       <xsl:apply-templates select="definition"/>
363     </xsl:if>
364   </xsl:template>
365 
366   <xsl:template match="constants">
367     <xsl:text>
368 
369     /* </xsl:text>
370     <xsl:value-of select="@label"/>
371     <xsl:text> */
372 </xsl:text>
373     <xsl:choose>
374       <xsl:when test="@kind='enum'">
375         <xsl:apply-templates select="." mode="enum"/>
376       </xsl:when>
377       <xsl:otherwise>
378         <xsl:apply-templates select="." mode="constants"/>
379       </xsl:otherwise>
380     </xsl:choose>
381   </xsl:template>
382 
383 <xsl:template match="callback">
384       <xsl:text>
385 typedef </xsl:text>
386       <xsl:apply-templates select="child::*[position()=1]" mode="signature"/>
387       <xsl:text> (JNICALL *</xsl:text>
388       <xsl:value-of select="@id"/>
389       <xsl:text>)
390     (</xsl:text>
391       <xsl:for-each select="parameters">
392         <xsl:apply-templates select="param[position()=1]" mode="signature"/>
393         <xsl:for-each select="param[position()>1]">
394           <xsl:text>, </xsl:text>
395           <xsl:apply-templates select="." mode="signature"/>
396         </xsl:for-each>
397       </xsl:for-each>
398       <xsl:text>);
399 </xsl:text>
400 </xsl:template>
401 
402 <xsl:template match="capabilitiestypedef">
403   <xsl:text>
404 </xsl:text>
405   <xsl:apply-templates select="." mode="genstruct"/>
406   <xsl:text>
407 </xsl:text>
408 </xsl:template>
409 
410 <xsl:template match="typedef" mode="early">
411   <xsl:text>struct </xsl:text>
412   <xsl:value-of select="@id"/>
413   <xsl:text>;
414 </xsl:text>
415   <xsl:text>typedef struct </xsl:text>
416   <xsl:value-of select="@id"/>
417   <xsl:text> </xsl:text>
418   <xsl:value-of select="@id"/>
419   <xsl:text>;
420 </xsl:text>
421 </xsl:template>
422 
423 <xsl:template match="typedef" mode="body">
424   <xsl:text>struct </xsl:text>
425   <xsl:value-of select="@id"/>
426   <xsl:text> {
427 </xsl:text>
428 <xsl:apply-templates select="field" mode="signature"/>
429   <xsl:text>};
430 </xsl:text>
431 </xsl:template>
432 
433 <xsl:template match="uniontypedef" mode="early">
434   <xsl:text>union </xsl:text>
435   <xsl:value-of select="@id"/>
436   <xsl:text>;
437 </xsl:text>
438   <xsl:text>typedef union </xsl:text>
439   <xsl:value-of select="@id"/>
440   <xsl:text> </xsl:text>
441   <xsl:value-of select="@id"/>
442   <xsl:text>;
443 </xsl:text>
444 </xsl:template>
445 
446 <xsl:template match="uniontypedef" mode="body">
447   <xsl:text>union </xsl:text>
448   <xsl:value-of select="@id"/>
449   <xsl:text> {
450 </xsl:text>
451 <xsl:apply-templates select="field" mode="signature"/>
452   <xsl:text>};
453 </xsl:text>
454 </xsl:template>
455 
456 </xsl:stylesheet>