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
27 #include "mm/memory.hpp"
29 #include "vm/jit/code.hpp"
30 #include "vm/jit/oprofile-agent.hpp"
34 /* static fields **************************************************************/
35 op_agent_t OprofileAgent::_handle = 0;
38 * Initializes the OprofileAgent system.
41 /* void OprofileAgent_initialize() */
42 void OprofileAgent::initialize(void)
44 _handle = op_open_agent();
46 os::abort_errno("unable to open opagent handle");
50 * Reports the given method to oprofile.
52 * This has to be done once per JIT compilation step for a specific method.
54 * @param m Method to register.
56 /* void OprofileAgent_newmethod(methodinfo *m) */
57 void OprofileAgent::newmethod(methodinfo *m)
59 unsigned int real_length = (unsigned int) m->code->mcodelength -
60 (unsigned int) (m->code->entrypoint - m->code->mcode);
65 len = utf_bytes(m->clazz->name) + strlen(".") +
66 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
68 buf = MNEW(char, len);
70 utf_copy_classname(buf, m->clazz->name);
72 utf_cat(buf, m->name);
73 utf_cat(buf, m->descriptor);
76 op_write_native_code(_handle, buf,
77 (uint64_t) (ptrint) m->code->entrypoint,
78 (const void *) m->code->entrypoint,
81 MFREE(buf, char, len);
85 * Shuts down the OprofileAgent system.
88 /* void OprofileAgent_close() */
89 void OprofileAgent::close()
92 op_close_agent(_handle);
98 * These are local overrides for various environment variables in Emacs.
99 * Please do not remove this and leave it at the end of the file, where
100 * Emacs will automagically detect them.
101 * ---------------------------------------------------------------------
104 * indent-tabs-mode: t