CACAO
oprofile-agent.cpp
Go to the documentation of this file.
1 /* src/vm/jit/oprofile-agent.cpp - oprofile agent implementation
2 
3  Copyright (C) 2008-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
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.
12 
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.
17 
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
21  02110-1301, USA.
22 
23 */
24 
25 #include "config.h"
26 
27 #include "mm/memory.hpp"
28 
29 #include "vm/jit/code.hpp"
31 
32 #include "toolbox/buffer.hpp"
33 
34 #include <string.h>
35 
36 /* static fields **************************************************************/
37 op_agent_t OprofileAgent::_handle = 0;
38 
39 /**
40  * Initializes the OprofileAgent system.
41  *
42  */
43 /* void OprofileAgent_initialize() */
45 {
46  _handle = op_open_agent();
47  if (!_handle)
48  os::abort_errno("unable to open opagent handle");
49 }
50 
51 /**
52  * Reports the given method to oprofile.
53  *
54  * This has to be done once per JIT compilation step for a specific method.
55  *
56  * @param m Method to register.
57  */
58 /* void OprofileAgent_newmethod(methodinfo *m) */
60 {
61  unsigned int real_length = (unsigned int) m->code->mcodelength -
62  (unsigned int) (m->code->entrypoint - m->code->mcode);
63 
64  size_t len = Utf8String(m->clazz->name) + strlen(".")
66  + strlen("0");
67 
68  // can the buffer free it's contents or not?
69  Buffer<> buf(len, false);
70 
72  .write('.')
73  .write(m->name)
74  .write(m->descriptor)
75 
76  if (_handle)
77  op_write_native_code(_handle, (char*) buf,
78  (uint64_t) (ptrint) m->code->entrypoint,
79  (const void *) m->code->entrypoint,
80  real_length);
81 }
82 
83 /**
84  * Shuts down the OprofileAgent system.
85  *
86  */
87 /* void OprofileAgent_close() */
89 {
90  if (_handle)
91  op_close_agent(_handle);
92 
93  _handle = 0;
94 }
95 
96 /*
97  * These are local overrides for various environment variables in Emacs.
98  * Please do not remove this and leave it at the end of the file, where
99  * Emacs will automagically detect them.
100  * ---------------------------------------------------------------------
101  * Local variables:
102  * mode: c++
103  * indent-tabs-mode: t
104  * c-basic-offset: 4
105  * tab-width: 4
106  * End:
107  */
Utf8String name
Definition: method.hpp:71
static void newmethod(methodinfo *)
Reports the given method to oprofile.
static void initialize()
Initializes the OprofileAgent system.
static void abort_errno(const char *text,...)
Equal to abort_errnum, but uses errno to get the error number.
Definition: os.cpp:165
s4 mcodelength
Definition: code.hpp:85
Buffer & write_slash_to_dot(const char *)
write to buffer, replacing &#39;/&#39; by &#39;.&#39;
Definition: buffer.hpp:297
u1 * mcode
Definition: code.hpp:83
Utf8String descriptor
Definition: method.hpp:72
static void close()
Shuts down the OprofileAgent system.
classinfo * clazz
Definition: method.hpp:80
Utf8String name
Definition: class.hpp:91
codeinfo * code
Definition: method.hpp:103
static op_agent_t _handle
Buffer & write(char)
Definition: buffer.hpp:280
uintptr_t ptrint
Definition: types.hpp:54
u1 * entrypoint
Definition: code.hpp:84