1 /* src/vm/jit/oprofile-agent.cpp - oprofile agent implementation
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "mm/memory.h"
30 #include "vm/jit/code.hpp"
31 #include "vm/jit/oprofile-agent.hpp"
35 /* static fields **************************************************************/
36 op_agent_t OprofileAgent::_handle = 0;
39 * Initializes the OprofileAgent system.
42 /* void OprofileAgent_initialize() */
43 void OprofileAgent::initialize(void)
45 _handle = op_open_agent();
47 vm_abort_errno("unable to open opagent handle:");
51 * Reports the given method to oprofile.
53 * This has to be done once per JIT compilation step for a specific method.
55 * @param m Method to register.
57 /* void OprofileAgent_newmethod(methodinfo *m) */
58 void OprofileAgent::newmethod(methodinfo *m)
60 unsigned int real_length = (unsigned int) m->code->mcodelength -
61 (unsigned int) (m->code->entrypoint - m->code->mcode);
66 len = utf_bytes(m->clazz->name) + strlen(".") +
67 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
69 buf = MNEW(char, len);
71 utf_copy_classname(buf, m->clazz->name);
73 utf_cat(buf, m->name);
74 utf_cat(buf, m->descriptor);
77 op_write_native_code(_handle, buf,
78 (uint64_t) (ptrint) m->code->entrypoint,
79 (const void *) m->code->entrypoint,
82 MFREE(buf, char, len);
86 * Shuts down the OprofileAgent system.
89 /* void OprofileAgent_close() */
90 void OprofileAgent::close()
93 op_close_agent(_handle);
97 /* Legacy C interface *********************************************************/
101 void OprofileAgent_initialize() { OprofileAgent::initialize(); }
102 void OprofileAgent_newmethod(methodinfo *m) { OprofileAgent::newmethod(m); }
103 void OprofileAgent_close() { OprofileAgent::close(); }
108 * These are local overrides for various environment variables in Emacs.
109 * Please do not remove this and leave it at the end of the file, where
110 * Emacs will automagically detect them.
111 * ---------------------------------------------------------------------
114 * indent-tabs-mode: t