configure.ac: Added AC_CHECK_ENABLE_OPAGENT.
authorRobert Schuster <robertschuster@fsfe.org>
Fri, 8 Aug 2008 08:40:00 +0000 (10:40 +0200)
committerRobert Schuster <robertschuster@fsfe.org>
Fri, 8 Aug 2008 08:40:00 +0000 (10:40 +0200)
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.

configure.ac
m4/opagent.m4 [new file with mode: 0644]
src/vm/jit/Makefile.am
src/vm/jit/jit.c
src/vm/jit/oprofile-agent.cpp [new file with mode: 0644]
src/vm/jit/oprofile-agent.hpp [new file with mode: 0644]
src/vmcore/options.c
src/vmcore/options.h

index 3853a5853b4d12ec92d784c5e5b42ba6ae155242..f119092de49e1ab7df0bbb605a769a77b6ea584d 100644 (file)
@@ -520,6 +520,7 @@ else
        AM_CONDITIONAL([USE_SCHEDULER], [false])
 fi
 
+AC_CHECK_ENABLE_OPAGENT
 
 AC_CHECK_ENABLE_ZLIB
 
diff --git a/m4/opagent.m4 b/m4/opagent.m4
new file mode 100644 (file)
index 0000000..5b55961
--- /dev/null
@@ -0,0 +1,58 @@
+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"])
+])
+
index ae59305d12d05f669a3928da97724cc31b858970..31140671af9e6d9f1df50622470cc76064b8c9be 100644 (file)
@@ -127,6 +127,13 @@ VERIFIER_LIB = \
        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
@@ -178,7 +185,8 @@ libjit_la_SOURCES = \
        stacktrace.hpp \
        trace.cpp \
        trace.hpp \
-       $(TRAP_SOURCES)
+       $(TRAP_SOURCES) \
+       $(OPAGENT_SOURCES)
 
 libjit_la_SOURCES += \
        cfg.c \
index e83e168864f63bb9601f807b10edab10ecad633d..295cebda93b41283476ea3970e5f34bd9a76f803 100644 (file)
 #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"
@@ -210,6 +214,11 @@ void jit_init(void)
 #else
        intrp_md_init();
 #endif
+
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_initialize();
+#endif
 }
 
 
@@ -221,7 +230,10 @@ void jit_init(void)
 
 void jit_close(void)
 {
-       /* do nothing */
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_close();
+#endif
 }
 
 
@@ -444,6 +456,11 @@ u1 *jit_compile(methodinfo *m)
                compilingtime_stop();
 #endif
 
+#if defined(ENABLE_OPAGENT)
+       if (opt_EnableOpagent)
+               OprofileAgent_newmethod(m);
+#endif
+
        /* leave the monitor */
 
        LOCK_MONITOR_EXIT(m);
@@ -556,6 +573,11 @@ u1 *jit_recompile(methodinfo *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 */
diff --git a/src/vm/jit/oprofile-agent.cpp b/src/vm/jit/oprofile-agent.cpp
new file mode 100644 (file)
index 0000000..3936972
--- /dev/null
@@ -0,0 +1,118 @@
+/* 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:
+ */
diff --git a/src/vm/jit/oprofile-agent.hpp b/src/vm/jit/oprofile-agent.hpp
new file mode 100644 (file)
index 0000000..e21b722
--- /dev/null
@@ -0,0 +1,84 @@
+/* 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:
+ */
index 47981338a37242ddc3529a4299cbb2b41ee20841..641dd47a2306a7976372be4ca26305c6667328b5 100644 (file)
@@ -113,6 +113,9 @@ bool opt_prof    = false;
 bool opt_prof_bb = false;
 #endif
 
+#if defined(ENABLE_OPAGENT)
+bool opt_opagent = false;
+#endif
 
 /* optimization options *******************************************************/
 
@@ -175,6 +178,9 @@ int      opt_DebugThreads                 = 0;
 #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;
@@ -240,6 +246,7 @@ enum {
        OPT_DebugStackTrace,
        OPT_DebugThreads,
        OPT_DisassembleStubs,
+       OPT_EnableOpagent,
        OPT_GCDebugRootSet,
        OPT_GCStress,
        OPT_Inline,
@@ -294,6 +301,9 @@ option_t options_XX[] = {
 #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" },
@@ -656,6 +666,12 @@ void options_xx(JavaVMInitArgs *vm_args)
                        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;
index 8b4ae1f58c1834f89604f6dc1ebab7a537993b3d..539f1ee0a9dbacea3ff2917af624ed43ae4678a0 100644 (file)
@@ -197,6 +197,9 @@ extern int      opt_DebugThreads;
 #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;