/usr/share/doc/oprofile/op-jit-devel.html is in oprofile 1.1.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>OProfile JIT agent developer guide</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
</head>
<body>
<div class="book">
<div class="titlepage">
<div>
<div>
<h1 class="title"><a id="oprofile-devel-guide"></a>OProfile JIT agent developer guide</h1>
</div>
<div>
<div class="authorgroup">
<div class="author">
<h3 class="author"><span class="firstname">Maynard</span> <span class="surname">Johnson</span></h3>
<div class="affiliation">
<div class="address">
<p>
<code class="email"><<a class="email" href="mailto:maynardj@us.ibm.com">maynardj@us.ibm.com</a>></code>
</p>
</div>
</div>
</div>
</div>
</div>
<div>
<p class="copyright">Copyright © 2007 IBM Corporation</p>
</div>
</div>
<hr />
</div>
<div class="toc">
<p>
<strong>Table of Contents</strong>
</p>
<dl class="toc">
<dt>
<span class="chapter">
<a href="#developing">1. Developing a new JIT agent</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect1">
<a href="#jit-devel-overview">1. Overview</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#jit-interface">2. Implementing JIT support for a new virtual machine</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="chapter">
<a href="#jit-api">2. The JIT support API</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="sect1">
<a href="#op_open_agent">1. op_open_agent</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_close_agent">2. op_close_agent</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_write_native_code">3. op_write_native_code</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_write_debug_line_info">4. op_write_debug_line_info</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_unload_native_code">5. op_unload_native_code</a>
</span>
</dt>
</dl>
</dd>
</dl>
</div>
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title"><a id="developing"></a>Chapter 1. Developing a new JIT agent</h1>
</div>
</div>
</div>
<div class="toc">
<p>
<strong>Table of Contents</strong>
</p>
<dl class="toc">
<dt>
<span class="sect1">
<a href="#jit-devel-overview">1. Overview</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#jit-interface">2. Implementing JIT support for a new virtual machine</a>
</span>
</dt>
</dl>
</div>
<p>
OProfile includes a header file and library that are intended to be used by
developers who wish to extend OProfile's JIT support to other non-supported
virtual machines. This developer guide describes these development files and how
to use them.
</p>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="jit-devel-overview"></a>1. Overview</h2>
</div>
</div>
</div>
<p>
OProfile already includes some implementations that use the JIT support,
e.g., the Java Virtual Machine Toolkit Interface (JVMTI) library,
libjvmti_oprofile.so. In developing a new implementation, you will
likely follow a similar (if not identical) procedure as was used in
developing the JVMTI library. Following are the high level steps to follow:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">Ensure your virtual machine provides an API that, at minimum,
can provide the following information about dynamically compiled code:
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Notification when compilation occurs</li><li class="listitem">Name of the symbol (i.e., function or class/method, etc.)</li><li class="listitem">Address in anonymous memory where the compiled code was loaded</li><li class="listitem">Length of the compiled code segment</li></ul></div></li>
<li class="listitem">Write an agent library that communicates with your VM to obtain
compiled code notifications. Invoke the required functions from opagent.h
(<a class="xref" href="#jit-interface" title="2. Implementing JIT support for a new virtual machine">Section 2, “Implementing JIT support for a new virtual machine”</a>) and link your library with libopagent.so
(installed at <code class="filename"><oprofile_install_dir>/lib/oprofile</code>).
</li>
</ol>
</div>
<p>
</p>
</div>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="jit-interface"></a>2. Implementing JIT support for a new virtual machine</h2>
</div>
</div>
</div>
<p>
The JIT support API for OProfile is defined
in <code class="filename"><oprofile-install-dir>/include/opagent.h</code>.
Some parts of the API are mandatory for an agent library to use; other
parts are optional. The mandatory functions are shown below.
</p>
<table xmlns="" border="0" style="background: #E0E0E0;" width="90%">
<tr>
<td>
<pre class="screen">
op_agent_t op_open_agent(void);
void op_close_agent(op_agent_t hdl);
int op_write_native_code(op_agent_t hdl, char const * symbol_name,
uint64_t vma, const void * code,
const unsigned int code_size);
</pre>
</td>
</tr>
</table>
<p>
To implement this part of your library, you must perform the
following steps:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">Implement a function to set up initial communication with the VM.
Once communication to the VM is established, your agent library should call
<code class="function">op_op_agent()</code> and cache the returned <code class="code">op_agent_t</code> handle for use in
future calls.</li>
<li class="listitem">Perform any necessary steps to register with the VM to be notified of
compiled code load events. Registration must include a callback function you
will implement in the library to handle the compiled code load events.</li>
<li class="listitem">The callback function mentioned above must obtain all required
information from the VM to pass to libopagent via <code class="function">op_write_native_code()</code>.</li>
<li class="listitem">When disconnecting from the VM, your library should call
<code class="function">op_agent_close()</code>.</li>
</ol>
</div>
<p>
</p>
<p>Use of the functions below are optional, depending on the kinds of information your VM
can provide to your agent library. See the JVMTI agent library for an example of how to use
these functions.
</p>
<table xmlns="" border="0" style="background: #E0E0E0;" width="90%">
<tr>
<td>
<pre class="screen">
int op_unload_native_code(op_agent_t hdl, uint64_t vma);
int op_write_debug_line_info(op_agent_t hdl, void const * code,
size_t nr_entry,
struct debug_line_info const * compile_map);
</pre>
</td>
</tr>
</table>
<p>
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>While the libopagent functions are thread-safe, you should not use them in
signal handlers.
</div>
</div>
</div>
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title"><a id="jit-api"></a>Chapter 2. The JIT support API</h1>
</div>
</div>
</div>
<div class="toc">
<p>
<strong>Table of Contents</strong>
</p>
<dl class="toc">
<dt>
<span class="sect1">
<a href="#op_open_agent">1. op_open_agent</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_close_agent">2. op_close_agent</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_write_native_code">3. op_write_native_code</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_write_debug_line_info">4. op_write_debug_line_info</a>
</span>
</dt>
<dt>
<span class="sect1">
<a href="#op_unload_native_code">5. op_unload_native_code</a>
</span>
</dt>
</dl>
</div>
<p>
This chapter describes the JIT support API. See opagent.h for more details.
</p>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="op_open_agent"></a>1. op_open_agent</h2>
</div>
</div>
</div>
<div class="funcsynopsis">Initializes the agent library.
<pre class="funcsynopsisinfo">#include <opagent.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">op_agent_t <strong class="fsfunc">op_open_agent</strong>(</code></td><td><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>void</code>;</div><div class="funcprototype-spacer"> </div></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Description</h3>
This function must be called by agents before any other function.
Creates and opens a JIT dump file in <code class="filename">/var/lib/oprofile/jitdump</code>
using the naming convention <code class="filename"><process_id>.dump</code>.
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Parameters</h3>
None
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Return value</h3>
<p>Returns a valid <code class="code">op_agent_t</code> handle or NULL.
If NULL is returned, <code class="code">errno</code> is set to indicate the nature of the error. For a list
of possible <code class="code">errno</code> values, see the man pages for:</p>
<code class="code">
stat, creat, gettimeofday, fdopen, fwrite
</code>
</div>
</div>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="op_close_agent"></a>2. op_close_agent</h2>
</div>
</div>
</div>
<div class="funcsynopsis">Uninitialize the agent library.
<pre class="funcsynopsisinfo">#include <opagent.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <strong class="fsfunc">op_close_agent</strong>(</code></td><td><var class="pdparam">hdl</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>op_agent_t <var class="pdparam">hdl</var></code>;</div><div class="funcprototype-spacer"> </div></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Description</h3>
Frees all resources and closes open file handles.
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Parameters</h3><em class="parameter"><code>hdl : </code></em>Handle returned from an earlier call to
<code class="function">op_open_agent()</code></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Return value</h3>
<p>Returns 0 on success; -1 otherwise. If -1 is returned, <code class="code">errno</code> is set
to indicate the nature of the error.
<code class="code">errno</code> is set to EINVAL if an invalid <code class="code">op_agent_t</code>
handle is passed. For a list of other possible <code class="code">errno</code> values, see the man pages for:</p>
<code class="code">gettimeofday, fwrite</code>
</div>
</div>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="op_write_native_code"></a>3. op_write_native_code</h2>
</div>
</div>
</div>
<div class="funcsynopsis">Write information about compiled code to a JIT dump file.
<pre class="funcsynopsisinfo">#include <opagent.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <strong class="fsfunc">op_write_native_code</strong>(</code></td><td><var class="pdparam">hdl</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">symbol_name</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">vma</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">code</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">code_size</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>op_agent_t<var class="pdparam">hdl</var></code>;<br /><code>char const *<var class="pdparam">symbol_name</var></code>;<br /><code>uint64_t<var class="pdparam">vma</var></code>;<br /><code>void const *<var class="pdparam">code</var></code>;<br /><code>const unsigned int<var class="pdparam">code_size</var></code>;</div><div class="funcprototype-spacer"> </div></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Description</h3>
Signal the dynamic generation of native code from a virtual machine.
Writes a JIT dump record to the open JIT dump file using the passed information.
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Parameters</h3>
<p>
<em class="parameter"><code>hdl : </code></em>Handle returned from an earlier call to
<code class="function">op_open_agent()</code>
</p>
<p>
<em class="parameter"><code>symbol_name : </code></em>The name of the symbol being dynamically compiled.
This name can (and should) contain all necessary information to disambiguate it from
symbols of the same name; e.g., class, method signature.
</p>
<p>
<em class="parameter"><code>vma : </code></em>Virtual memory address of the executable code
</p>
<p>
<em class="parameter"><code>code : </code></em>Pointer to the location of the compiled code.
Theoretically, this may be a different location from
that given by the vma argument. For some JIT compilers,
obtaining the code may be impractical. For this (or any other)
reason, the agent can choose to pass NULL for this paraemter.
If NULL is passed, no code will be copied into the JIT dump
file.
</p>
<p>
<em class="parameter"><code>code_size : </code></em>Size of the compiled code
</p>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Return value</h3>
<p>Returns 0 on success; -1 otherwise. If -1 is returned, <code class="code">errno</code> is set
to indicate the nature of the error.
<code class="code">errno</code> is set to EINVAL if an invalid <code class="code">op_agent_t</code>
handle is passed. For a list of other possible <code class="code">errno</code> values, see the man pages for:</p>
<code class="code">gettimeofday, fwrite</code>
</div>
</div>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="op_write_debug_line_info"></a>4. op_write_debug_line_info</h2>
</div>
</div>
</div>
<div class="funcsynopsis">Write debug information about compiled code to a JIT dump file.
<pre class="funcsynopsisinfo">#include <opagent.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <strong class="fsfunc">op_write_debug_line_info</strong>(</code></td><td><var class="pdparam">hdl</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">code</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">nr_entry</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">compile_map</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>op_agent_t<var class="pdparam">hdl</var></code>;<br /><code>void const *<var class="pdparam">code</var></code>;<br /><code>size_t<var class="pdparam">nr_entry</var></code>;<br /><code>struct debug_line_info const *<var class="pdparam">compile_map</var></code>;</div><div class="funcprototype-spacer"> </div></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Description</h3>
Add debug line information to a piece of code. An <code class="function">op_write_native_code()</code>
with the same code pointer should have occurred before this call. It's not
necessary to provide one lineno information entry per machine instruction;
the array can contain hole.
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Parameters</h3>
<p>
<em class="parameter"><code>hdl : </code></em>Handle returned from an earlier call to
<code class="function">op_open_agent()</code>
</p>
<p>
<em class="parameter"><code>code : </code></em>Pointer to the location of the code with debug info
</p>
<p>
<em class="parameter"><code>nr_entry : </code></em>Number of entries in compile_map
</p>
<p>
<em class="parameter"><code>compile_map : </code></em>Array of struct debug_line_info. See the JVMTI agent
library implementation for an example of what information should be retrieved
from a VM to fill out this data structure.
</p>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Return value</h3>
<p>Returns 0 on success; -1 otherwise. If -1 is returned, <code class="code">errno</code> is set
to indicate the nature of the error.
<code class="code">errno</code> is set to EINVAL if an invalid <code class="code">op_agent_t</code>
handle is passed. For a list of other possible <code class="code">errno</code> values, see the man pages for:</p>
<code class="code">gettimeofday, ftell, fwrite</code>
</div>
</div>
<div class="sect1">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="op_unload_native_code"></a>5. op_unload_native_code</h2>
</div>
</div>
</div>
<div class="funcsynopsis">Write information to the JIT dump file about invalidated compiled code.
<pre class="funcsynopsisinfo">#include <opagent.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <strong class="fsfunc">op_unload_native_code</strong>(</code></td><td><var class="pdparam">hdl</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">vma</var><code>)</code>;</td><td> </td></tr></table><div class="paramdef-list"><code>op_agent_t<var class="pdparam">hdl</var></code>;<br /><code>uint64_t<var class="pdparam">vma</var></code>;</div><div class="funcprototype-spacer"> </div></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Description</h3>
Signal the invalidation of native code from a virtual machine.</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Parameters</h3>
<p>
<em class="parameter"><code>hdl : </code></em>Handle returned from an earlier call to
<code class="function">op_open_agent()</code>
</p>
<p>
<em class="parameter"><code>vma : </code></em>Virtual memory address of the compiled code being unloaded.
An <code class="function">op_write_native_code()</code> with the same vma should have occurred before this call.
</p>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Return value</h3>
<p>Returns 0 on success; -1 otherwise. If -1 is returned, <code class="code">errno</code> is set
to indicate the nature of the error.
<code class="code">errno</code> is set to EINVAL if an invalid <code class="code">op_agent_t</code>
handle is passed. For a list of other possible <code class="code">errno</code> values, see the man pages for:</p>
<code class="code">gettimeofday, fwrite</code>
</div>
</div>
</div>
</div>
</body>
</html>
|