Blame SOURCES/0029-Speed-up-ExceptionCatch-event-callback.patch

78a2f7
From 2ccddc0329fb7103663f5d4c2347a3f8957ebe4b Mon Sep 17 00:00:00 2001
78a2f7
From: Jakub Filak <jfilak@redhat.com>
78a2f7
Date: Fri, 17 Jan 2014 20:09:05 +0100
78a2f7
Subject: [PATCH 29/39] Speed up ExceptionCatch event callback
78a2f7
78a2f7
Return from the callback immediately when there is no uncaught exception
78a2f7
to be checked. I suppose that the majority of ExceptionCatch events
78a2f7
occur in normal state of execution. The current solution needs to get
78a2f7
TID of the current thread just to find out that the uncaught exceptions
78a2f7
map is empty. This is not necessary because the map can provide such
78a2f7
information by counting the stored items. If the size of the map is
78a2f7
zero, we can safely return from the exception callback without other
78a2f7
processing.
78a2f7
78a2f7
Related to rhbz#1051198
78a2f7
---
78a2f7
 src/abrt-checker.c | 13 ++++++++-----
78a2f7
 src/jthread_map.c  |  7 +++++++
78a2f7
 src/jthread_map.h  | 10 ++++++++++
78a2f7
 3 files changed, 25 insertions(+), 5 deletions(-)
78a2f7
78a2f7
diff --git a/src/abrt-checker.c b/src/abrt-checker.c
78a2f7
index b6f11e8..1f91cb7 100644
78a2f7
--- a/src/abrt-checker.c
78a2f7
+++ b/src/abrt-checker.c
78a2f7
@@ -2251,11 +2251,8 @@ static void JNICALL callback_on_exception_catch(
78a2f7
             jlocation location __UNUSED_VAR,
78a2f7
             jobject   exception_object)
78a2f7
 {
78a2f7
-    jvmtiError error_code;
78a2f7
-
78a2f7
-    char *method_name_ptr = NULL;
78a2f7
-    char *method_signature_ptr = NULL;
78a2f7
-    char *class_signature_ptr = NULL;
78a2f7
+    if (jthread_map_empty(uncaughtExceptionMap))
78a2f7
+        return;
78a2f7
 
78a2f7
     /* all operations should be processed in critical section */
78a2f7
     enter_critical_section(jvmti_env, shared_lock);
78a2f7
@@ -2325,6 +2322,12 @@ static void JNICALL callback_on_exception_catch(
78a2f7
 
78a2f7
         if (NULL == threads_exc_buf || NULL == jthrowable_circular_buf_find(threads_exc_buf, rpt->exception_object))
78a2f7
         {
78a2f7
+            char *method_name_ptr = NULL;
78a2f7
+            char *method_signature_ptr = NULL;
78a2f7
+            char *class_signature_ptr = NULL;
78a2f7
+
78a2f7
+            jvmtiError error_code;
78a2f7
+
78a2f7
             /* retrieve all required informations */
78a2f7
             error_code = (*jvmti_env)->GetMethodName(jvmti_env, method, &method_name_ptr, &method_signature_ptr, NULL);
78a2f7
             if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
78a2f7
diff --git a/src/jthread_map.c b/src/jthread_map.c
78a2f7
index cd5ca52..e9d60e9 100644
78a2f7
--- a/src/jthread_map.c
78a2f7
+++ b/src/jthread_map.c
78a2f7
@@ -44,6 +44,7 @@ typedef struct jthread_map_item {
78a2f7
 struct jthread_map {
78a2f7
     T_jthreadMapItem *items[MAP_SIZE]; ///< map elements
78a2f7
     pthread_mutex_t mutex;
78a2f7
+    size_t size;
78a2f7
 };
78a2f7
 
78a2f7
 
78a2f7
@@ -75,6 +76,10 @@ void jthread_map_free(T_jthreadMap *map)
78a2f7
 }
78a2f7
 
78a2f7
 
78a2f7
+int jthread_map_empty(T_jthreadMap *map)
78a2f7
+{
78a2f7
+    return 0 == map->size;
78a2f7
+}
78a2f7
 
78a2f7
 static T_jthreadMapItem *jthrowable_map_item_new(long tid, void *item)
78a2f7
 {
78a2f7
@@ -110,6 +115,7 @@ void jthread_map_push(T_jthreadMap *map, jlong tid, void *item)
78a2f7
     assert(NULL != map);
78a2f7
 
78a2f7
     pthread_mutex_lock(&map->mutex);
78a2f7
+    ++map->size;
78a2f7
 
78a2f7
     const long index = tid % MAP_SIZE;
78a2f7
     T_jthreadMapItem *last = NULL;
78a2f7
@@ -168,6 +174,7 @@ void *jthread_map_pop(T_jthreadMap *map, jlong tid)
78a2f7
     assert(NULL != map);
78a2f7
 
78a2f7
     pthread_mutex_lock(&map->mutex);
78a2f7
+    --map->size;
78a2f7
 
78a2f7
     const size_t index = tid % MAP_SIZE;
78a2f7
     void *data = NULL;
78a2f7
diff --git a/src/jthread_map.h b/src/jthread_map.h
78a2f7
index 52d2832..4284a1b 100644
78a2f7
--- a/src/jthread_map.h
78a2f7
+++ b/src/jthread_map.h
78a2f7
@@ -50,6 +50,16 @@ void jthread_map_free(T_jthreadMap *map);
78a2f7
 
78a2f7
 
78a2f7
 /*
78a2f7
+ * Checks whether the map is empty
78a2f7
+ *
78a2f7
+ * @param mam Pointer to @jthread_map
78a2f7
+ * @returns true if the map is empty, false otherwise
78a2f7
+ */
78a2f7
+int jthread_map_empty(T_jthreadMap *map);
78a2f7
+
78a2f7
+
78a2f7
+
78a2f7
+/*
78a2f7
  * Adds a new map item identified by @tid with value @item
78a2f7
  *
78a2f7
  * Does nothing if item with same @tid already exists in @map
78a2f7
-- 
78a2f7
1.8.3.1
78a2f7