18cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
28cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * @file opagent.h
38cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Interface to report symbol names and dynamically generated code to Oprofile
48cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
58cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * @remark Copyright 2007 OProfile authors
68cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
78cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * This library is free software; you can redistribute it and/or
88cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * modify it under the terms of the GNU Lesser General Public
98cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * License as published by the Free Software Foundation; either
108cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * version 2.1 of the License, or (at your option) any later version.
118cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
128cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * This library is distributed in the hope that it will be useful,
138cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * but WITHOUT ANY WARRANTY; without even the implied warranty of
148cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
158cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Lesser General Public License for more details.
168cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
178cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * You should have received a copy of the GNU Lesser General Public
188cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * License along with this library; if not, write to the Free Software
198cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
208cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
218cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * @author Jens Wilke
228cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * @Modifications Daniel Hansel
238cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
248cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Copyright IBM Corporation 2007
258cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
268cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd */
278cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
288cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#ifndef _LIB_OPAGENT_H
298cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#define _LIB_OPAGENT_H
308cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
318cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#include <sys/types.h>
328cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
338cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#if defined(__cplusplus)
348cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddextern "C" {
358cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#endif
368cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
378cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddstruct debug_line_info {
388cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd	unsigned long vma;
398cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd	unsigned int lineno;
408cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd	/* The filename format is unspecified, absolute path, relative etc. */
418cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd	char const * filename;
428cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd};
438cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
448cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddtypedef void * op_agent_t;
458cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
468cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
478cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * This function must be called by agents before any other function.
488cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Creates and opens a JIT dump file in /var/lib/oprofile/jitdump
498cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * using the naming convention <process_id>.dump.
508cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
518cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns a valid op_agent_t handle or NULL.  If NULL is returned, errno
528cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * is set to indicate the nature of the error.
538cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
548cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddop_agent_t op_open_agent(void);
558cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
568cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
578cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Frees all resources and closes open file handles.
588cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
598cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * hdl:         Handle returned from an earlier call to op_open_agent()
608cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
618cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns 0 on success; -1 otherwise.  If -1 is returned, errno is
628cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * set to indicate the nature of the error.
638cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
648cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_close_agent(op_agent_t hdl);
658cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
668cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
678cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Signal the dynamic generation of native code from a virtual machine.
688cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Writes a JIT dump record to the open JIT dump file using
698cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * the passed information.
708cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
718cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * hdl:         Handle returned from an earlier call to op_open_agent()
728cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * symbol_name: The name of the symbol being dynamically compiled.
738cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              This name can (and should) contain all necessary
748cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              information to disambiguate it from symbols of the
758cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              same name; e.g., class, method signature.
768cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * vma:         The virtual memory address of the executable code.
778cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * code:        Pointer to the location of the compiled code.
788cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *		Theoretically, this may be a different location from
798cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *		that given by the vma argument.  For some JIT compilers,
808cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *		obtaining the code may be impractical.  For this (or any other)
818cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *		reason, the agent can choose to pass NULL for this paraemter.
828cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *		If NULL is passed, no code will be copied into the JIT dump
838cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *		file.
848cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * code_size:   Size of the compiled code.
858cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
868cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns 0 on success; -1 otherwise.  If -1 is returned, errno is
878cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * set to indicate the nature of the error.
888cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
898cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_write_native_code(op_agent_t hdl, char const * symbol_name,
908cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd			 uint64_t vma, void const * code,
918cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd			 const unsigned int code_size);
928cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
938cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
948cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Add debug line information to a piece of code. An op_write_native_code()
958cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * with the same code pointer should have occurred before this call. It's not
968cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * necessary to provide one lineno information entry per machine instruction;
978cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * the array can contain hole.
988cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
998cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * hdl:         Handle returned from an earlier call to op_open_agent()
1008cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * code:        Pointer to the location of the code with debug info
1018cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * nr_entry:    Number of entries in compile_map
1028cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * compile_map: Array of struct debug_line_info.  See the JVMTI agent
1038cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              library implementation for an example of what information
1048cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              should be retrieved from a VM to fill out this data structure.
1058cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
1068cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns 0 on success; -1 otherwise.  If -1 is returned, errno is
1078cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * set to indicate the nature of the error.
1088cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
1098cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_write_debug_line_info(op_agent_t hdl, void const * code,
1108cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd			     size_t nr_entry,
1118cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd			     struct debug_line_info const * compile_map);
1128cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
1138cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
1148cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Signal the invalidation of native code from a virtual machine.
1158cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
1168cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * hdl:         Handle returned from an earlier call to op_open_agent()
1178cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * vma:         The virtual memory address of the compiled code being unloaded.
1188cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              An op_write_native_code() with the same vma should have
1198cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *              occurred before this call.
1208cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd *
1218cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns 0 on success; -1 otherwise.  If -1 is returned, errno is
1228cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * set to indicate the nature of the error.
1238cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
1248cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_unload_native_code(op_agent_t hdl, uint64_t vma);
1258cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
1268cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
1278cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns the major version number of the libopagent library that will be used.
1288cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
1298cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_major_version(void);
1308cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
1318cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/**
1328cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd * Returns the minor version number of the libopagent library that will be used.
1338cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd **/
1348cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_minor_version(void);
1358cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
1368cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd/* idea how to post additional information for a piece of code.
1378cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd   we use the code address as reference
1388cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Doddint op_write_loader_name(const void* code_addr, char const * loader_name);
1398cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd*/
1408cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
1418cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#if defined(__cplusplus)
1428cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd}
1438cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#endif
1448cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd
1458cfa702f803c5ef6a2b062a489a1b2cf66b45b5eMike Dodd#endif
146