Blame SOURCES/0024-Do-not-report-exceptions-caught-by-native-methods.patch

23d3c3
From 47461c8bd7427432bc0afe848db001e05f8d01a3 Mon Sep 17 00:00:00 2001
23d3c3
From: Jakub Filak <jfilak@redhat.com>
23d3c3
Date: Wed, 15 Jan 2014 11:49:36 +0100
23d3c3
Subject: [PATCH 24/39] Do not report exceptions caught by native methods
23d3c3
23d3c3
Related to rhbz#1051198
23d3c3
---
23d3c3
 src/abrt-checker.c | 247 ++++++++++++++++++++++++++++++++++++++++-------------
23d3c3
 src/jthread_map.c  |  26 +++---
23d3c3
 src/jthread_map.h  |  18 ++--
23d3c3
 3 files changed, 212 insertions(+), 79 deletions(-)
23d3c3
23d3c3
diff --git a/src/abrt-checker.c b/src/abrt-checker.c
23d3c3
index d5160cb..fb0c0eb 100644
23d3c3
--- a/src/abrt-checker.c
23d3c3
+++ b/src/abrt-checker.c
23d3c3
@@ -63,9 +63,6 @@
23d3c3
 /* Enables checks based on JVMTI_EVENT_VM_DEATH */
23d3c3
 /* #define ABRT_VM_DEATH_CHECK */
23d3c3
 
23d3c3
-/* Enables checks based on JVMTI_EVENT_EXCEPTION_CATCH  */
23d3c3
-/* #define ABRT_EXCEPTION_CATCH_CHECK */
23d3c3
-
23d3c3
 /* Enables checks based on JVMTI_EVENT_VM_OBJECT_ALLOC */
23d3c3
 /* #define ABRT_OBJECT_ALLOCATION_SIZE_CHECK */
23d3c3
 
23d3c3
@@ -165,6 +162,19 @@ typedef struct {
23d3c3
 
23d3c3
 
23d3c3
 /*
23d3c3
+ * This structure is representation of a single report of an exception.
23d3c3
+ */
23d3c3
+typedef struct {
23d3c3
+    char *message;
23d3c3
+    char *stacktrace;
23d3c3
+    char *executable;
23d3c3
+    char *exception_type_name;
23d3c3
+    jobject exception_object;
23d3c3
+} T_exceptionReport;
23d3c3
+
23d3c3
+
23d3c3
+
23d3c3
+/*
23d3c3
  * Flags for specification of destination for error reports
23d3c3
  */
23d3c3
 typedef enum {
23d3c3
@@ -214,6 +224,9 @@ int executableFlags = 0;
23d3c3
 /* Map of buffer for already reported exceptions to prevent re-reporting */
23d3c3
 T_jthreadMap *threadMap;
23d3c3
 
23d3c3
+/* Map of uncaught exceptions. There should be only 1 per thread.*/
23d3c3
+T_jthreadMap *uncaughtExceptionMap;
23d3c3
+
23d3c3
 
23d3c3
 /* forward headers */
23d3c3
 static char* get_path_to_class(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jclass class, char *class_name, const char *stringize_method_name);
23d3c3
@@ -453,9 +466,12 @@ static int exception_is_intended_to_be_reported(
23d3c3
 
23d3c3
     if (reportedCaughExceptionTypes != NULL)
23d3c3
     {
23d3c3
-        *exception_type = get_exception_type_name(jvmti_env, jni_env, exception_object);
23d3c3
         if (NULL == *exception_type)
23d3c3
-            return 0;
23d3c3
+        {
23d3c3
+            *exception_type = get_exception_type_name(jvmti_env, jni_env, exception_object);
23d3c3
+            if (NULL == *exception_type)
23d3c3
+                return 0;
23d3c3
+        }
23d3c3
 
23d3c3
         /* special cases for selected exceptions */
23d3c3
         for (char **cursor = reportedCaughExceptionTypes; *cursor; ++cursor)
23d3c3
@@ -1277,7 +1293,7 @@ static void JNICALL callback_on_thread_start(
23d3c3
         return;
23d3c3
     }
23d3c3
 
23d3c3
-    jthread_map_push(threadMap, tid, threads_exc_buf);
23d3c3
+    jthread_map_push(threadMap, tid, (void *)threads_exc_buf);
23d3c3
 }
23d3c3
 
23d3c3
 
23d3c3
@@ -1304,7 +1320,25 @@ static void JNICALL callback_on_thread_end(
23d3c3
         return;
23d3c3
     }
23d3c3
 
23d3c3
-    T_jthrowableCircularBuf *threads_exc_buf = jthread_map_pop(threadMap, tid);
23d3c3
+    T_exceptionReport *rpt = (T_exceptionReport *)jthread_map_pop(uncaughtExceptionMap, tid);
23d3c3
+    T_jthrowableCircularBuf *threads_exc_buf = (T_jthrowableCircularBuf *)jthread_map_pop(threadMap, tid);
23d3c3
+
23d3c3
+    if (NULL != rpt)
23d3c3
+    {
23d3c3
+        if (NULL == threads_exc_buf || NULL == jthrowable_circular_buf_find(threads_exc_buf, rpt->exception_object))
23d3c3
+        {
23d3c3
+            report_stacktrace(NULL != rpt->executable ? rpt->executable : processProperties.main_class,
23d3c3
+                              NULL != rpt->message ? rpt->message : "Uncaught exception",
23d3c3
+                              rpt->stacktrace,
23d3c3
+                              NULL != threads_exc_buf);
23d3c3
+        }
23d3c3
+
23d3c3
+        free(rpt->message);
23d3c3
+        free(rpt->stacktrace);
23d3c3
+        free(rpt->executable);
23d3c3
+        free(rpt->exception_type_name);
23d3c3
+    }
23d3c3
+
23d3c3
     if (threads_exc_buf != NULL)
23d3c3
     {
23d3c3
         jthrowable_circular_buf_free(threads_exc_buf);
23d3c3
@@ -2120,7 +2154,7 @@ static void JNICALL callback_on_exception(
23d3c3
 
23d3c3
         if (NULL != threadMap && 0 == get_tid(jni_env, thr, &tid))
23d3c3
         {
23d3c3
-            threads_exc_buf = jthread_map_get(threadMap, tid);
23d3c3
+            threads_exc_buf = (T_jthrowableCircularBuf *)jthread_map_get(threadMap, tid);
23d3c3
             VERBOSE_PRINT("Got circular buffer for thread %p\n", (void *)threads_exc_buf);
23d3c3
         }
23d3c3
         else
23d3c3
@@ -2137,12 +2171,6 @@ static void JNICALL callback_on_exception(
23d3c3
             char *class_name_ptr = NULL;
23d3c3
             char *class_signature_ptr = NULL;
23d3c3
 
23d3c3
-            if (NULL != threads_exc_buf)
23d3c3
-            {
23d3c3
-                VERBOSE_PRINT("Pushing to circular buffer\n");
23d3c3
-                jthrowable_circular_buf_push(threads_exc_buf, exception_object);
23d3c3
-            }
23d3c3
-
23d3c3
             error_code = (*jvmti_env)->GetMethodName(jvmti_env, method, &method_name_ptr, &method_signature_ptr, NULL);
23d3c3
             if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
                 goto callback_on_exception_cleanup;
23d3c3
@@ -2176,11 +2204,47 @@ static void JNICALL callback_on_exception(
23d3c3
             if (NULL == report_message)
23d3c3
                 report_message = (NULL != catch_method) ? "Caught exception" : "Uncaught exception";
23d3c3
 
23d3c3
-            report_stacktrace(NULL != executable ? executable : processProperties.main_class,
23d3c3
-                    report_message,
23d3c3
-                    stack_trace_str,
23d3c3
-                    NULL != threads_exc_buf);
23d3c3
+            if (NULL == catch_method)
23d3c3
+            {   /* Postpone reporting of uncaught exceptions as they may be caught by a native function */
23d3c3
+                T_exceptionReport *rpt = malloc(sizeof(*rpt));
23d3c3
+                if (NULL == rpt)
23d3c3
+                {
23d3c3
+                    fprintf(stderr, __FILE__ ":" STRINGIZE(__LINE__) ": malloc(): out of memory");
23d3c3
+                }
23d3c3
+                else
23d3c3
+                {
23d3c3
+                    rpt->message = message;
23d3c3
+                    message = NULL;
23d3c3
+
23d3c3
+                    rpt->exception_type_name = exception_type_name;
23d3c3
+                    exception_type_name = NULL;
23d3c3
+
23d3c3
+                    rpt->stacktrace = stack_trace_str;
23d3c3
+                    stack_trace_str = NULL;
23d3c3
+
23d3c3
+                    rpt->executable = executable;
23d3c3
+                    executable = NULL;
23d3c3
 
23d3c3
+                    rpt->exception_object = exception_object;
23d3c3
+
23d3c3
+                    jthread_map_push(uncaughtExceptionMap, tid, (T_exceptionReport *)rpt);
23d3c3
+                }
23d3c3
+            }
23d3c3
+            else
23d3c3
+            {
23d3c3
+                report_stacktrace(NULL != executable ? executable : processProperties.main_class,
23d3c3
+                        report_message,
23d3c3
+                        stack_trace_str,
23d3c3
+                        NULL != threads_exc_buf);
23d3c3
+
23d3c3
+                if (NULL != threads_exc_buf)
23d3c3
+                {
23d3c3
+                    VERBOSE_PRINT("Pushing to circular buffer\n");
23d3c3
+                    jthrowable_circular_buf_push(threads_exc_buf, exception_object);
23d3c3
+                }
23d3c3
+            }
23d3c3
+
23d3c3
+            free(executable);
23d3c3
             free(message);
23d3c3
             free(stack_trace_str);
23d3c3
 
23d3c3
@@ -2217,18 +2281,16 @@ callback_on_exception_cleanup:
23d3c3
 }
23d3c3
 
23d3c3
 
23d3c3
-
23d3c3
-#if ABRT_EXCEPTION_CATCH_CHECK
23d3c3
 /*
23d3c3
  * This function is called when an exception is catched.
23d3c3
  */
23d3c3
 static void JNICALL callback_on_exception_catch(
23d3c3
             jvmtiEnv *jvmti_env,
23d3c3
-            JNIEnv   *jni_env __UNUSED_VAR,
23d3c3
-            jthread   thr __UNUSED_VAR,
23d3c3
+            JNIEnv   *jni_env,
23d3c3
+            jthread   thread,
23d3c3
             jmethodID method,
23d3c3
             jlocation location __UNUSED_VAR,
23d3c3
-            jobject   exception __UNUSED_VAR)
23d3c3
+            jobject   exception_object)
23d3c3
 {
23d3c3
     jvmtiError error_code;
23d3c3
 
23d3c3
@@ -2236,52 +2298,120 @@ static void JNICALL callback_on_exception_catch(
23d3c3
     char *method_signature_ptr = NULL;
23d3c3
     char *class_signature_ptr = NULL;
23d3c3
 
23d3c3
-    jclass class;
23d3c3
-
23d3c3
     /* all operations should be processed in critical section */
23d3c3
     enter_critical_section(jvmti_env, shared_lock);
23d3c3
 
23d3c3
-    /* retrieve all required informations */
23d3c3
-    error_code = (*jvmti_env)->GetMethodName(jvmti_env, method, &method_name_ptr, &method_signature_ptr, NULL);
23d3c3
-    if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
-        goto callback_on_exception_catch_cleanup;
23d3c3
-
23d3c3
-    error_code = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &class);
23d3c3
-    if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
-        goto callback_on_exception_catch_cleanup;
23d3c3
+    jclass class;
23d3c3
 
23d3c3
-    error_code = (*jvmti_env)->GetClassSignature(jvmti_env, class, &class_signature_ptr, NULL);
23d3c3
-    if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
-        goto callback_on_exception_catch_cleanup;
23d3c3
+    jlong tid = 0;
23d3c3
 
23d3c3
-#ifdef VERBOSE
23d3c3
-    /* readable class name */
23d3c3
-    char *class_name_ptr = format_class_name(class_signature_ptr, '.');
23d3c3
-#endif
23d3c3
+    if (get_tid(jni_env, thread, &tid))
23d3c3
+    {
23d3c3
+        fprintf(stderr, __FILE__ ":" STRINGIZE(__LINE__) ": Cannot clear uncaught exceptions");
23d3c3
+        goto callback_on_exception_catch_exit;
23d3c3
+    }
23d3c3
 
23d3c3
-    VERBOSE_PRINT("An exception was caught in a method %s%s() with signature %s\n", class_name_ptr, method_name_ptr, method_signature_ptr);
23d3c3
+    T_exceptionReport *rpt = (T_exceptionReport *)jthread_map_get(uncaughtExceptionMap, tid);
23d3c3
+    if (NULL == rpt)
23d3c3
+    {
23d3c3
+        goto callback_on_exception_catch_exit;
23d3c3
+    }
23d3c3
 
23d3c3
-callback_on_exception_catch_cleanup:
23d3c3
-    /* cleapup */
23d3c3
-    if (method_name_ptr != NULL)
23d3c3
+    jclass object_class = (*jni_env)->FindClass(jni_env, "java/lang/Object");
23d3c3
+    if (NULL == object_class)
23d3c3
     {
23d3c3
-        error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_name_ptr);
23d3c3
-        check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
23d3c3
+        VERBOSE_PRINT("Cannot find java/lang/Object class");
23d3c3
+        goto callback_on_exception_catch_exit;
23d3c3
     }
23d3c3
-    if (method_signature_ptr != NULL)
23d3c3
+
23d3c3
+    jmethodID equal_method = (*jni_env)->GetMethodID(jni_env, object_class, "equals", "(Ljava/lang/Object;)Z");
23d3c3
+    if (NULL == equal_method)
23d3c3
     {
23d3c3
-        error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_signature_ptr);
23d3c3
-        check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
23d3c3
+        VERBOSE_PRINT("Cannot find java.lang.Object.equals(Ljava/lang/Object;)Z method");
23d3c3
+        (*jni_env)->DeleteLocalRef(jni_env, object_class);
23d3c3
+        goto callback_on_exception_catch_exit;
23d3c3
     }
23d3c3
-    if (class_signature_ptr != NULL)
23d3c3
+
23d3c3
+    jboolean equal_objects = (*jni_env)->CallBooleanMethod(jni_env, exception_object, equal_method, rpt->exception_object);
23d3c3
+    if (!equal_objects)
23d3c3
+        goto callback_on_exception_catch_exit;
23d3c3
+
23d3c3
+    /* Faster than get()-pop() approach is faster because it is search-and-search-free but
23d3c3
+     * pop()-push() approach is search-free-and-search-malloc
23d3c3
+     *
23d3c3
+     * JVM always catches java.security.PrivilegedActionException while
23d3c3
+     * handling uncaught java.lang.ClassNotFoundException throw by
23d3c3
+     * initialization of the system (native) class loader.
23d3c3
+     */
23d3c3
+    jthread_map_pop(uncaughtExceptionMap, tid);
23d3c3
+
23d3c3
+    if (exception_is_intended_to_be_reported(jvmti_env, jni_env, rpt->exception_object, &(rpt->exception_type_name)))
23d3c3
     {
23d3c3
-        error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)class_signature_ptr);
23d3c3
-        check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
23d3c3
+        jlong tid = 0;
23d3c3
+        T_jthrowableCircularBuf *threads_exc_buf = NULL;
23d3c3
+
23d3c3
+        if (NULL != threadMap && 0 == get_tid(jni_env, thread, &tid))
23d3c3
+        {
23d3c3
+            threads_exc_buf = (T_jthrowableCircularBuf *)jthread_map_get(threadMap, tid);
23d3c3
+            VERBOSE_PRINT("Got circular buffer for thread %p\n", (void *)threads_exc_buf);
23d3c3
+        }
23d3c3
+        else
23d3c3
+        {
23d3c3
+            VERBOSE_PRINT("Cannot get thread's ID. Disabling reporting to ABRT.");
23d3c3
+        }
23d3c3
+
23d3c3
+        if (NULL == threads_exc_buf || NULL == jthrowable_circular_buf_find(threads_exc_buf, rpt->exception_object))
23d3c3
+        {
23d3c3
+            /* retrieve all required informations */
23d3c3
+            error_code = (*jvmti_env)->GetMethodName(jvmti_env, method, &method_name_ptr, &method_signature_ptr, NULL);
23d3c3
+            if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
+                goto callback_on_exception_catch_cleanup;
23d3c3
+
23d3c3
+            error_code = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &class);
23d3c3
+            if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
+                goto callback_on_exception_catch_cleanup;
23d3c3
+
23d3c3
+            error_code = (*jvmti_env)->GetClassSignature(jvmti_env, class, &class_signature_ptr, NULL);
23d3c3
+            if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
23d3c3
+                goto callback_on_exception_catch_cleanup;
23d3c3
+
23d3c3
+            /* readable class name */
23d3c3
+            char *class_name_ptr = format_class_name(class_signature_ptr, '\0');
23d3c3
+            char *message = format_exception_reason_message(/*caught*/1, rpt->exception_type_name,  class_name_ptr, method_name_ptr);
23d3c3
+            report_stacktrace(NULL != rpt->executable ? rpt->executable : processProperties.main_class,
23d3c3
+                              NULL != message ? message : "Caught exception",
23d3c3
+                              rpt->stacktrace,
23d3c3
+                              NULL != threads_exc_buf);
23d3c3
+
23d3c3
+            if (NULL != threads_exc_buf)
23d3c3
+            {
23d3c3
+                VERBOSE_PRINT("Pushing to circular buffer\n");
23d3c3
+                jthrowable_circular_buf_push(threads_exc_buf, rpt->exception_object);
23d3c3
+            }
23d3c3
+
23d3c3
+callback_on_exception_catch_cleanup:
23d3c3
+            /* cleapup */
23d3c3
+            if (method_name_ptr != NULL)
23d3c3
+            {
23d3c3
+                error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_name_ptr);
23d3c3
+                check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
23d3c3
+            }
23d3c3
+            if (class_signature_ptr != NULL)
23d3c3
+            {
23d3c3
+                error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)class_signature_ptr);
23d3c3
+                check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
23d3c3
+            }
23d3c3
+        }
23d3c3
     }
23d3c3
 
23d3c3
+    free(rpt->message);
23d3c3
+    free(rpt->stacktrace);
23d3c3
+    free(rpt->executable);
23d3c3
+    free(rpt->exception_type_name);
23d3c3
+
23d3c3
+callback_on_exception_catch_exit:
23d3c3
     exit_critical_section(jvmti_env, shared_lock);
23d3c3
 }
23d3c3
-#endif /* ABRT_EXCEPTION_CATCH_CHECK */
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
@@ -2497,10 +2627,8 @@ jvmtiError register_all_callback_functions(jvmtiEnv *jvmti_env)
23d3c3
     /* JVMTI_EVENT_EXCEPTION */
23d3c3
     callbacks.Exception = &callback_on_exception;
23d3c3
 
23d3c3
-#if ABRT_EXCEPTION_CATCH_CHECK
23d3c3
     /* JVMTI_EVENT_EXCEPTION_CATCH */
23d3c3
     callbacks.ExceptionCatch = &callback_on_exception_catch;
23d3c3
-#endif /* ABRT_EXCEPTION_CATCH_CHECK */
23d3c3
 
23d3c3
 #if ABRT_OBJECT_ALLOCATION_SIZE_CHECK
23d3c3
     /* JVMTI_EVENT_VM_OBJECT_ALLOC */
23d3c3
@@ -2580,12 +2708,10 @@ jvmtiError set_event_notification_modes(jvmtiEnv* jvmti_env)
23d3c3
         return error_code;
23d3c3
     }
23d3c3
 
23d3c3
-#if ABRT_EXCEPTION_CATCH_CHECK
23d3c3
     if ((error_code = set_event_notification_mode(jvmti_env, JVMTI_EVENT_EXCEPTION_CATCH)) != JNI_OK)
23d3c3
     {
23d3c3
         return error_code;
23d3c3
     }
23d3c3
-#endif /* ABRT_EXCEPTION_CATCH_CHECK */
23d3c3
 
23d3c3
 #if ABRT_OBJECT_ALLOCATION_SIZE_CHECK
23d3c3
     if ((error_code = set_event_notification_mode(jvmti_env, JVMTI_EVENT_VM_OBJECT_ALLOC)) != JNI_OK)
23d3c3
@@ -2903,6 +3029,12 @@ JNIEXPORT jint JNICALL Agent_OnLoad(
23d3c3
         return -1;
23d3c3
     }
23d3c3
 
23d3c3
+    uncaughtExceptionMap = jthread_map_new();
23d3c3
+    if (NULL == uncaughtExceptionMap)
23d3c3
+    {
23d3c3
+        fprintf(stderr, __FILE__ ":" STRINGIZE(__LINE__) ": can not create a set of uncaught exceptions\n");
23d3c3
+        return -1;
23d3c3
+    }
23d3c3
     return JNI_OK;
23d3c3
 }
23d3c3
 
23d3c3
@@ -2928,6 +3060,7 @@ JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm __UNUSED_VAR)
23d3c3
         fclose(fout);
23d3c3
     }
23d3c3
 
23d3c3
+    jthread_map_free(uncaughtExceptionMap);
23d3c3
     jthread_map_free(threadMap);
23d3c3
 }
23d3c3
 
23d3c3
diff --git a/src/jthread_map.c b/src/jthread_map.c
23d3c3
index 29c5c29..cd5ca52 100644
23d3c3
--- a/src/jthread_map.c
23d3c3
+++ b/src/jthread_map.c
23d3c3
@@ -35,7 +35,7 @@ struct jthread_map_item;
23d3c3
 
23d3c3
 typedef struct jthread_map_item {
23d3c3
     long tid;                         ///< item ID from Thread.getId()
23d3c3
-    T_jthrowableCircularBuf *buffer;  ///< an instance of circular buffer for thread
23d3c3
+    void *data;                       ///< data
23d3c3
     struct jthread_map_item *next;    ///< a next item mapped to same element
23d3c3
 } T_jthreadMapItem;
23d3c3
 
23d3c3
@@ -76,7 +76,7 @@ void jthread_map_free(T_jthreadMap *map)
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
-static T_jthreadMapItem *jthrowable_map_item_new(long tid, T_jthrowableCircularBuf *buffer)
23d3c3
+static T_jthreadMapItem *jthrowable_map_item_new(long tid, void *item)
23d3c3
 {
23d3c3
     T_jthreadMapItem *itm = malloc(sizeof(*itm));
23d3c3
     if (NULL == itm)
23d3c3
@@ -86,7 +86,7 @@ static T_jthreadMapItem *jthrowable_map_item_new(long tid, T_jthrowableCircularB
23d3c3
     }
23d3c3
 
23d3c3
     itm->tid = tid;
23d3c3
-    itm->buffer = buffer;
23d3c3
+    itm->data = item;
23d3c3
     itm->next = NULL;
23d3c3
     return itm;
23d3c3
 }
23d3c3
@@ -105,7 +105,7 @@ static void jthread_map_item_free(T_jthreadMapItem *itm)
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
-void jthread_map_push(T_jthreadMap *map, jlong tid, T_jthrowableCircularBuf *buffer)
23d3c3
+void jthread_map_push(T_jthreadMap *map, jlong tid, void *item)
23d3c3
 {
23d3c3
     assert(NULL != map);
23d3c3
 
23d3c3
@@ -122,7 +122,7 @@ void jthread_map_push(T_jthreadMap *map, jlong tid, T_jthrowableCircularBuf *buf
23d3c3
 
23d3c3
     if (NULL == itm)
23d3c3
     {
23d3c3
-        T_jthreadMapItem *new = jthrowable_map_item_new(tid, buffer);
23d3c3
+        T_jthreadMapItem *new = jthrowable_map_item_new(tid, item);
23d3c3
         if (last == NULL)
23d3c3
         {
23d3c3
             map->items[index] = new;
23d3c3
@@ -138,39 +138,39 @@ void jthread_map_push(T_jthreadMap *map, jlong tid, T_jthrowableCircularBuf *buf
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
-T_jthrowableCircularBuf *jthread_map_get(T_jthreadMap *map, jlong tid)
23d3c3
+void *jthread_map_get(T_jthreadMap *map, jlong tid)
23d3c3
 {
23d3c3
     assert(NULL != map);
23d3c3
 
23d3c3
     pthread_mutex_lock(&map->mutex);
23d3c3
 
23d3c3
     const size_t index = tid % MAP_SIZE;
23d3c3
-    T_jthrowableCircularBuf *buffer = NULL;
23d3c3
+    void *data = NULL;
23d3c3
 
23d3c3
     for (T_jthreadMapItem *itm = map->items[index]; NULL != itm; itm = itm->next)
23d3c3
     {
23d3c3
         if (itm->tid == tid)
23d3c3
         {
23d3c3
-            buffer = itm->buffer;
23d3c3
+            data = itm->data;
23d3c3
             break;
23d3c3
         }
23d3c3
     }
23d3c3
 
23d3c3
     pthread_mutex_unlock(&map->mutex);
23d3c3
 
23d3c3
-    return buffer;
23d3c3
+    return data;
23d3c3
 }
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
-T_jthrowableCircularBuf *jthread_map_pop(T_jthreadMap *map, jlong tid)
23d3c3
+void *jthread_map_pop(T_jthreadMap *map, jlong tid)
23d3c3
 {
23d3c3
     assert(NULL != map);
23d3c3
 
23d3c3
     pthread_mutex_lock(&map->mutex);
23d3c3
 
23d3c3
     const size_t index = tid % MAP_SIZE;
23d3c3
-    T_jthrowableCircularBuf *buffer = NULL;
23d3c3
+    void *data = NULL;
23d3c3
     if (NULL != map->items[index])
23d3c3
     {
23d3c3
         T_jthreadMapItem *last = NULL;
23d3c3
@@ -183,7 +183,7 @@ T_jthrowableCircularBuf *jthread_map_pop(T_jthreadMap *map, jlong tid)
23d3c3
 
23d3c3
         if (NULL != itm)
23d3c3
         {
23d3c3
-            buffer = itm->buffer;
23d3c3
+            data = itm->data;
23d3c3
 
23d3c3
             if (NULL == last)
23d3c3
             {
23d3c3
@@ -200,7 +200,7 @@ T_jthrowableCircularBuf *jthread_map_pop(T_jthreadMap *map, jlong tid)
23d3c3
 
23d3c3
     pthread_mutex_unlock(&map->mutex);
23d3c3
 
23d3c3
-    return buffer;
23d3c3
+    return data;
23d3c3
 }
23d3c3
 
23d3c3
 
23d3c3
diff --git a/src/jthread_map.h b/src/jthread_map.h
23d3c3
index 29fcc92..52d2832 100644
23d3c3
--- a/src/jthread_map.h
23d3c3
+++ b/src/jthread_map.h
23d3c3
@@ -23,7 +23,7 @@
23d3c3
 
23d3c3
 
23d3c3
 /*
23d3c3
- * Map of TID to jthrowable_circular_buf
23d3c3
+ * Map of TID to (void *)
23d3c3
  */
23d3c3
 typedef struct jthread_map T_jthreadMap;
23d3c3
 
23d3c3
@@ -41,7 +41,7 @@ T_jthreadMap *jthread_map_new();
23d3c3
 /*
23d3c3
  * Frees map's memory
23d3c3
  *
23d3c3
- * Doesn't release memory of stored circular buffers.
23d3c3
+ * Doesn't release memory of stored (void *).
23d3c3
  *
23d3c3
  * @param map Pointer to @jthread_map. Accepts NULL
23d3c3
  */
23d3c3
@@ -50,15 +50,15 @@ void jthread_map_free(T_jthreadMap *map);
23d3c3
 
23d3c3
 
23d3c3
 /*
23d3c3
- * Adds a new map item identified by @tid with value @buffer
23d3c3
+ * Adds a new map item identified by @tid with value @item
23d3c3
  *
23d3c3
  * Does nothing if item with same @tid already exists in @map
23d3c3
  *
23d3c3
  * @param map Map
23d3c3
  * @param tid New item ID
23d3c3
- * @param buffer A pointer to @jthrowable_circular_buf
23d3c3
+ * @param item A (void *) item
23d3c3
  */
23d3c3
-void jthread_map_push(T_jthreadMap *map, jlong tid, T_jthrowableCircularBuf *buffer);
23d3c3
+void jthread_map_push(T_jthreadMap *map, jlong tid, void *item);
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
@@ -67,9 +67,9 @@ void jthread_map_push(T_jthreadMap *map, jlong tid, T_jthrowableCircularBuf *buf
23d3c3
  *
23d3c3
  * @param map Map
23d3c3
  * @param tid Required ID
23d3c3
- * @returns A pointer to stored @jthrowable_circular_buf or NULL if item with @tid was not found
23d3c3
+ * @returns A stored item or NULL if item with @tid was not found
23d3c3
  */
23d3c3
-T_jthrowableCircularBuf *jthread_map_get(T_jthreadMap *map, jlong tid);
23d3c3
+void *jthread_map_get(T_jthreadMap *map, jlong tid);
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
@@ -78,9 +78,9 @@ T_jthrowableCircularBuf *jthread_map_get(T_jthreadMap *map, jlong tid);
23d3c3
  *
23d3c3
  * @param map Map
23d3c3
  * @param tid Removed item's ID
23d3c3
- * @returns A pointer to stored @jthrowable_circular_buf or NULL if item with @tid was not found
23d3c3
+ * @returns A stored item or NULL if item with @tid was not found
23d3c3
  */
23d3c3
-T_jthrowableCircularBuf *jthread_map_pop(T_jthreadMap *map, jlong tid);
23d3c3
+void *jthread_map_pop(T_jthreadMap *map, jlong tid);
23d3c3
 
23d3c3
 
23d3c3
 
23d3c3
-- 
23d3c3
1.8.3.1
23d3c3