java tracing
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 26 May 2006 03:51:26 +0000 (03:51 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 26 May 2006 03:51:26 +0000 (03:51 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1858 04897980-b3bd-0310-b5e0-8ef037075253

ltt-usertrace/java/Sample.java [new file with mode: 0644]
ltt-usertrace/java/generate.sh [new file with mode: 0755]
ltt-usertrace/java/ltt-java-string.c [new file with mode: 0644]

diff --git a/ltt-usertrace/java/Sample.java b/ltt-usertrace/java/Sample.java
new file mode 100644 (file)
index 0000000..08f7cc8
--- /dev/null
@@ -0,0 +1,15 @@
+// The Sample-java.java file
+public class Sample
+{
+  // Declaration of the Native (C) function
+  private static native void trace_java_generic_string(String arg);
+  static {
+    System.loadLibrary("ltt-java-string");
+  }
+
+  public static void main(String[] args)
+  {
+    System.out.println("Hello world");
+    Sample.trace_java_generic_string("Tracing from java");
+  }
+}
diff --git a/ltt-usertrace/java/generate.sh b/ltt-usertrace/java/generate.sh
new file mode 100755 (executable)
index 0000000..92ca199
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+javac Sample.java
+CLASSPATH=.:/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/bin javah -jni Sample
+gcc -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include \
+  -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux \
+  -shared -Wl,-soname,libltt-java-string \
+  -o libltt-java-string.so ltt-java-string.c \
+  ../ltt-facility-loader-user_generic.c
+LD_LIBRARY_PATH=. java Sample
diff --git a/ltt-usertrace/java/ltt-java-string.c b/ltt-usertrace/java/ltt-java-string.c
new file mode 100644 (file)
index 0000000..be011fb
--- /dev/null
@@ -0,0 +1,20 @@
+
+#include <jni.h>
+#include "Sample.h"
+#include <stdio.h>
+#include <unistd.h>
+
+#define LTT_TRACE
+#define LTT_BLOCKING 1
+#include <ltt/ltt-facility-user_generic.h>
+
+JNIEXPORT void JNICALL Java_Sample_trace_1java_1generic_1string
+  (JNIEnv *env, jobject obj, jstring jstr)
+{
+  const char *str;
+  str = (*env)->GetStringUTFChars(env, jstr, NULL);
+  if (str == NULL) return; // out of memory error thrown
+       trace_user_generic_string(str);
+  (*env)->ReleaseStringUTFChars(env, jstr, str);
+}
+
This page took 0.0248 seconds and 4 git commands to generate.