harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r520531 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src: jni/jni.cpp util/win/ia32_em64t/nt_exception_filter_common.cpp
Date Tue, 20 Mar 2007 19:29:46 GMT
Author: gshimansky
Date: Tue Mar 20 12:29:45 2007
New Revision: 520531

URL: http://svn.apache.org/viewvc?view=rev&rev=520531
Log:
Applied HARMONY-3428 [drlvm][winx64] HWA fails with new VEH in Interpreter/debug mode

The patch fixes bugs with exception handler crashing on windows especially with MSVC 2005
runtime which throws exceptions in very unexpected places


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.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/jni/jni.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp?view=diff&rev=520531&r1=520530&r2=520531
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp Tue Mar 20 12:29:45 2007
@@ -1463,6 +1463,7 @@
     
     // Destroy VM environment.
     delete java_vm->vm_env;
+    java_vm->vm_env = NULL;
     
     // Destroy VM pool.
     apr_pool_destroy(java_vm->pool);

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?view=diff&rev=520531&r1=520530&r2=520531
==============================================================================
--- 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 Mar 20 12:29:45 2007
@@ -52,16 +52,39 @@
 
 static LONG process_crash(LPEXCEPTION_POINTERS nt_exception, const char* msg = NULL)
 {
+static DWORD saved_eip_index = TlsAlloc();
+static BOOL UNREF tmp_init = TlsSetValue(saved_eip_index, (LPVOID)0);
+
     Registers regs;
     nt_to_vm_context(nt_exception->ContextRecord, &regs);
 
     // Check crash location to prevent infinite recursion
-    if (regs.get_ip() == p_TLS_vmthread->regs.get_ip())
+    if (regs.get_ip() == (void*)TlsGetValue(saved_eip_index))
         return EXCEPTION_CONTINUE_SEARCH;
     // Store registers to compare IP in future
-    p_TLS_vmthread->regs = regs;
+    TlsSetValue(saved_eip_index, (LPVOID)regs.get_ip());
+
+    switch (nt_exception->ExceptionRecord->ExceptionCode)
+    {
+    case EXCEPTION_DATATYPE_MISALIGNMENT:
+    case EXCEPTION_ILLEGAL_INSTRUCTION:
+    case EXCEPTION_ACCESS_VIOLATION:
+    case EXCEPTION_PRIV_INSTRUCTION:
+    case EXCEPTION_FLT_DIVIDE_BY_ZERO:
+    case EXCEPTION_FLT_OVERFLOW:
+    case EXCEPTION_FLT_UNDERFLOW:
+    case EXCEPTION_INT_DIVIDE_BY_ZERO:
+    case EXCEPTION_INT_OVERFLOW:
+        break;
+
+    case EXCEPTION_STACK_OVERFLOW:
+    default:
+        return EXCEPTION_CONTINUE_SEARCH;
+    }
 
-    if (get_boolean_property("vm.assert_dialog", TRUE, VM_PROPERTIES))
+    // We can't obtain a value of property if loader_env is NULL
+    if (VM_Global_State::loader_env == NULL ||
+        get_boolean_property("vm.assert_dialog", TRUE, VM_PROPERTIES))
         return EXCEPTION_CONTINUE_SEARCH;
 
     print_state(nt_exception, msg);
@@ -204,28 +227,32 @@
     PCONTEXT context = nt_exception->ContextRecord;
     Registers regs;
     bool flag_replaced = false;
+    VM_thread* vmthread = p_TLS_vmthread;
 
     // Convert NT context to Registers
     nt_to_vm_context(context, &regs);
     POINTER_SIZE_INT saved_eip = (POINTER_SIZE_INT)regs.get_ip();
 
-    assert(p_TLS_vmthread);
-    // 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)p_TLS_vmthread->jvmti_jit_breakpoints_handling_buffer;
-    if (saved_eip >= break_buf &&
-        saved_eip < break_buf + 50)
+    bool in_java = false;
+
+    if (vmthread)
     {
-        flag_replaced = true;
-        regs.set_ip(p_TLS_vmthread->jvmti_saved_exception_registers.get_ip());
-        vm_to_nt_context(&regs, context);
-    }
+        // 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)vmthread->jvmti_jit_breakpoints_handling_buffer;
+        if (saved_eip >= break_buf &&
+            saved_eip < break_buf + 50)
+        {
+            flag_replaced = true;
+            regs.set_ip(vmthread->jvmti_saved_exception_registers.get_ip());
+            vm_to_nt_context(&regs, context);
+        }
 
-    TRACE2("signals", ("VEH received an exception: code = %x, ip = %p, sp = %p",
-        nt_exception->ExceptionRecord->ExceptionCode, regs.get_ip(), regs_get_sp(&regs)));
+        in_java = (vm_identify_eip(regs.get_ip()) == VM_TYPE_JAVA);
+    }
 
     // the possible reasons for hardware exception are
     //  - segfault or division by zero in java code
@@ -240,10 +267,11 @@
     //  - other (internal VM error or debugger breakpoint)
     //    => delegate to default handler
 
-    bool in_java = (vm_identify_eip(regs.get_ip()) == VM_TYPE_JAVA);
-
-    // delegate "other" cases to default handler
-    if (!in_java && code != STATUS_STACK_OVERFLOW)
+    // delegate "other" cases to crash handler
+    // Crash handler shouls be invoked when VM_thread is not attached to VM
+    // or exception has occured in native code and it's not STACK_OVERFLOW
+    if (!vmthread ||
+        (!in_java && code != STATUS_STACK_OVERFLOW))
     {
         LONG result = process_crash(nt_exception);
         regs.set_ip((void*)saved_eip);
@@ -251,6 +279,9 @@
         return result;
     }
 
+    TRACE2("signals", ("VEH received an exception: code = %x, ip = %p, sp = %p",
+        nt_exception->ExceptionRecord->ExceptionCode, regs.get_ip(), regs_get_sp(&regs)));
+
     // if HWE occured in java code, suspension should also have been disabled
     assert(!in_java || !hythread_is_suspend_enabled());
 
@@ -267,7 +298,7 @@
                 ("StackOverflowError detected at ip = %p, esp = %p",
                  regs.get_ip(), regs_get_sp(&regs)));
 
-            p_TLS_vmthread->restore_guard_page = true;
+            vmthread->restore_guard_page = true;
             exn_class = env->java_lang_StackOverflowError_Class;
             if (in_java) {
                 // stack overflow occured in java code:
@@ -339,7 +370,7 @@
 
     // save register context of hardware exception site
     // into thread-local registers snapshot
-    p_TLS_vmthread->regs = regs;
+    vmthread->regs = regs;
 
     // __cdecl <=> push parameters in the reversed order
     // push in_java argument onto stack



Mime
View raw message