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

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