Commit 8cc658c7 authored by Lubomir Bulej's avatar Lubomir Bulej
Browse files

Don't query thread id during debugging to avoid JVM crashes

Calling the thread.getId() function through JNI seems to cause JVM
crashes when runtime debugging is enabled, so we avoid it for now.
parent 4ed458f0
Pipeline #19440 passed with stages
in 12 minutes and 26 seconds
......@@ -153,10 +153,6 @@ static volatile bool java_is_9_or_above;
rdoutput ("disl-agent [%s]: ", __safe_name ((info)->name)); \
rdoutput (args);
#define rdatiprefix(info, args...) \
rdoutput ("disl-agent [%s, %" PRId64 "]: ", __safe_name ((info)->name), (info)->id); \
rdoutput (args);
#define rdaprintf(args...) \
rdexec { \
rdaprefix (args); \
......@@ -167,11 +163,6 @@ static volatile bool java_is_9_or_above;
rdatprefix (info, args); \
}
#define rdatiprintf(info, args...) \
rdexec { \
rdatiprefix (info, args); \
}
// ****************************************************************************
// CLASS FILE LOAD
......@@ -381,48 +372,6 @@ __force_classes (
}
}
static jlong
__thread_id (JNIEnv * jni) {
assert (jni != NULL && jvm_is_started);
static jclass thread_class;
if (thread_class == NULL) {
jclass thread_class_local = (* jni)->FindClass (jni, "java/lang/Thread");
if (thread_class_local == NULL) {
return -1;
}
thread_class = (jclass) (* jni)->NewGlobalRef (jni, thread_class_local);
if (thread_class == NULL) {
return -1;
}
}
//
static jmethodID m_currentThread;
if (m_currentThread == NULL) {
m_currentThread = (* jni)->GetStaticMethodID (jni, thread_class, "currentThread", "()Ljava/lang/Thread;");
if (m_currentThread == NULL) {
return -1;
}
}
jobject thread = (* jni)->CallStaticObjectMethod (jni, thread_class, m_currentThread);
//
static jmethodID m_getId;
if (m_getId == NULL) {
m_getId = (* jni)->GetMethodID (jni, thread_class, "getId", "()J");
if (m_getId == NULL) {
return -1;
}
}
return (thread != NULL) ? (* jni)->CallLongMethod (jni, thread, m_getId) : -1;
}
static char *
__thread_name (jvmtiEnv * jvmti, JNIEnv * jni) {
......@@ -446,11 +395,10 @@ __thread_name (jvmtiEnv * jvmti, JNIEnv * jni) {
struct thread_info {
jlong id;
char * name;
};
#define INIT_THREAD_INFO { .id = -1, .name = NULL }
#define INIT_THREAD_INFO { .name = NULL }
static void
......@@ -458,10 +406,6 @@ __thread_info_init (jvmtiEnv * jvmti, JNIEnv * jni, struct thread_info * info) {
if (jvmti != NULL && jvm_is_initialized) {
info->name = __thread_name (jvmti, jni);
}
if (jni != NULL && jvm_is_started) {
info->id = __thread_id (jni);
}
}
......@@ -486,7 +430,7 @@ jvmti_callback_class_file_load (
rdexec {
__thread_info_init (jvmti, jni, &info);
rdatiprefix (
rdatprefix (
&info, "processing %s (%ld bytes)\n",
__safe (class_name), (long) class_byte_count
);
......@@ -496,7 +440,7 @@ jvmti_callback_class_file_load (
// Avoid instrumenting the bypass check class.
//
if (class_name != NULL && strcmp (class_name, BPC_CLASS_NAME) == 0) {
rdatiprintf (&info, "ignored %s (bypass check class)\n", class_name);
rdatprintf (&info, "ignored %s (bypass check class)\n", class_name);
goto __release_thread_info;
}
......@@ -507,10 +451,10 @@ jvmti_callback_class_file_load (
//
if (agent_config.force_superclass || agent_config.force_interfaces) {
if (jni != NULL) {
rdatiprintf (&info, "forcing lookup of dependent classes for %s\n", __safe (class_name));
rdatprintf (&info, "forcing lookup of dependent classes for %s\n", __safe (class_name));
__force_classes (jni, class_name, class_bytes, class_byte_count);
} else {
rdatiprintf (&info, "VM still primordial, skipping lookup of dependent classes for %s\n", __safe (class_name));
rdatprintf (&info, "VM still primordial, skipping lookup of dependent classes for %s\n", __safe (class_name));
}
}
......@@ -562,12 +506,12 @@ jvmti_callback_class_file_load (
*new_class_byte_count = class_def.class_byte_count;
*new_class_bytes = jvm_class_bytes;
rdatiprintf (
rdatprintf (
&info, "redefined %s (%ld bytes)\n",
__safe (class_name), (long) class_def.class_byte_count
);
} else {
rdatiprintf (&info, "loaded %s (unmodified)\n", __safe (class_name));
rdatprintf (&info, "loaded %s (unmodified)\n", __safe (class_name));
}
__release_thread_info:
......@@ -592,7 +536,7 @@ jvmti_callback_vm_init (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
struct thread_info info = INIT_THREAD_INFO;
rdexec {
__thread_info_init (jvmti, jni, &info);
rdatiprefix (&info, "vm_init (the VM has been initialized)\n");
rdatprefix (&info, "vm_init (the VM has been initialized)\n");
}
//
......@@ -602,10 +546,10 @@ jvmti_callback_vm_init (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
//
jvmtiClassDefinition * bpc_classdef;
if (agent_config.bypass_mode == BYPASS_MODE_DYNAMIC) {
rdatiprintf (&info, "redefining BypassCheck for dynamic bypass\n");
rdatprintf (&info, "redefining BypassCheck for dynamic bypass\n");
bpc_classdef = &dynamic_BypassCheck_classdef;
} else {
rdatiprintf (&info, "redefining BypassCheck to disable bypass\n");
rdatprintf (&info, "redefining BypassCheck to disable bypass\n");
bpc_classdef = &never_BypassCheck_classdef;
}
......@@ -614,6 +558,7 @@ jvmti_callback_vm_init (jvmtiEnv * jvmti, JNIEnv * jni, jthread thread) {
}
rdexec {
rdatprefix (&info, "vm_init complete\n");
__thread_info_done (jvmti, &info);
}
}
......@@ -645,7 +590,7 @@ jvmti_callback_vm_death (jvmtiEnv * jvmti, JNIEnv * jni) {
rdexec {
struct thread_info info = INIT_THREAD_INFO;
__thread_info_init (jvmti, jni, &info);
rdatiprefix (&info, "vm_death (the VM is shutting down)\n");
rdatprefix (&info, "vm_death (the VM is shutting down)\n");
__thread_info_done (jvmti, &info);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment