Table of Contents
Table of Contents
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.
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:
<oprofile_install_dir>/lib/oprofile
).
The JIT support API for OProfile is defined
in <oprofile-install-dir>/include/opagent.h
.
Some parts of the API are mandatory for an agent library to use; other
parts are optional. The mandatory functions are shown below.
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); |
To implement this part of your library, you must perform the following steps:
op_op_agent()
and cache the returned op_agent_t
handle for use in
future calls.op_write_native_code()
.op_agent_close()
.
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.
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); |
Table of Contents
This chapter describes the JIT support API. See opagent.h for more details.
#include <opagent.h>
op_agent_t op_open_agent( | ) ; |
void
;/var/lib/oprofile/jitdump
using the naming convention <process_id>.dump
.
Returns a valid op_agent_t
handle or NULL.
If NULL is returned, errno
is set to indicate the nature of the error. For a list
of possible errno
values, see the man pages for:
stat, creat, gettimeofday, fdopen, fwrite
#include <opagent.h>
int op_close_agent( | hdl) ; |
op_agent_t hdl
;hdl :
Handle returned from an earlier call to
op_open_agent()
Returns 0 on success; -1 otherwise. If -1 is returned, errno
is set
to indicate the nature of the error.
errno
is set to EINVAL if an invalid op_agent_t
handle is passed. For a list of other possible errno
values, see the man pages for:
gettimeofday, fwrite
#include <opagent.h>
int op_write_native_code( | hdl, | |
symbol_name, | ||
vma, | ||
code, | ||
code_size) ; |
op_agent_thdl
;char const *symbol_name
;uint64_tvma
;void const *code
;const unsigned intcode_size
;
hdl :
Handle returned from an earlier call to
op_open_agent()
symbol_name :
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.
vma :
Virtual memory address of the executable code
code :
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.
code_size :
Size of the compiled code
Returns 0 on success; -1 otherwise. If -1 is returned, errno
is set
to indicate the nature of the error.
errno
is set to EINVAL if an invalid op_agent_t
handle is passed. For a list of other possible errno
values, see the man pages for:
gettimeofday, fwrite
#include <opagent.h>
int op_write_debug_line_info( | hdl, | |
code, | ||
nr_entry, | ||
compile_map) ; |
op_agent_thdl
;void const *code
;size_tnr_entry
;struct debug_line_info const *compile_map
;op_write_native_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.
hdl :
Handle returned from an earlier call to
op_open_agent()
code :
Pointer to the location of the code with debug info
nr_entry :
Number of entries in compile_map
compile_map :
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.
Returns 0 on success; -1 otherwise. If -1 is returned, errno
is set
to indicate the nature of the error.
errno
is set to EINVAL if an invalid op_agent_t
handle is passed. For a list of other possible errno
values, see the man pages for:
gettimeofday, ftell, fwrite
#include <opagent.h>
int op_unload_native_code( | hdl, | |
vma) ; |
op_agent_thdl
;uint64_tvma
;
hdl :
Handle returned from an earlier call to
op_open_agent()
vma :
Virtual memory address of the compiled code being unloaded.
An op_write_native_code()
with the same vma should have occurred before this call.
Returns 0 on success; -1 otherwise. If -1 is returned, errno
is set
to indicate the nature of the error.
errno
is set to EINVAL if an invalid op_agent_t
handle is passed. For a list of other possible errno
values, see the man pages for:
gettimeofday, fwrite