[jboss-cvs] JBoss Profiler SVN: r519 - in branches/JBossProfiler2: src and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 19 08:55:41 EDT 2009


Author: jesper.pedersen
Date: 2009-04-19 08:55:40 -0400 (Sun, 19 Apr 2009)
New Revision: 519

Added:
   branches/JBossProfiler2/CMakeLists.txt
   branches/JBossProfiler2/src/CMakeLists.txt
   branches/JBossProfiler2/src/native/
   branches/JBossProfiler2/src/native/CMakeLists.txt
   branches/JBossProfiler2/src/native/agent.cpp
   branches/JBossProfiler2/src/native/agent.h
Log:
[JBPROFILER-60] Integrate a native build environment

Added: branches/JBossProfiler2/CMakeLists.txt
===================================================================
--- branches/JBossProfiler2/CMakeLists.txt	                        (rev 0)
+++ branches/JBossProfiler2/CMakeLists.txt	2009-04-19 12:55:40 UTC (rev 519)
@@ -0,0 +1,13 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+PROJECT(jboss-profiler)
+SET(${PROJECT_NAME}_MAJOR_VERSION 0)
+SET(${PROJECT_NAME}_MINOR_VERSION 1)
+SET(${PROJECT_NAME}_PATCH_LEVEL 0)
+
+FIND_PACKAGE(Java)
+FIND_PACKAGE(JNI)
+
+ADD_DEFINITIONS("-O2 -Wall -ansi")
+
+SUBDIRS(src)

Added: branches/JBossProfiler2/src/CMakeLists.txt
===================================================================
--- branches/JBossProfiler2/src/CMakeLists.txt	                        (rev 0)
+++ branches/JBossProfiler2/src/CMakeLists.txt	2009-04-19 12:55:40 UTC (rev 519)
@@ -0,0 +1 @@
+SUBDIRS(native)

Added: branches/JBossProfiler2/src/native/CMakeLists.txt
===================================================================
--- branches/JBossProfiler2/src/native/CMakeLists.txt	                        (rev 0)
+++ branches/JBossProfiler2/src/native/CMakeLists.txt	2009-04-19 12:55:40 UTC (rev 519)
@@ -0,0 +1,6 @@
+INCLUDE_DIRECTORIES(. ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH}/linux)
+ADD_LIBRARY(JBossProfiler SHARED agent)
+
+INSTALL(TARGETS JBossProfiler
+        DESTINATION lib
+        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

Added: branches/JBossProfiler2/src/native/agent.cpp
===================================================================
--- branches/JBossProfiler2/src/native/agent.cpp	                        (rev 0)
+++ branches/JBossProfiler2/src/native/agent.cpp	2009-04-19 12:55:40 UTC (rev 519)
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <string>
+#include <stdlib.h>
+#include <stdio.h>
+#include <jni.h>
+#include <jvmti.h>
+
+#define AGENT_MAIN
+#include <agent.h>
+
+jint 
+init_jvmti_callbacks(JavaVM* jvm)
+{
+   jint res;
+   jvmtiError error;
+   jvmtiCapabilities capabilities;
+   jvmtiEventCallbacks callbacks;
+
+   res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_0);
+   if (res != JNI_OK) {
+      return res;
+   }
+
+   // Set the capabilities
+   error = jvmti->GetCapabilities(&capabilities);
+   verifyError(error);
+
+   capabilities.can_generate_method_entry_events = 1;
+
+   error = jvmti->AddCapabilities(&capabilities);
+   verifyError(error);
+   
+   jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
+   
+   return JNI_OK;
+}
+
+
+
+JNIEXPORT jint JNICALL 
+Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
+{
+   printf("Loading JBoss Profiler agent\n");
+
+   return init_jvmti_callbacks(jvm);
+}
+
+JNIEXPORT void JNICALL 
+Agent_OnUnload(JavaVM *jvm)
+{
+   printf("Unloading JBoss Profiler agent\n");
+}

Added: branches/JBossProfiler2/src/native/agent.h
===================================================================
--- branches/JBossProfiler2/src/native/agent.h	                        (rev 0)
+++ branches/JBossProfiler2/src/native/agent.h	2009-04-19 12:55:40 UTC (rev 519)
@@ -0,0 +1,17 @@
+#include <jvmti.h>
+
+#ifdef AGENT_MAIN
+jvmtiEnv *jvmti = NULL;
+#else
+extern jvmtiEnv *jvmti;
+#endif
+
+inline void verifyError(jvmtiError error) {
+   if ( error != JVMTI_ERROR_NONE ) {
+      char * errorName;
+      jvmti->GetErrorName(error,&errorName);
+      fprintf (stderr,"JVMTI Error %s\n",errorName);
+      fflush(stderr);
+      jvmti->Deallocate((unsigned char *)errorName);
+   }
+}




More information about the jboss-cvs-commits mailing list