From 6e7bc9e0a5346b2dde6d9d5d72e0d2bf3a073f54 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Mon, 4 Jan 2016 15:11:11 -0500 Subject: [PATCH] Split the JNI APIs in separate classes Isolate the "native" methods in their own class, to better reflect what is present in the equivalent C files. Signed-off-by: Alexandre Montplaisir Signed-off-by: Mathieu Desnoyers --- .gitignore | 4 +- .../java/lttng-ust-agent-jul/Makefile.am | 5 ++- .../org/lttng/ust/agent/jul/LttngJulApi.java | 36 ++++++++++++++++++ .../lttng/ust/agent/jul/LttngLogHandler.java | 10 +---- .../java/lttng-ust-agent-log4j/Makefile.am | 5 ++- .../lttng/ust/agent/log4j/LttngLog4jApi.java | 38 +++++++++++++++++++ .../ust/agent/log4j/LttngLogAppender.java | 14 +------ liblttng-ust-java-agent/jni/jul/Makefile.am | 2 +- .../jni/jul/lttng_ust_jul.c | 4 +- liblttng-ust-java-agent/jni/log4j/Makefile.am | 2 +- .../jni/log4j/lttng_ust_log4j.c | 4 +- 11 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngJulApi.java create mode 100644 liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jApi.java diff --git a/.gitignore b/.gitignore index 287d9e7a..d480867e 100644 --- a/.gitignore +++ b/.gitignore @@ -61,8 +61,8 @@ classnoinst.stamp jni-header.stamp jul-jni-header.stamp log4j-jni-header.stamp -org_lttng_ust_agent_jul_LttngLogHandler.h -org_lttng_ust_agent_log4j_LttngLogAppender.h +org_lttng_ust_agent_jul_LttngJulApi.h +org_lttng_ust_agent_log4j_LttngLog4jApi.h # Python agent python-lttngust/lttngust/__init__.py diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/Makefile.am b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/Makefile.am index d32e1d69..c0316e23 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/Makefile.am +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/Makefile.am @@ -13,6 +13,7 @@ jardir = $(datadir)/java juljniout = ../../jni/jul dist_noinst_JAVA = $(pkgpath)/LttngJulAgent.java \ + $(pkgpath)/LttngJulApi.java \ $(pkgpath)/LttngLogHandler.java dist_noinst_DATA = $(jarfile_manifest) @@ -26,7 +27,7 @@ $(jarfile): classnoinst.stamp $(JAR) cfm $(JARFLAGS) $@ $(jarfile_manifest) $(classes) && rm -f $(jarfile_symlink) && $(LN_S) $@ $(jarfile_symlink) jul-jni-header.stamp: $(dist_noinst_JAVA) - $(JAVAH) -classpath $(CLASSPATH):$(srcdir) -d $(juljniout) $(JAVAHFLAGS) org.lttng.ust.agent.jul.LttngLogHandler && \ + $(JAVAH) -classpath $(CLASSPATH):$(srcdir) -d $(juljniout) $(JAVAHFLAGS) org.lttng.ust.agent.jul.LttngJulApi && \ echo "JUL JNI header generated" > jul-jni-header.stamp all-local: $(stamp) @@ -38,4 +39,4 @@ uninstall-hook: cd $(DESTDIR)/$(jardir) && rm -f $(jarfile_symlink) CLEANFILES = $(jarfile) $(pkgpath)/*.class jul-jni-header.stamp \ - $(juljniout)/org_lttng_ust_agent_jul_LttngLogHandler.h + $(juljniout)/org_lttng_ust_agent_jul_LttngJulApi.h diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngJulApi.java b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngJulApi.java new file mode 100644 index 00000000..f8a29d6d --- /dev/null +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngJulApi.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library 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 Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.lttng.ust.agent.jul; + +/** + * Virtual class containing the Java side of the LTTng-JUL JNI API methods. + * + * @author Alexandre Montplaisir + */ +final class LttngJulApi { + + private LttngJulApi() {} + + static native void tracepoint(String msg, + String logger_name, + String class_name, + String method_name, + long millis, + int log_level, + int thread_id); +} diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java index 39e08a83..3e61fe95 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java @@ -123,7 +123,7 @@ public class LttngLogHandler extends Handler implements ILttngHandler { * caller is used for the event name, the raw message is taken, the * loglevel of the record and the thread ID. */ - tracepoint(formattedMessage, + LttngJulApi.tracepoint(formattedMessage, record.getLoggerName(), record.getSourceClassName(), record.getSourceMethodName(), @@ -132,12 +132,4 @@ public class LttngLogHandler extends Handler implements ILttngHandler { record.getThreadID()); } - /* Send tracepoint information to the JNI library */ - private native void tracepoint(String msg, - String logger_name, - String class_name, - String method_name, - long millis, - int log_level, - int thread_id); } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/Makefile.am b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/Makefile.am index 9ae53233..c05f2129 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/Makefile.am +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/Makefile.am @@ -13,6 +13,7 @@ jardir = $(datadir)/java log4jjniout = ../../jni/log4j dist_noinst_JAVA = $(pkgpath)/LttngLog4jAgent.java \ + $(pkgpath)/LttngLog4jApi.java \ $(pkgpath)/LttngLogAppender.java dist_noinst_DATA = $(jarfile_manifest) @@ -26,7 +27,7 @@ $(jarfile): classnoinst.stamp $(JAR) cfm $(JARFLAGS) $@ $(jarfile_manifest) $(classes) && rm -f $(jarfile_symlink) && $(LN_S) $@ $(jarfile_symlink) log4j-jni-header.stamp: $(dist_noinst_JAVA) - $(JAVAH) -classpath $(CLASSPATH):$(srcdir) -d $(log4jjniout) $(JAVAHFLAGS) org.lttng.ust.agent.log4j.LttngLogAppender && \ + $(JAVAH) -classpath $(CLASSPATH):$(srcdir) -d $(log4jjniout) $(JAVAHFLAGS) org.lttng.ust.agent.log4j.LttngLog4jApi && \ echo "Log4j JNI header generated" > log4j-jni-header.stamp all-local: $(stamp) @@ -38,4 +39,4 @@ uninstall-hook: cd $(DESTDIR)/$(jardir) && rm -f $(jarfile_symlink) CLEANFILES = $(jarfile) $(pkgpath)/*.class log4j-jni-header.stamp \ - $(log4jjniout)/org_lttng_ust_agent_log4j_LttngLogAppender.h + $(log4jjniout)/org_lttng_ust_agent_log4j_LttngLog4jApi.h diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jApi.java b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jApi.java new file mode 100644 index 00000000..2521e9f0 --- /dev/null +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jApi.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library 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 Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.lttng.ust.agent.log4j; + +/** + * Virtual class containing the Java side of the LTTng-log4j JNI API methods. + * + * @author Alexandre Montplaisir + */ +final class LttngLog4jApi { + + private LttngLog4jApi() {} + + static native void tracepoint(String msg, + String logger_name, + String class_name, + String method_name, + String file_name, + int line_number, + long timestamp, + int loglevel, + String thread_name); +} diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLogAppender.java b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLogAppender.java index 98cc2c8d..753a5df3 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLogAppender.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLogAppender.java @@ -117,7 +117,8 @@ public class LttngLogAppender extends AppenderSkeleton implements ILttngHandler } eventCount.incrementAndGet(); - tracepoint(event.getRenderedMessage(), + + LttngLog4jApi.tracepoint(event.getRenderedMessage(), event.getLoggerName(), event.getLocationInformation().getClassName(), event.getLocationInformation().getMethodName(), @@ -128,15 +129,4 @@ public class LttngLogAppender extends AppenderSkeleton implements ILttngHandler event.getThreadName()); } - - /* Use for a user session daemon. */ - private native void tracepoint(String msg, - String logger_name, - String class_name, - String method_name, - String file_name, - int line_number, - long timestamp, - int loglevel, - String thread_name); } diff --git a/liblttng-ust-java-agent/jni/jul/Makefile.am b/liblttng-ust-java-agent/jni/jul/Makefile.am index 40906e10..cd0b7dc3 100644 --- a/liblttng-ust-java-agent/jni/jul/Makefile.am +++ b/liblttng-ust-java-agent/jni/jul/Makefile.am @@ -4,6 +4,6 @@ lib_LTLIBRARIES = liblttng-ust-jul-jni.la liblttng_ust_jul_jni_la_SOURCES = lttng_ust_jul.c \ lttng_ust_jul.h -nodist_liblttng_ust_jul_jni_la_SOURCES = org_lttng_ust_agent_jul_LttngLogHandler.h +nodist_liblttng_ust_jul_jni_la_SOURCES = org_lttng_ust_agent_jul_LttngJulApi.h liblttng_ust_jul_jni_la_LIBADD = -lc -L$(top_builddir)/liblttng-ust/.libs -llttng-ust diff --git a/liblttng-ust-java-agent/jni/jul/lttng_ust_jul.c b/liblttng-ust-java-agent/jni/jul/lttng_ust_jul.c index 0e86fbc7..a0e893e5 100644 --- a/liblttng-ust-java-agent/jni/jul/lttng_ust_jul.c +++ b/liblttng-ust-java-agent/jni/jul/lttng_ust_jul.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "org_lttng_ust_agent_jul_LttngLogHandler.h" +#include "org_lttng_ust_agent_jul_LttngJulApi.h" #define TRACEPOINT_DEFINE #define TRACEPOINT_CREATE_PROBES @@ -25,7 +25,7 @@ /* * Tracepoint used by Java applications using the JUL handler. */ -JNIEXPORT void JNICALL Java_org_lttng_ust_agent_jul_LttngLogHandler_tracepoint(JNIEnv *env, +JNIEXPORT void JNICALL Java_org_lttng_ust_agent_jul_LttngJulApi_tracepoint(JNIEnv *env, jobject jobj, jstring msg, jstring logger_name, diff --git a/liblttng-ust-java-agent/jni/log4j/Makefile.am b/liblttng-ust-java-agent/jni/log4j/Makefile.am index 07384f8d..5030a03f 100644 --- a/liblttng-ust-java-agent/jni/log4j/Makefile.am +++ b/liblttng-ust-java-agent/jni/log4j/Makefile.am @@ -3,6 +3,6 @@ lib_LTLIBRARIES = liblttng-ust-log4j-jni.la liblttng_ust_log4j_jni_la_SOURCES = lttng_ust_log4j.c \ lttng_ust_log4j.h -nodist_liblttng_ust_log4j_jni_la_SOURCES = org_lttng_ust_agent_log4j_LttngLogAppender.h +nodist_liblttng_ust_log4j_jni_la_SOURCES = org_lttng_ust_agent_log4j_LttngLog4jApi.h liblttng_ust_log4j_jni_la_LIBADD = -lc -L$(top_builddir)/liblttng-ust/.libs -llttng-ust diff --git a/liblttng-ust-java-agent/jni/log4j/lttng_ust_log4j.c b/liblttng-ust-java-agent/jni/log4j/lttng_ust_log4j.c index 73d4eee7..3b78c8e5 100644 --- a/liblttng-ust-java-agent/jni/log4j/lttng_ust_log4j.c +++ b/liblttng-ust-java-agent/jni/log4j/lttng_ust_log4j.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "org_lttng_ust_agent_log4j_LttngLogAppender.h" +#include "org_lttng_ust_agent_log4j_LttngLog4jApi.h" #define TRACEPOINT_DEFINE #define TRACEPOINT_CREATE_PROBES @@ -25,7 +25,7 @@ /* * System tracepoint meaning only root agent will fire this. */ -JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLogAppender_tracepoint(JNIEnv *env, +JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepoint(JNIEnv *env, jobject jobj, jstring msg, jstring logger_name, -- 2.34.1