2. Implementing JIT support for a new virtual machine

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:

  1. Implement a function to set up initial communication with the VM. Once communication to the VM is established, your agent library should call op_op_agent() and cache the returned op_agent_t handle for use in future calls.
  2. 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.
  3. The callback function mentioned above must obtain all required information from the VM to pass to libopagent via op_write_native_code().
  4. When disconnecting from the VM, your library should call 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);


While the libopagent functions are thread-safe, you should not use them in signal handlers.