|
|
78a2f7 |
From ba1f3f10129765dec30caa238679331db6848938 Mon Sep 17 00:00:00 2001
|
|
|
78a2f7 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
78a2f7 |
Date: Wed, 15 Jan 2014 09:14:44 +0100
|
|
|
78a2f7 |
Subject: [PATCH 22/39] Exception callback code optimizations
|
|
|
78a2f7 |
|
|
|
78a2f7 |
The old code was doing a lot of stuff which is not necessary when the
|
|
|
78a2f7 |
processes exception won't be reported.
|
|
|
78a2f7 |
|
|
|
78a2f7 |
Related to rhbz#1051198
|
|
|
78a2f7 |
---
|
|
|
78a2f7 |
src/abrt-checker.c | 180 ++++++++++++++++++++++++++++++++---------------------
|
|
|
78a2f7 |
1 file changed, 108 insertions(+), 72 deletions(-)
|
|
|
78a2f7 |
|
|
|
78a2f7 |
diff --git a/src/abrt-checker.c b/src/abrt-checker.c
|
|
|
78a2f7 |
index 613a0ec..a5c2bdd 100644
|
|
|
78a2f7 |
--- a/src/abrt-checker.c
|
|
|
78a2f7 |
+++ b/src/abrt-checker.c
|
|
|
78a2f7 |
@@ -219,6 +219,7 @@ T_jthreadMap *threadMap;
|
|
|
78a2f7 |
static char* get_path_to_class(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jclass class, char *class_name, const char *stringize_method_name);
|
|
|
78a2f7 |
static void print_jvm_environment_variables_to_file(FILE *out);
|
|
|
78a2f7 |
static char* format_class_name(char *class_signature, char replace_to);
|
|
|
78a2f7 |
+static int check_jvmti_error(jvmtiEnv *jvmti_env, jvmtiError error_code, const char *str);
|
|
|
78a2f7 |
|
|
|
78a2f7 |
|
|
|
78a2f7 |
|
|
|
78a2f7 |
@@ -404,26 +405,70 @@ static const char * null2empty(const char *str)
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
|
|
|
78a2f7 |
|
|
|
78a2f7 |
+static char *get_exception_type_name(
|
|
|
78a2f7 |
+ jvmtiEnv *jvmti_env,
|
|
|
78a2f7 |
+ JNIEnv *jni_env,
|
|
|
78a2f7 |
+ jobject exception_object)
|
|
|
78a2f7 |
+{
|
|
|
78a2f7 |
+ jclass exception_class = (*jni_env)->GetObjectClass(jni_env, exception_object);
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ char *exception_name_ptr = NULL;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ /* retrieve all required informations */
|
|
|
78a2f7 |
+ jvmtiError error_code = (*jvmti_env)->GetClassSignature(jvmti_env, exception_class, &exception_name_ptr, NULL);
|
|
|
78a2f7 |
+ if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
|
|
|
78a2f7 |
+ return NULL;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ char *formated_exception_name_ptr = format_class_name(exception_name_ptr, '\0');
|
|
|
78a2f7 |
+ if (formated_exception_name_ptr != exception_name_ptr)
|
|
|
78a2f7 |
+ {
|
|
|
78a2f7 |
+ char *dest = exception_name_ptr;
|
|
|
78a2f7 |
+ char *src = formated_exception_name_ptr;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ while(src[0] != '\0')
|
|
|
78a2f7 |
+ {
|
|
|
78a2f7 |
+ *dest = *src;
|
|
|
78a2f7 |
+ ++dest;
|
|
|
78a2f7 |
+ ++src;
|
|
|
78a2f7 |
+ }
|
|
|
78a2f7 |
+ dest[0] = '\0';
|
|
|
78a2f7 |
+ }
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ return exception_name_ptr;
|
|
|
78a2f7 |
+}
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
|
|
|
78a2f7 |
/*
|
|
|
78a2f7 |
* Returns non zero value if exception's type is intended to be reported even
|
|
|
78a2f7 |
* if the exception was caught.
|
|
|
78a2f7 |
*/
|
|
|
78a2f7 |
-static int exception_is_intended_to_be_reported(const char *type_name)
|
|
|
78a2f7 |
+static int exception_is_intended_to_be_reported(
|
|
|
78a2f7 |
+ jvmtiEnv *jvmti_env,
|
|
|
78a2f7 |
+ JNIEnv *jni_env,
|
|
|
78a2f7 |
+ jobject exception_object,
|
|
|
78a2f7 |
+ char **exception_type)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
+ int retval = 0;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
if (reportedCaughExceptionTypes != NULL)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
+ *exception_type = get_exception_type_name(jvmti_env, jni_env, exception_object);
|
|
|
78a2f7 |
+ if (NULL == *exception_type)
|
|
|
78a2f7 |
+ return 0;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
/* special cases for selected exceptions */
|
|
|
78a2f7 |
for (char **cursor = reportedCaughExceptionTypes; *cursor; ++cursor)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
- if (strcmp(*cursor, type_name) == 0)
|
|
|
78a2f7 |
+ if (strcmp(*cursor, *exception_type) == 0)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
- return 1;
|
|
|
78a2f7 |
+ retval = 1;
|
|
|
78a2f7 |
+ break;
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
|
|
|
78a2f7 |
- return 0;
|
|
|
78a2f7 |
+ return retval;
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
|
|
|
78a2f7 |
|
|
|
78a2f7 |
@@ -695,19 +740,21 @@ static char* format_class_name(char *class_signature, char replace_to)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
output++; /* goto to the next character */
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
- /* replace the last character in the class name */
|
|
|
78a2f7 |
- /* but inly if this character is ';' */
|
|
|
78a2f7 |
- char *last_char = output + strlen(output) - 1;
|
|
|
78a2f7 |
- if (*last_char == ';')
|
|
|
78a2f7 |
- {
|
|
|
78a2f7 |
- *last_char = replace_to;
|
|
|
78a2f7 |
- }
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
/* replace all '/'s to '.'s */
|
|
|
78a2f7 |
char *c;
|
|
|
78a2f7 |
for (c = class_signature; *c != 0; c++)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
if (*c == '/') *c = '.';
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ /* replace the last character in the class name */
|
|
|
78a2f7 |
+ /* but inly if this character is ';' */
|
|
|
78a2f7 |
+ /* c[0] == '\0' see the for loop above */
|
|
|
78a2f7 |
+ if (c != class_signature && c[-1] == ';')
|
|
|
78a2f7 |
+ {
|
|
|
78a2f7 |
+ c[-1] = replace_to;
|
|
|
78a2f7 |
+ }
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
else
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
@@ -2053,52 +2100,17 @@ static void JNICALL callback_on_exception(
|
|
|
78a2f7 |
jmethodID catch_method,
|
|
|
78a2f7 |
jlocation catch_location __UNUSED_VAR)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
- jvmtiError error_code;
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- char *method_name_ptr = NULL;
|
|
|
78a2f7 |
- char *method_signature_ptr = NULL;
|
|
|
78a2f7 |
- char *class_name_ptr = NULL;
|
|
|
78a2f7 |
- char *class_signature_ptr = NULL;
|
|
|
78a2f7 |
- char *exception_name_ptr = NULL;
|
|
|
78a2f7 |
- char *updated_exception_name_ptr = NULL;
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- jclass method_class;
|
|
|
78a2f7 |
- jclass exception_class;
|
|
|
78a2f7 |
+ char *exception_type_name = NULL;
|
|
|
78a2f7 |
|
|
|
78a2f7 |
/* all operations should be processed in critical section */
|
|
|
78a2f7 |
enter_critical_section(jvmti_env, shared_lock);
|
|
|
78a2f7 |
|
|
|
78a2f7 |
- char tname[MAX_THREAD_NAME_LENGTH];
|
|
|
78a2f7 |
- get_thread_name(jvmti_env, thr, tname, sizeof(tname));
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- exception_class = (*jni_env)->GetObjectClass(jni_env, exception_object);
|
|
|
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 |
- goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &method_class);
|
|
|
78a2f7 |
- if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
|
|
|
78a2f7 |
- goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->GetClassSignature(jvmti_env, method_class, &class_signature_ptr, NULL);
|
|
|
78a2f7 |
- if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
|
|
|
78a2f7 |
- goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->GetClassSignature(jvmti_env, exception_class, &exception_name_ptr, NULL);
|
|
|
78a2f7 |
- if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
|
|
|
78a2f7 |
- goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
/* readable class names */
|
|
|
78a2f7 |
- class_name_ptr = format_class_name(class_signature_ptr, '.');
|
|
|
78a2f7 |
- updated_exception_name_ptr = format_class_name(exception_name_ptr, '\0');
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- INFO_PRINT("%s %s exception in thread \"%s\" ", (catch_method == NULL ? "Uncaught" : "Caught"), updated_exception_name_ptr, tname);
|
|
|
78a2f7 |
- INFO_PRINT("in a method %s%s() with signature %s\n", class_name_ptr, method_name_ptr, method_signature_ptr);
|
|
|
78a2f7 |
-
|
|
|
78a2f7 |
- if (catch_method == NULL || exception_is_intended_to_be_reported(updated_exception_name_ptr))
|
|
|
78a2f7 |
+ if (catch_method == NULL || exception_is_intended_to_be_reported(jvmti_env, jni_env, exception_object, &exception_type_name))
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
+ char tname[MAX_THREAD_NAME_LENGTH];
|
|
|
78a2f7 |
+ get_thread_name(jvmti_env, thr, tname, sizeof(tname));
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
jlong tid = 0;
|
|
|
78a2f7 |
T_jthrowableCircularBuf *threads_exc_buf = NULL;
|
|
|
78a2f7 |
|
|
|
78a2f7 |
@@ -2114,19 +2126,43 @@ static void JNICALL callback_on_exception(
|
|
|
78a2f7 |
|
|
|
78a2f7 |
if (NULL == threads_exc_buf || NULL == jthrowable_circular_buf_find(threads_exc_buf, exception_object))
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
+ jvmtiError error_code;
|
|
|
78a2f7 |
+ jclass method_class;
|
|
|
78a2f7 |
+ char *method_name_ptr = NULL;
|
|
|
78a2f7 |
+ char *method_signature_ptr = NULL;
|
|
|
78a2f7 |
+ char *class_name_ptr = NULL;
|
|
|
78a2f7 |
+ char *class_signature_ptr = NULL;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
if (NULL != threads_exc_buf)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
VERBOSE_PRINT("Pushing to circular buffer\n");
|
|
|
78a2f7 |
jthrowable_circular_buf_push(threads_exc_buf, exception_object);
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
|
|
|
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 |
+ goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ error_code = (*jvmti_env)->GetMethodDeclaringClass(jvmti_env, method, &method_class);
|
|
|
78a2f7 |
+ if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
|
|
|
78a2f7 |
+ goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ error_code = (*jvmti_env)->GetClassSignature(jvmti_env, method_class, &class_signature_ptr, NULL);
|
|
|
78a2f7 |
+ if (check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__)))
|
|
|
78a2f7 |
+ goto callback_on_exception_cleanup;
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+ class_name_ptr = format_class_name(class_signature_ptr, '.');
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
/* Remove trailing '.' */
|
|
|
78a2f7 |
const ssize_t class_name_len = strlen(class_name_ptr);
|
|
|
78a2f7 |
if (class_name_len > 0)
|
|
|
78a2f7 |
class_name_ptr[class_name_len - 1] = '\0';
|
|
|
78a2f7 |
|
|
|
78a2f7 |
+ if (NULL == exception_type_name)
|
|
|
78a2f7 |
+ exception_type_name = get_exception_type_name(jvmti_env, jni_env, exception_object);
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
char *message = format_exception_reason_message(/*caught?*/NULL != catch_method,
|
|
|
78a2f7 |
- updated_exception_name_ptr, class_name_ptr, method_name_ptr);
|
|
|
78a2f7 |
+ exception_type_name, class_name_ptr, method_name_ptr);
|
|
|
78a2f7 |
|
|
|
78a2f7 |
char *executable = NULL;
|
|
|
78a2f7 |
char *stack_trace_str = generate_thread_stack_trace(jvmti_env, jni_env, tname, exception_object,
|
|
|
78a2f7 |
@@ -2143,6 +2179,24 @@ static void JNICALL callback_on_exception(
|
|
|
78a2f7 |
|
|
|
78a2f7 |
free(message);
|
|
|
78a2f7 |
free(stack_trace_str);
|
|
|
78a2f7 |
+
|
|
|
78a2f7 |
+callback_on_exception_cleanup:
|
|
|
78a2f7 |
+ /* cleapup */
|
|
|
78a2f7 |
+ if (method_name_ptr != NULL)
|
|
|
78a2f7 |
+ {
|
|
|
78a2f7 |
+ error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_name_ptr);
|
|
|
78a2f7 |
+ check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
+ }
|
|
|
78a2f7 |
+ if (method_signature_ptr != NULL)
|
|
|
78a2f7 |
+ {
|
|
|
78a2f7 |
+ error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_signature_ptr);
|
|
|
78a2f7 |
+ check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
+ }
|
|
|
78a2f7 |
+ if (class_signature_ptr != NULL)
|
|
|
78a2f7 |
+ {
|
|
|
78a2f7 |
+ error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)class_signature_ptr);
|
|
|
78a2f7 |
+ check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
+ }
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
else
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
@@ -2150,27 +2204,9 @@ static void JNICALL callback_on_exception(
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
|
|
|
78a2f7 |
-callback_on_exception_cleanup:
|
|
|
78a2f7 |
- /* cleapup */
|
|
|
78a2f7 |
- if (method_name_ptr != NULL)
|
|
|
78a2f7 |
- {
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_name_ptr);
|
|
|
78a2f7 |
- check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
- }
|
|
|
78a2f7 |
- if (method_signature_ptr != NULL)
|
|
|
78a2f7 |
+ if (NULL != exception_type_name)
|
|
|
78a2f7 |
{
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)method_signature_ptr);
|
|
|
78a2f7 |
- check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
- }
|
|
|
78a2f7 |
- if (class_signature_ptr != NULL)
|
|
|
78a2f7 |
- {
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)class_signature_ptr);
|
|
|
78a2f7 |
- check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
- }
|
|
|
78a2f7 |
- if (exception_name_ptr != NULL)
|
|
|
78a2f7 |
- {
|
|
|
78a2f7 |
- error_code = (*jvmti_env)->Deallocate(jvmti_env, (unsigned char *)exception_name_ptr);
|
|
|
78a2f7 |
- check_jvmti_error(jvmti_env, error_code, __FILE__ ":" STRINGIZE(__LINE__));
|
|
|
78a2f7 |
+ free(exception_type_name);
|
|
|
78a2f7 |
}
|
|
|
78a2f7 |
|
|
|
78a2f7 |
exit_critical_section(jvmti_env, shared_lock);
|
|
|
78a2f7 |
--
|
|
|
78a2f7 |
1.8.3.1
|
|
|
78a2f7 |
|