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

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