Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 12070 invoked from network); 5 Feb 2008 15:11:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Feb 2008 15:11:25 -0000 Received: (qmail 90694 invoked by uid 500); 5 Feb 2008 15:11:17 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 90599 invoked by uid 500); 5 Feb 2008 15:11:17 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 90590 invoked by uid 99); 5 Feb 2008 15:11:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2008 07:11:17 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2008 15:10:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8C4801A9832; Tue, 5 Feb 2008 07:11:04 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r618668 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src: stack/stack_dump.cpp util/linux/ia32_em64t/signals_common.cpp util/win/ia32_em64t/nt_exception_filter_common.cpp Date: Tue, 05 Feb 2008 15:11:02 -0000 To: commits@harmony.apache.org From: gshimansky@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080205151104.8C4801A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gshimansky Date: Tue Feb 5 07:11:01 2008 New Revision: 618668 URL: http://svn.apache.org/viewvc?rev=618668&view=rev Log: Applied patch from HARMONY-5452 [drlvm][signals] Signal handler and crash handler crash themselves for pure native threads Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp?rev=618668&r1=618667&r2=618668&view=diff ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp Tue Feb 5 07:11:01 2008 @@ -403,7 +403,7 @@ jthread java_thread = jthread_get_java_thread(thread); JNIEnv* jni_env = vm_thread->jni_env; - if (java_thread) + if (cur_thread && java_thread) { jclass cl = GetObjectClass(jni_env, java_thread); jmethodID id = jni_env->GetMethodID(cl, "getName","()Ljava/lang/String;"); @@ -431,9 +431,15 @@ void sd_print_stack(Registers* regs) { hymutex_t* sd_lock; + int disable_count; + bool unwindable; + + VM_thread* thread = get_thread_ptr(); // Can be NULL for pure native thread // Enable suspend to allow working with threads - int disable_count = hythread_reset_suspend_disable(); + if (thread) + disable_count = hythread_reset_suspend_disable(); + // Acquire global lock to print threads list and stop other crashed threads hythread_global_lock(); @@ -441,7 +447,8 @@ return; hymutex_lock(sd_lock); - bool unwindable = set_unwindable(false); // To call Java code + if (thread) + unwindable = set_unwindable(false); // To call Java code // Print register info print_reg_state(regs); @@ -455,7 +462,6 @@ // Print the whole list of modules sd_print_modules(); - VM_thread* thread = get_thread_ptr(); // Can be NULL for pure native thread native_frame_t* frames = NULL; // Print threads info @@ -489,11 +495,13 @@ fprintf(stderr, "\n"); fflush(stderr); - set_unwindable(unwindable); + if (thread) + set_unwindable(unwindable); // Do not unlock to prevent other threads from printing crash stack //hymutex_unlock(sd_lock); hythread_global_unlock(); - hythread_set_suspend_disable(disable_count); + if (thread) + hythread_set_suspend_disable(disable_count); } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp?rev=618668&r1=618667&r2=618668&view=diff ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp Tue Feb 5 07:11:01 2008 @@ -70,7 +70,7 @@ #include "signals_common.h" -static void general_crash_handler(int signum, Registers* regs, const char* message); +static void general_crash_handler(int signum, Registers* regs); extern "C" { @@ -436,7 +436,7 @@ } } - general_crash_handler(signum, ®s, "SIGSEGV"); + general_crash_handler(signum, ®s); } @@ -457,7 +457,7 @@ Registers regs; ucontext_to_regs(®s, uc); - general_crash_handler(signum, ®s, "SIGFPE"); + general_crash_handler(signum, ®s); } static void jvmti_jit_breakpoint_handler(int signum, siginfo_t* UNREF info, void* context) @@ -478,7 +478,7 @@ } } - general_crash_handler(signum, ®s, "SIGTRAP"); + general_crash_handler(signum, ®s); } /** @@ -489,7 +489,7 @@ { Registers regs; ucontext_to_regs(®s, (ucontext_t *)context); - general_crash_handler(signum, ®s, "SIGABRT"); + general_crash_handler(signum, ®s); } static void process_crash(Registers* regs) @@ -498,12 +498,39 @@ sd_print_stack(regs); } -static void general_crash_handler(int signum, Registers* regs, const char* message) +struct sig_name_t +{ + int num; + char* name; +}; + +static sig_name_t sig_names[] = +{ + {SIGTRAP, "SIGTRAP"}, + {SIGSEGV, "SIGSEGV"}, + {SIGFPE, "SIGFPE" }, + {SIGABRT, "SIGABRT"}, + {SIGINT, "SIGINT" }, + {SIGQUIT, "SIGQUIT"} +}; + +static const char* get_sig_name(int signum) +{ + for (int i = 0; i < sizeof(sig_names)/sizeof(sig_names[0]); i++) + { + if (signum == sig_names[i].num) + return sig_names[i].name; + } + + return "unregistered"; +} + +static void general_crash_handler(int signum, Registers* regs) { // setup default handler signal(signum, SIG_DFL); // Print message - fprintf(stderr, "Signal is reported: %s\n", message); + fprintf(stderr, "Signal %d is reported: %s\n", signum, get_sig_name(signum)); if (!is_gdb_crash_handler_enabled() || !gdb_crash_handler(regs)) @@ -516,37 +543,58 @@ { bool replaced = false; ucontext_t* uc = (ucontext_t *)context; - POINTER_SIZE_INT saved_eip = (POINTER_SIZE_INT)UC_IP(uc); - POINTER_SIZE_INT new_eip = saved_eip; VM_thread* vm_thread = p_TLS_vmthread; bool violation = (signum == SIGSEGV) && vm_thread && vm_thread->jvmti_thread.violation_flag; - // If exception is occured in processor instruction previously - // instrumented by breakpoint, the actual exception address will reside - // in jvmti_jit_breakpoints_handling_buffer - // We should replace exception address with saved address of instruction - POINTER_SIZE_INT break_buf = - (POINTER_SIZE_INT)vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer; - if (saved_eip >= break_buf && - saved_eip < break_buf + TM_JVMTI_MAX_BUFFER_SIZE) + Registers regs; + ucontext_to_regs(®s, uc); + void* saved_ip = regs.get_ip(); + void* new_ip = saved_ip; + bool in_java = false; + + if (vm_thread) { - // Breakpoints should not occur in breakpoint buffer - assert(signum != SIGTRAP); + // If exception is occured in processor instruction previously + // instrumented by breakpoint, the actual exception address will reside + // in jvmti_jit_breakpoints_handling_buffer + // We should replace exception address with saved address of instruction + POINTER_SIZE_INT break_buf = + (POINTER_SIZE_INT)vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer; + if ((POINTER_SIZE_INT)saved_ip >= break_buf && + (POINTER_SIZE_INT)saved_ip < break_buf + TM_JVMTI_MAX_BUFFER_SIZE) + { + // Breakpoints should not occur in breakpoint buffer + assert(signum != SIGTRAP); + + replaced = true; + new_ip = vm_get_ip_from_regs(vm_thread); + regs.set_ip(new_ip); + regs_to_ucontext(uc, ®s); + } - replaced = true; - new_eip = (POINTER_SIZE_INT)vm_get_ip_from_regs(vm_thread); - UC_IP(uc) = new_eip; + in_java = (vm_identify_eip(regs.get_ip()) == VM_TYPE_JAVA); } // Pass exception to NCAI exception handler bool is_handled = 0; bool is_internal = (signum == SIGTRAP) || violation; - ncai_process_signal_event((NativeCodePtr)UC_IP(uc), + ncai_process_signal_event((NativeCodePtr)regs.get_ip(), (jint)signum, is_internal, &is_handled); if (is_handled) return; + // delegate evident cases to crash handler + if ((!vm_thread || + (!in_java && signum != SIGSEGV)) && + signum != SIGTRAP && signum != SIGINT && signum != SIGQUIT) + { + general_crash_handler(signum, ®s); + regs.set_ip(saved_ip); + regs_to_ucontext(uc, ®s); + return; + } + switch (signum) { case SIGTRAP: @@ -573,12 +621,14 @@ break; } - // If EIP was not changed in specific handler to start another handler, - // we should restore original EIP, if it's nesessary - if (replaced && - UC_IP(uc) == new_eip) + ucontext_to_regs(®s, uc); + + // If IP was not changed in specific handler to start another handler, + // we should restore original IP, if it's nesessary + if (replaced && regs.get_ip() == new_ip) { - UC_IP(uc) = saved_eip; + regs.set_ip((void*)saved_ip); + regs_to_ucontext(uc, ®s); } } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp?rev=618668&r1=618667&r2=618668&view=diff ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp Tue Feb 5 07:11:01 2008 @@ -281,7 +281,7 @@ bool in_java = false; - if (vmthread && (&vmthread->jvmti_thread)) + if (vmthread) { // If exception is occured in processor instruction previously // instrumented by breakpoint, the actual exception address will reside