From: Robert Schuster Date: Fri, 8 Aug 2008 08:40:00 +0000 (+0200) Subject: configure.ac: Added AC_CHECK_ENABLE_OPAGENT. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=cacao.git;a=commitdiff_plain;h=ad6c5b222ac4cd777101545580d7f11fa254d6c2 configure.ac: Added AC_CHECK_ENABLE_OPAGENT. 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. --- diff --git a/configure.ac b/configure.ac index 3853a5853..f119092de 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 000000000..5b5596102 --- /dev/null +++ b/m4/opagent.m4 @@ -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=,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=,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"]) +]) + diff --git a/src/vm/jit/Makefile.am b/src/vm/jit/Makefile.am index ae59305d1..31140671a 100644 --- a/src/vm/jit/Makefile.am +++ b/src/vm/jit/Makefile.am @@ -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 \ diff --git a/src/vm/jit/jit.c b/src/vm/jit/jit.c index e83e16886..295cebda9 100644 --- a/src/vm/jit/jit.c +++ b/src/vm/jit/jit.c @@ -57,6 +57,10 @@ #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 index 000000000..393697268 --- /dev/null +++ b/src/vm/jit/oprofile-agent.cpp @@ -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 + +/* 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 index 000000000..e21b72295 --- /dev/null +++ b/src/vm/jit/oprofile-agent.hpp @@ -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 + +#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: + */ diff --git a/src/vmcore/options.c b/src/vmcore/options.c index 47981338a..641dd47a2 100644 --- a/src/vmcore/options.c +++ b/src/vmcore/options.c @@ -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; diff --git a/src/vmcore/options.h b/src/vmcore/options.h index 8b4ae1f58..539f1ee0a 100644 --- a/src/vmcore/options.h +++ b/src/vmcore/options.h @@ -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;