m4/opagent.m4: New file.
src/vm/jit/Makefile.am: Added new oprofile agent sources.
src/vm/jit.c: Added calls to OprofileAgent methods.
src/vm/oprofile-agent.cpp: New file.
src/vm/oprofile-agent.hpp: New file.
src/vmcore/options.h: Added opt_EnableOpagent variable.
src/vmcore/options.c: Added -XX:+EnableOpagent option handling.
AM_CONDITIONAL([USE_SCHEDULER], [false])
fi
+AC_CHECK_ENABLE_OPAGENT
AC_CHECK_ENABLE_ZLIB
--- /dev/null
+dnl m4/opagent.m4
+dnl
+dnl Copyright (C) 2008
+dnl CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+dnl
+dnl This file is part of CACAO.
+dnl
+dnl This program is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU General Public License as
+dnl published by the Free Software Foundation; either version 2, or (at
+dnl your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+
+dnl check if opagent library should be used
+
+AC_DEFUN([AC_CHECK_ENABLE_OPAGENT],[
+AC_ARG_WITH([opagent-includedir],
+ [AS_HELP_STRING(--with-opagent-includedir=<path>,location of opagent header files [[default=/usr/include]])],
+ [OPAGENT_CFLAGS=-I"${withval}"],
+ [])
+AC_SUBST(OPAGENT_CFLAGS)
+
+AC_ARG_WITH([opagent-libdir],
+ [AS_HELP_STRING(--with-opagent-libdir=<path>,location of opagent library [[default=/usr/lib/oprofile]])],
+ [OPAGENT_LDFLAGS=-L"${withval}"],
+ [OPAGENT_LDFLAGS=-L/usr/lib/oprofile])
+AC_SUBST(OPAGENT_LDFLAGS)
+
+AC_MSG_CHECKING(whether Oprofile opagent support code should be compiled)
+AC_ARG_ENABLE([opagent],
+ [AS_HELP_STRING(--enable-opagent,enable opagent library support [[default=disabled]])],
+ [case "${enableval}" in
+ yes) ENABLE_OPAGENT=yes;;
+ *) ENABLE_OPAGENT=no;;
+ esac],
+ [ENABLE_OPAGENT=no])
+AC_MSG_RESULT(${ENABLE_OPAGENT})
+
+if test x"${ENABLE_OPAGENT}" = "xyes"; then
+ CFLAGS="$CFLAGS $OPAGENT_CFLAGS"
+ CPPFLAGS="$CPPFLAGS $OPAGENT_CFLAGS"
+ LDFLAGS="$LDFLAGS $OPAGENT_LDFLAGS"
+ AC_CHECK_HEADERS([opagent.h],, [AC_MSG_ERROR(cannot find opagent.h)])
+ AC_CHECK_LIB(opagent, op_open_agent,, [AC_MSG_ERROR(cannot find libopagent)])
+ AC_DEFINE([ENABLE_OPAGENT], 1, [use opagent])
+fi
+AM_CONDITIONAL([ENABLE_OPAGENT], [test x"${ENABLE_OPAGENT}" = "xyes"])
+])
+
verify/libverify.la
endif
+if ENABLE_OPAGENT
+OPAGENT_SOURCES = \
+ oprofile-agent.cpp \
+ oprofile-agent.hpp
+
+endif
+
if WITH_BINUTILS_DISASSEMBLER
DISASS_SOURCES = disass-common.c
endif
stacktrace.hpp \
trace.cpp \
trace.hpp \
- $(TRAP_SOURCES)
+ $(TRAP_SOURCES) \
+ $(OPAGENT_SOURCES)
libjit_la_SOURCES += \
cfg.c \
#include "vm/jit/show.h"
#include "vm/jit/stack.h"
+#if defined(ENABLE_OPAGENT)
+#include "vm/jit/oprofile-agent.hpp"
+#endif
+
#include "vm/jit/allocator/simplereg.h"
#if defined(ENABLE_LSRA) && !defined(ENABLE_SSA)
# include "vm/jit/allocator/lsra.h"
#else
intrp_md_init();
#endif
+
+#if defined(ENABLE_OPAGENT)
+ if (opt_EnableOpagent)
+ OprofileAgent_initialize();
+#endif
}
void jit_close(void)
{
- /* do nothing */
+#if defined(ENABLE_OPAGENT)
+ if (opt_EnableOpagent)
+ OprofileAgent_close();
+#endif
}
compilingtime_stop();
#endif
+#if defined(ENABLE_OPAGENT)
+ if (opt_EnableOpagent)
+ OprofileAgent_newmethod(m);
+#endif
+
/* leave the monitor */
LOCK_MONITOR_EXIT(m);
compilingtime_stop();
#endif
+#if defined(ENABLE_OPAGENT)
+ if (opt_EnableOpagent)
+ OprofileAgent_newmethod(m);
+#endif
+
DEBUG_JIT_COMPILEVERBOSE("Recompiling done: ");
/* return pointer to the methods entry point */
--- /dev/null
+/* src/vm/jit/oprofile-agent.cpp - oprofile agent implementation
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include "mm/memory.h"
+
+#include "vm/jit/code.h"
+#include "vm/jit/oprofile-agent.hpp"
+
+#include <string.h>
+
+/* static fields **************************************************************/
+op_agent_t OprofileAgent::_handle = 0;
+
+/**
+ * Initializes the OprofileAgent system.
+ *
+ */
+/* void OprofileAgent_initialize() */
+void OprofileAgent::initialize(void)
+{
+ _handle = op_open_agent();
+ if (!_handle)
+ vm_abort_errno("unable to open opagent handle:");
+}
+
+/**
+ * Reports the given method to oprofile.
+ *
+ * This has to be done once per JIT compilation step for a specific method.
+ *
+ * @param m Method to register.
+ */
+/* void OprofileAgent_newmethod(methodinfo *m) */
+void OprofileAgent::newmethod(methodinfo *m)
+{
+ unsigned int real_length = (unsigned int) m->code->mcodelength -
+ (unsigned int) (m->code->entrypoint - m->code->mcode);
+
+ char *buf;
+ s4 len;
+
+ len = utf_bytes(m->clazz->name) + strlen(".") +
+ utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
+
+ buf = MNEW(char, len);
+
+ utf_copy_classname(buf, m->clazz->name);
+ strcat(buf, ".");
+ utf_cat(buf, m->name);
+ utf_cat(buf, m->descriptor);
+
+ if (_handle)
+ op_write_native_code(_handle, buf,
+ (uint64_t) (ptrint) m->code->entrypoint,
+ (const void *) m->code->entrypoint,
+ real_length);
+
+ MFREE(buf, char, len);
+}
+
+/**
+ * Shuts down the OprofileAgent system.
+ *
+ */
+/* void OprofileAgent_close() */
+void OprofileAgent::close()
+{
+ if (_handle)
+ op_close_agent(_handle);
+
+ _handle = 0;
+}
+/* Legacy C interface *********************************************************/
+
+extern "C" {
+
+void OprofileAgent_initialize() { OprofileAgent::initialize(); }
+void OprofileAgent_newmethod(methodinfo *m) { OprofileAgent::newmethod(m); }
+void OprofileAgent_close() { OprofileAgent::close(); }
+
+}
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--- /dev/null
+/* src/vm/jit/oprofile-agent.hpp - oprofile agent implementation
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _OPROFILE_AGENT_HPP
+#define _OPROFILE_AGENT_HPP
+
+#include "config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "vmcore/method.h"
+
+#include <opagent.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef __cplusplus
+
+class OprofileAgent
+{
+ static op_agent_t _handle;
+
+public:
+ static void initialize();
+
+ static void newmethod(methodinfo *);
+
+ static void close();
+};
+
+#else
+
+/* Legacy C interface *********************************************************/
+
+typedef struct OprofileAgent OprofileAgent;
+
+void OprofileAgent_initialize(void);
+void OprofileAgent_newmethod(methodinfo *);
+void OprofileAgent_close();
+
+#endif
+
+#endif /* _OPROFILE_AGENT_HPP */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
bool opt_prof_bb = false;
#endif
+#if defined(ENABLE_OPAGENT)
+bool opt_opagent = false;
+#endif
/* optimization options *******************************************************/
#if defined(ENABLE_DISASSEMBLER)
int opt_DisassembleStubs = 0;
#endif
+#if defined(ENABLE_OPAGENT)
+int opt_EnableOpagent = 0;
+#endif
#if defined(ENABLE_GC_CACAO)
int opt_GCDebugRootSet = 0;
int opt_GCStress = 0;
OPT_DebugStackTrace,
OPT_DebugThreads,
OPT_DisassembleStubs,
+ OPT_EnableOpagent,
OPT_GCDebugRootSet,
OPT_GCStress,
OPT_Inline,
#if defined(ENABLE_DISASSEMBLER)
{ "DisassembleStubs", OPT_DisassembleStubs, OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
#endif
+#if defined(ENABLE_OPAGENT)
+ { "EnableOpagent", OPT_EnableOpagent, OPT_TYPE_BOOLEAN, "enable providing JIT output to Oprofile" },
+#endif
#if defined(ENABLE_GC_CACAO)
{ "GCDebugRootSet", OPT_GCDebugRootSet, OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
{ "GCStress", OPT_GCStress, OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
break;
#endif
+#if defined(ENABLE_OPAGENT)
+ case OPT_EnableOpagent:
+ opt_EnableOpagent = enable;
+ break;
+#endif
+
#if defined(ENABLE_GC_CACAO)
case OPT_GCDebugRootSet:
opt_GCDebugRootSet = enable;
#if defined(ENABLE_DISASSEMBLER)
extern int opt_DisassembleStubs;
#endif
+#if defined(ENABLE_OPAGENT)
+extern int opt_EnableOpagent;
+#endif
#if defined(ENABLE_GC_CACAO)
extern int opt_GCDebugRootSet;
extern int opt_GCStress;