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

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