You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2008/03/04 11:27:05 UTC

svn commit: r633414 [2/2] - in /harmony/enhanced/drlvm/trunk: make/vm/ vm/include/open/ vm/port/include/ vm/port/src/thread/linux/ vm/port/src/thread/win/ vm/thread/src/ vm/thread/src/linux/ vm/thread/src/win/ vm/vmcore/include/ vm/vmcore/src/jvmti/ vm...

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c Tue Mar  4 02:26:56 2008
@@ -174,352 +174,3 @@
     return (UDATA)stack_size;
 }
 
-typedef struct os_thread_info_t os_thread_info_t;
-
-struct os_thread_info_t
-{
-    osthread_t              thread;
-    int                     suspend_count;
-    os_thread_context_t     context;
-
-    os_thread_info_t*       next;
-};
-
-
-static CRITICAL_SECTION g_crit_section;
-static os_thread_info_t* g_suspended_list = NULL;
-
-/* Forward declarations */
-static int suspend_init_lock();
-static os_thread_info_t* init_susres_list_item();
-static os_thread_info_t* suspend_add_thread(osthread_t thread);
-static void suspend_remove_thread(osthread_t thread);
-static os_thread_info_t* suspend_find_thread(osthread_t thread);
-
-
-/**
- * Terminates the os thread.
- */
-int os_thread_cancel(osthread_t os_thread)
-{
-    os_thread_info_t* pinfo;
-    int status = TM_ERROR_NONE;
-
-    if (!suspend_init_lock())
-        return TM_ERROR_INTERNAL;
-
-    pinfo = suspend_find_thread(os_thread);
-
-    if (pinfo)
-        suspend_remove_thread(os_thread);
-
-    if (!TerminateThread(os_thread, 0))
-        status = (int)GetLastError();
-
-    LeaveCriticalSection(&g_crit_section);
-    return status;
-}
-
-/**
- * Causes the other thread to have a memory barrier by suspending
- * and resuming it.
- */
-void os_thread_yield_other(osthread_t os_thread)
-{
-    os_thread_info_t* pinfo;
-
-    /*
-     * Synchronization is needed to avoid cyclic (mutual) suspension problem.
-     * Accordingly to MSDN, it is possible on multiprocessor box that
-     * 2 threads suspend each other and become deadlocked.
-     */
-    if (!suspend_init_lock()) // Initializes and enters a critical section
-        return;
-
-    pinfo = suspend_find_thread(os_thread);
-
-    if (pinfo && pinfo->suspend_count > 0) {
-        LeaveCriticalSection(&g_crit_section);
-        return;
-    }
-
-    if (SuspendThread(os_thread) != -1) {
-        /* suspended successfully, so resume it back. */
-        ResumeThread(os_thread);
-    }
-
-    LeaveCriticalSection(&g_crit_section);
-}
-
-
-/**
- * Suspend given thread
- * @param thread The thread to suspend
- */
-int os_thread_suspend(osthread_t thread)
-{
-    os_thread_info_t* pinfo;
-    DWORD old_count;
-
-    if (!thread)
-        return TM_ERROR_NULL_POINTER;
-
-    if (!suspend_init_lock())
-        return TM_ERROR_INTERNAL;
-
-    pinfo = suspend_find_thread(thread);
-
-    if (!pinfo)
-        pinfo = suspend_add_thread(thread);
-
-    if (!pinfo)
-    {
-        LeaveCriticalSection(&g_crit_section);
-        return TM_ERROR_OUT_OF_MEMORY;
-    }
-
-    if (pinfo->suspend_count > 0)
-    {
-        ++pinfo->suspend_count;
-        LeaveCriticalSection(&g_crit_section);
-        return TM_ERROR_NONE;
-    }
-
-    old_count = SuspendThread(thread);
-
-    if (old_count == (DWORD)-1)
-    {
-        int status = (int)GetLastError();
-        LeaveCriticalSection(&g_crit_section);
-        return status;
-    }
-
-    ++pinfo->suspend_count;
-    LeaveCriticalSection(&g_crit_section);
-    return TM_ERROR_NONE;
-}
-
-/**
- * Resume given thread
- * @param thread The thread to resume
- */
-int os_thread_resume(osthread_t thread)
-{
-    os_thread_info_t* pinfo;
-    DWORD old_count;
-
-    if (!thread)
-        return TM_ERROR_NULL_POINTER;
-
-    if (!suspend_init_lock())
-        return TM_ERROR_INTERNAL;
-
-    pinfo = suspend_find_thread(thread);
-
-    if (!pinfo)
-    {
-        LeaveCriticalSection(&g_crit_section);
-        return TM_ERROR_UNATTACHED_THREAD;
-    }
-
-    if (pinfo->suspend_count > 1)
-    {
-        --pinfo->suspend_count;
-        LeaveCriticalSection(&g_crit_section);
-        return TM_ERROR_NONE;
-    }
-
-    old_count = ResumeThread(thread);
-
-    if (old_count == (DWORD)-1)
-    {
-        int status = (int)GetLastError();
-        LeaveCriticalSection(&g_crit_section);
-        return status;
-    }
-
-    if (--pinfo->suspend_count == 0)
-        suspend_remove_thread(thread);
-
-    LeaveCriticalSection(&g_crit_section);
-    return TM_ERROR_NONE;
-}
-
-/**
- * Determine suspend count for the given thread
- * @param thread The thread to check
- * @return -1 if error have occured
- */
-int os_thread_get_suspend_count(osthread_t thread)
-{
-    os_thread_info_t* pinfo;
-    int suspend_count;
-
-    if (!thread)
-        return -1;
-
-    if (!suspend_init_lock())
-        return -1;
-
-    pinfo = suspend_find_thread(thread);
-    suspend_count = pinfo ? pinfo->suspend_count : 0;
-
-    LeaveCriticalSection(&g_crit_section);
-    return suspend_count;
-}
-
-/**
- * Get context for given thread
- * @param thread The thread to process
- * @param context Pointer to platform-dependant context structure
- * @note The thread must be suspended
- */
-int os_thread_get_context(osthread_t thread, os_thread_context_t *context)
-{
-    os_thread_info_t* pinfo;
-    CONTEXT local_context;
-
-    if (!thread || !context)
-        return TM_ERROR_NULL_POINTER;
-
-    if (!suspend_init_lock())
-        return TM_ERROR_INTERNAL;
-
-    pinfo = suspend_find_thread(thread);
-
-    if (!pinfo)
-    {
-        LeaveCriticalSection(&g_crit_section);
-        return TM_ERROR_UNATTACHED_THREAD;
-    }
-
-#ifdef CONTEXT_ALL
-    local_context.ContextFlags = CONTEXT_ALL;
-#else
-    local_context.ContextFlags = CONTEXT_FULL;
-#endif
-
-    if (!GetThreadContext(thread, &local_context))
-    {
-        int status = (int)GetLastError();
-        LeaveCriticalSection(&g_crit_section);
-        return status;
-    }
-
-    pinfo->context = local_context;
-    *context = local_context;
-    LeaveCriticalSection(&g_crit_section);
-    return TM_ERROR_NONE;
-}
-
-/**
- * Set context for given thread
- * @param thread The thread to process
- * @param context Pointer to platform-dependant context structure
- * @note The thread must be suspended
- */
-int os_thread_set_context(osthread_t thread, os_thread_context_t *context)
-{
-    os_thread_info_t* pinfo;
-
-    if (!thread || !context)
-        return -1;
-
-    if (!suspend_init_lock())
-        return -2;
-
-    pinfo = suspend_find_thread(thread);
-
-    if (!pinfo)
-    {
-        LeaveCriticalSection(&g_crit_section);
-        return TM_ERROR_UNATTACHED_THREAD;
-    }
-
-    if (!SetThreadContext(thread, context))
-    {
-        int status = (int)GetLastError();
-        LeaveCriticalSection(&g_crit_section);
-        return status;
-    }
-
-    pinfo->context = *context;
-    LeaveCriticalSection(&g_crit_section);
-    return TM_ERROR_NONE;
-}
-
-
-static int suspend_init_lock()
-{
-    static uint32 initialized = 0;
-
-    if (!initialized)
-    {
-        // Critical section should be initialized only once,
-        // do nothing in case someone else already initialized it.
-        if (apr_atomic_cas32((volatile uint32*)&initialized, 1, 0) == 0)
-            InitializeCriticalSectionAndSpinCount(&g_crit_section, 400);
-    }
-
-    EnterCriticalSection(&g_crit_section);
-    return 1;
-}
-
-static os_thread_info_t* init_susres_list_item()
-{
-    os_thread_info_t* pinfo =
-        (os_thread_info_t*)malloc(sizeof(os_thread_info_t));
-
-    if (pinfo)
-        pinfo->suspend_count = 0;
-
-    return pinfo;
-}
-
-static os_thread_info_t* suspend_add_thread(osthread_t thread)
-{
-    os_thread_info_t* pinfo = init_susres_list_item();
-
-    if (!pinfo)
-        return NULL;
-
-    pinfo->thread = thread;
-    pinfo->next = g_suspended_list;
-    g_suspended_list = pinfo;
-
-    return pinfo;
-}
-
-static void suspend_remove_thread(osthread_t thread)
-{
-    os_thread_info_t** pprev = &g_suspended_list;
-    os_thread_info_t* pinfo;
-
-    for (pinfo = g_suspended_list; pinfo; pinfo = pinfo->next)
-    {
-        if (pinfo->thread == thread)
-            break;
-
-        pprev = &pinfo->next;
-    }
-
-    if (pinfo)
-    {
-        *pprev = pinfo->next;
-        free(pinfo);
-    }
-}
-
-static os_thread_info_t* suspend_find_thread(osthread_t thread)
-{
-    os_thread_info_t* pinfo;
-
-    for (pinfo = g_suspended_list; pinfo; pinfo = pinfo->next)
-    {
-        if (pinfo->thread == thread)
-            break;
-    }
-
-    return pinfo;
-}
-

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_jit.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_jit.h?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_jit.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_jit.h Tue Mar  4 02:26:56 2008
@@ -93,8 +93,4 @@
 
 Class_Handle exn_get_class_cast_exception_type();
 
-// Exception catch callback for jvm ti support implementation
-extern "C" void asm_exception_catch_callback();
-extern "C" void asm_jvmti_exception_catch_callback();
-
 #endif // _EXCEPTIONS_JIT_H_

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_break_intf.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_break_intf.h?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_break_intf.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_break_intf.h Tue Mar  4 02:26:56 2008
@@ -146,7 +146,7 @@
     VMBreakPoint* get_next_breakpoint(VMBreakPoint* prev);
 
     // General callback functions
-    void  process_native_breakpoint();
+    void  process_native_breakpoint(Registers* regs);
     jbyte process_interpreter_breakpoint(jmethodID method, jlocation location);
 
     // Find thread-local breakpoint information
@@ -186,8 +186,6 @@
 
     // Basic operations
 
-    // 'data' must be allocated with JVMTI Allocate (or internal _allocate)
-    // Users must not deallocate 'data', it will be deallocated by 'remove'
     VMBreakPointRef* add_reference(jmethodID method, jlocation location, POINTER_SIZE_INT data);
     // To specify address explicitly
     VMBreakPointRef* add_reference(jmethodID method, jlocation location,
@@ -231,7 +229,7 @@
 };
 
 // Address of this function is used for stack unwinding througn breakpoint
-extern "C" void __cdecl process_native_breakpoint_event();
+extern "C" void __cdecl process_native_breakpoint_event(Registers* regs);
 
 // Callback function for native breakpoint processing
 bool jvmti_jit_breakpoint_handler(Registers *regs);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h Tue Mar  4 02:26:56 2008
@@ -79,7 +79,7 @@
 jint jthread_allocate_vm_thread_pool(JavaVM * java_vm, vm_thread_t vm_thread);
 void jthread_deallocate_vm_thread_pool(vm_thread_t vm_thread);
 vm_thread_t jthread_allocate_thread();
-void vm_set_jvmti_saved_exception_registers(vm_thread_t vm_thread, Registers & regs);
+void vm_set_jvmti_saved_exception_registers(vm_thread_t vm_thread, Registers* regs);
 void vm_set_exception_registers(vm_thread_t vm_thread, Registers & regs);
 void *vm_get_ip_from_regs(vm_thread_t vm_thread);
 void vm_reset_ip_from_regs(vm_thread_t vm_thread);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp Tue Mar  4 02:26:56 2008
@@ -593,20 +593,18 @@
 }
 
 void
-VMBreakPoints::process_native_breakpoint()
+VMBreakPoints::process_native_breakpoint(Registers* regs)
 {
 #if (defined _IA32_) || (defined _EM64T_)
     // When we get here we know already that breakpoint occurred in JITted code,
     // JVMTI handles it, and registers context is saved for us in TLS
     VM_thread *vm_thread = p_TLS_vmthread;
     lock();
-    Registers regs = 
-        *(Registers*)vm_thread->jvmti_thread.jvmti_saved_exception_registers;
-    NativeCodePtr addr = (NativeCodePtr)regs.get_ip();
+    NativeCodePtr addr = (NativeCodePtr)regs->get_ip();
 
     TRACE2("jvmti.break", "Native breakpoint occured: " << addr);
 
-    M2nFrame* m2nf = m2n_push_suspended_frame(&regs);
+    M2nFrame* m2nf = m2n_push_suspended_frame(regs);
 
     VMBreakPoint* bp = find_breakpoint(addr);
     if (NULL == bp) {
@@ -618,7 +616,7 @@
         // instrumented, it means that another breakpoint has been set
         // there right after unlock was done.
         m2n_set_last_frame(m2n_get_previous_frame(m2nf));
-        transfer_to_regs(&regs);
+        return;
     }
     assert(bp->addr == addr);
     TRACE2("jvmti.break", "Process native breakpoint: "
@@ -629,6 +627,9 @@
         << (bp->method ? method_get_descriptor((Method*)bp->method) : "")
         << " :" << bp->location << " :" << bp->addr);
 
+    // Save registers in TLS - mainly for single stepping in virtual methods
+    vm_set_jvmti_saved_exception_registers(vm_thread, regs);
+
     jbyte *instruction_buffer;
     BEGIN_RAISE_AREA;
 
@@ -672,7 +673,7 @@
                 {
                     local.intf = intf->m_next;
                     VMBreakPoint local_bp = *bp;
-                    local_bp.regs = regs;
+                    local_bp.regs = *regs;
                     local.local_bp = &local_bp;
                     // Set local copy's pointer to local copy of disassembler
                     local_bp.disasm = &idisasm;
@@ -724,10 +725,6 @@
         }
     }
 
-    // Registers in TLS can be changed in user callbacks
-    // It should be restored to keep original address of instrumented instruction
-    // Exception/signal handlers use it when HWE occurs in instruction buffer
-    vm_set_jvmti_saved_exception_registers(vm_thread, regs);
     unlock();
 
     // Now we need to return back to normal code execution, it is
@@ -807,7 +804,7 @@
     }
     case InstructionDisassembler::INDIRECT_JUMP:
     {
-        char *jump_target = (char *)idisasm.get_target_address_from_context(&regs);
+        char *jump_target = (char *)idisasm.get_target_address_from_context(regs);
 
         // Create JMP to the absolute address which conditional jump
         // had in the execution buffer
@@ -817,7 +814,7 @@
     case InstructionDisassembler::INDIRECT_CALL:
     {
         jbyte *next_instruction = interrupted_instruction + instruction_length;
-        char *jump_target = (char *)idisasm.get_target_address_from_context(&regs);
+        char *jump_target = (char *)idisasm.get_target_address_from_context(regs);
         char *code = (char *)instruction_buffer;
 
         // Push "return address" to the $next_instruction
@@ -836,8 +833,8 @@
     // execute the original instruction with the registers which it
     // had before breakpoint happened
     m2n_set_last_frame(m2n_get_previous_frame(m2nf));
-    regs.set_ip(instruction_buffer);
-    transfer_to_regs(&regs);
+    regs->set_ip(instruction_buffer);
+    return; // We'll go to updated regs
 #else
     // PLATFORM dependent code
     abort();
@@ -1349,41 +1346,16 @@
 //////////////////////////////////////////////////////////////////////////////
 
 
-void __cdecl process_native_breakpoint_event()
+void __cdecl process_native_breakpoint_event(Registers* regs)
 {
     DebugUtilsTI *ti = VM_Global_State::loader_env->TI;
-    ti->vm_brpt->process_native_breakpoint();
+    ti->vm_brpt->process_native_breakpoint(regs);
 }
 
-#if defined (_WIN32)
-#if defined(_EM64T_)
-extern "C" void asm_process_native_breakpoint_event();
-#else
-static void __declspec(naked)
-asm_process_native_breakpoint_event()
-{
-    __asm {
-    push    ebp
-    mov     ebp,esp
-    pushfd
-    cld
-    call    process_native_breakpoint_event
-    popfd
-    pop     ebp
-    ret
-    }
-}
-#endif
-#endif // _WIN32
 
 bool jvmti_jit_breakpoint_handler(Registers *regs)
 {
-#if PLATFORM_POSIX && INSTRUMENTATION_BYTE == INSTRUMENTATION_BYTE_INT3
-    // Int3 exception address points to the instruction after it
-    NativeCodePtr native_location = (NativeCodePtr)(((POINTER_SIZE_INT)regs->get_ip()) - 1);
-#else
     NativeCodePtr native_location = (NativeCodePtr)regs->get_ip();
-#endif
 
     TRACE2("jvmti.break", "BREAKPOINT occured: " << native_location);
 
@@ -1426,16 +1398,8 @@
     }
 #endif
 
-    // Store possibly corrected location
-    regs->set_ip((void*)native_location);
-    // Copy original registers to TLS
-    vm_set_jvmti_saved_exception_registers(vm_thread, *regs);
-    // Set return address for exception handler
-#if defined (PLATFORM_POSIX)
-    regs->set_ip((void*)process_native_breakpoint_event);
-#else // PLATFORM_POSIX
-    regs->set_ip((void*)asm_process_native_breakpoint_event);
-#endif //PLATFORM_POSIX
+    NativeCodePtr callback = (NativeCodePtr)process_native_breakpoint_event;
+    port_set_longjump_regs(callback, regs, 1, regs);
 
     return true;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_em64t.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_em64t.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_em64t.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_em64t.cpp Tue Mar  4 02:26:56 2008
@@ -180,7 +180,7 @@
 
 bool ncai_get_register_value(hythread_t thread, jint reg_number, void* buf_ptr)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)
@@ -199,7 +199,7 @@
 
 bool ncai_set_register_value(hythread_t thread, jint reg_number, void* buf_ptr)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)
@@ -222,7 +222,7 @@
 
 void* ncai_get_instruction_pointer(hythread_t thread)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ia32.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ia32.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ia32.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ia32.cpp Tue Mar  4 02:26:56 2008
@@ -153,7 +153,7 @@
 
 bool ncai_get_register_value(hythread_t thread, jint reg_number, void* buf_ptr)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)
@@ -172,7 +172,7 @@
 
 bool ncai_set_register_value(hythread_t thread, jint reg_number, void* buf_ptr)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)
@@ -195,7 +195,7 @@
 
 void* ncai_get_instruction_pointer(hythread_t thread)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ipf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ipf.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ipf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_ipf.cpp Tue Mar  4 02:26:56 2008
@@ -203,7 +203,7 @@
 
 bool ncai_get_register_value(hythread_t thread, jint reg_number, void* buf_ptr)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)
@@ -222,7 +222,7 @@
 
 bool ncai_set_register_value(hythread_t thread, jint reg_number, void* buf_ptr)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)
@@ -245,7 +245,7 @@
 
 void* ncai_get_instruction_pointer(hythread_t thread)
 {
-    os_thread_context_t context;
+    thread_context_t context;
     IDATA status = hythread_get_thread_context(thread, &context);
 
     if (status != TM_ERROR_NONE)

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_linux.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_linux.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_linux.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_linux.cpp Tue Mar  4 02:26:56 2008
@@ -5,9 +5,7 @@
 
 #include "open/ncai_thread.h"
 #include "ncai_internal.h"
-
-void ucontext_to_regs(Registers* regs, ucontext_t *uc);
-void regs_to_ucontext(ucontext_t *uc, Registers* regs);
+#include "port_thread.h"
 
 bool ncai_get_generic_registers(hythread_t thread, Registers* regs)
 {
@@ -20,6 +18,6 @@
     if (status != TM_ERROR_NONE)
         return false;
 
-    ucontext_to_regs(regs, &uc);
+    port_thread_context_to_regs(regs, &uc);
     return true;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_win.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_win.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_win.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/ncai/utils/ncai_utils_win.cpp Tue Mar  4 02:26:56 2008
@@ -4,11 +4,9 @@
  */
 
 #include "open/ncai_thread.h"
+#include "port_thread.h"
 #include "ncai_internal.h"
 
-void nt_to_vm_context(PCONTEXT pcontext, Registers* regs);
-void vm_to_nt_context(Registers* regs, PCONTEXT pcontext);
-
 bool ncai_get_generic_registers(hythread_t thread, Registers* regs)
 {
     if (regs == NULL)
@@ -21,6 +19,6 @@
     if (status != TM_ERROR_NONE)
         return false;
 
-    nt_to_vm_context(&context, regs);
+    port_thread_context_to_regs(regs, &context);
     return true;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp Tue Mar  4 02:26:56 2008
@@ -166,7 +166,7 @@
  * Sets resisters to JVMTI thread
  */
 void vm_set_jvmti_saved_exception_registers(vm_thread_t vm_thread,
-                                            Registers & regs)
+                                            Registers* regs)
 {
     assert(vm_thread);
     jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread;
@@ -175,7 +175,7 @@
             (Registers*)STD_MALLOC(sizeof(Registers));
         assert(jvmti_thread->jvmti_saved_exception_registers);
     }
-    *(jvmti_thread->jvmti_saved_exception_registers) = regs;
+    *(jvmti_thread->jvmti_saved_exception_registers) = *regs;
 } // vm_set_jvmti_saved_exception_registers
 
 /**

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp Tue Mar  4 02:26:56 2008
@@ -29,6 +29,7 @@
 #include "port_sysinfo.h"
 #include "platform_lowlevel.h"
 #include "exception_filter.h"
+#include "port_thread.h"
 
 #include "crash_handler.h"
 

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=633414&r1=633413&r2=633414&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 Mar  4 02:26:56 2008
@@ -42,6 +42,7 @@
 #include <pthread_np.h>
 #endif
 #include <sys/time.h>
+#include "port_thread.h"
 #include "method_lookup.h"
 
 #include "Class.h"
@@ -74,58 +75,44 @@
 
 
 extern "C" {
-static void DECL_CHANDLER c_exception_handler(Class* exn_class, bool java_code) {
+static void DECL_CHANDLER c_exception_handler(Registers* regs, Class* exn_class, bool java_code) {
     // this exception handler is executed *after* NT exception handler returned
     DebugUtilsTI* ti = VM_Global_State::loader_env->TI;
     // Create local copy for registers because registers in TLS can be changed
-    Registers regs = {0};
     VM_thread *thread = p_TLS_vmthread;
     assert(thread);
     assert(exn_class);
 
-    if (thread->regs) {
-        regs = *thread->regs;
-    }
-
-    exn_athrow_regs(&regs, exn_class, java_code, true);
+    exn_athrow_regs(regs, exn_class, java_code, true);
 }
 }
 
-static void throw_from_sigcontext(ucontext_t *uc, Class* exc_clss)
+static void throw_from_sigcontext(Registers* regs, Class* exc_clss)
 {
-    Registers regs;
-    ucontext_to_regs(&regs, uc);
-
     DebugUtilsTI* ti = VM_Global_State::loader_env->TI;
-    bool java_code = (vm_identify_eip((void *)regs.get_ip()) == VM_TYPE_JAVA);
+    bool java_code = (vm_identify_eip((void*)regs->get_ip()) == VM_TYPE_JAVA);
     VM_thread* vmthread = p_TLS_vmthread;
-    NativeCodePtr callback = (NativeCodePtr) c_exception_handler;
 
-    vm_set_exception_registers(vmthread, regs);
-    add_red_zone(&regs);
-    regs_push_param(&regs, java_code, 1/*2nd arg */);
+    vm_set_exception_registers(vmthread, *regs);
+
     assert(exc_clss);
-    regs_push_param(&regs, (POINTER_SIZE_INT)exc_clss, 0/* 1st arg */);
-    // To get proper stack alignment on x86_64
-    regs_align_stack(&regs);
-    // imitate return IP on stack
-    regs_push_return_address(&regs, NULL);
-
-    // set up the real exception handler address
-    regs.set_ip(callback);
-    regs_to_ucontext(uc, &regs);
+
+    NativeCodePtr callback = (NativeCodePtr) c_exception_handler;
+    // Set up parameters and registers
+    port_set_longjump_regs(callback, regs,
+                            3, regs, exc_clss, (POINTER_SIZE_INT)java_code);
 }
 
-static bool java_throw_from_sigcontext(ucontext_t *uc, Class* exc_clss)
+static bool java_throw_from_sigcontext(Registers* regs, Class* exc_clss)
 {
     ASSERT_NO_INTERPRETER;
-    void* ip = (void*)UC_IP(uc);
+    void* ip = regs->get_ip();
     VM_Code_Type vmct = vm_identify_eip(ip);
     if(vmct != VM_TYPE_JAVA) {
         return false;
     }
 
-    throw_from_sigcontext(uc, exc_clss);
+    throw_from_sigcontext(regs, exc_clss);
     return true;
 }
 
@@ -359,7 +346,7 @@
     vm_thread->restore_guard_page = true;
 }
 
-static bool check_stack_overflow(siginfo_t *info, ucontext_t *uc) {
+static bool check_stack_overflow(Registers* regs, void* fault_addr) {
     char* stack_addr = (char*) get_stack_addr();
     size_t stack_size = get_stack_size();
     size_t guard_stack_size = get_guard_stack_size();
@@ -371,17 +358,13 @@
     // FIXME: Workaround for main thread
     guard_page_end += guard_page_size;
 
-    char* fault_addr = (char*)(info->si_addr);
-    //char* esp_value = (char*)(uc->uc_mcontext.gregs[REG_ESP]);
-
     return((guard_page_begin <= fault_addr) && (fault_addr < guard_page_end));
 }
 
 
 
-static void stack_overflow_handler(int signum, siginfo_t* UNREF info, void* context)
+static void stack_overflow_handler(Registers* regs)
 {
-    ucontext_t *uc = (ucontext_t *)context;
     Global_Env *env = VM_Global_State::loader_env;
 
     vm_thread_t vm_thread = p_TLS_vmthread;
@@ -389,7 +372,7 @@
     vm_thread->restore_guard_page = true;
 
     if (java_throw_from_sigcontext(
-                uc, env->java_lang_StackOverflowError_Class)) {
+                regs, env->java_lang_StackOverflowError_Class)) {
         return;
     } else {
         if (is_unwindable()) {
@@ -397,7 +380,7 @@
                 tmn_suspend_disable();
             }
             throw_from_sigcontext(
-                uc, env->java_lang_StackOverflowError_Class);
+                regs, env->java_lang_StackOverflowError_Class);
         } else {
             exn_raise_by_class(env->java_lang_StackOverflowError_Class);
         }
@@ -405,91 +388,76 @@
 }
 
 
-static void null_java_reference_handler(int signum, siginfo_t* UNREF info, void* context)
+static void null_java_reference_handler(int signum, Registers* regs, void* fault_addr)
 {
-    ucontext_t *uc = (ucontext_t *)context;
     VM_thread *vm_thread = p_TLS_vmthread;
-    Registers regs;
-    ucontext_to_regs(&regs, uc);
 
     if (vm_thread && vm_thread->jvmti_thread.violation_flag)
     {
         vm_thread->jvmti_thread.violation_flag = 0;
-        regs.set_ip(vm_thread->jvmti_thread.violation_restart_address);
-        regs_to_ucontext(uc, &regs);
+        regs->set_ip(vm_thread->jvmti_thread.violation_restart_address);
         return;
     }
 
     Global_Env *env = VM_Global_State::loader_env;
 
-    TRACE2("signals", "NPE or SOE detected at " << (void*)UC_IP(uc));
+    TRACE2("signals", "NPE or SOE detected at " << regs->get_ip());
 
-    if (check_stack_overflow(info, uc)) {
-        stack_overflow_handler(signum, info, context);
+    if (check_stack_overflow(regs, fault_addr)) {
+        stack_overflow_handler(regs);
         return;
     }
 
     if (!interpreter_enabled()) {
         if (java_throw_from_sigcontext(
-                    uc, env->java_lang_NullPointerException_Class)) {
+                    regs, env->java_lang_NullPointerException_Class)) {
             return;
         }
     }
 
-    general_crash_handler(signum, &regs);
+    general_crash_handler(signum, regs);
 }
 
 
-static void null_java_divide_by_zero_handler(int signum, siginfo_t* UNREF info, void* context)
+static void null_java_divide_by_zero_handler(int signum, Registers* regs, void* UNREF fault_addr)
 {
-    ucontext_t *uc = (ucontext_t *)context;
     Global_Env *env = VM_Global_State::loader_env;
 
     TRACE2("signals",
-           "ArithmeticException detected at " << (void*)UC_IP(uc));
+           "ArithmeticException detected at " << regs->get_ip());
 
     if (!interpreter_enabled()) {
         if (java_throw_from_sigcontext(
-                    uc, env->java_lang_ArithmeticException_Class)) {
+                    regs, env->java_lang_ArithmeticException_Class)) {
             return;
         }
     }
 
-    Registers regs;
-    ucontext_to_regs(&regs, uc);
-    general_crash_handler(signum, &regs);
+    general_crash_handler(signum, regs);
 }
 
-static void jvmti_jit_breakpoint_handler(int signum, siginfo_t* UNREF info, void* context)
+static void jvmti_jit_breakpoint_handler(int signum, Registers* regs, void* UNREF fault_addr)
 {
-    ucontext_t *uc = (ucontext_t*)context;
-    Registers regs;
-
-    ucontext_to_regs(&regs, uc);
-    TRACE2("signals", "JVMTI breakpoint detected at " << (void*)regs.get_ip());
+    TRACE2("signals", "JVMTI breakpoint detected at " << (void*)regs->get_ip());
 
     if (!interpreter_enabled())
     {
-        bool handled = jvmti_jit_breakpoint_handler(&regs);
+        regs->set_ip((void*)((POINTER_SIZE_INT)regs->get_ip() - 1));
+        bool handled = jvmti_jit_breakpoint_handler(regs);
         if (handled)
-        {
-            regs_to_ucontext(uc, &regs);
             return;
-        }
     }
 
-    general_crash_handler(signum, &regs);
+    general_crash_handler(signum, regs);
 }
 
 /**
  * Print out the call stack of the aborted thread.
  * @note call stacks may be used for debugging
  */
-static void abort_handler (int signum, siginfo_t* UNREF info, void* context)
+static void abort_handler(int signum, Registers* regs, void* UNREF fault_addr)
 {
-    Registers regs;
-    ucontext_to_regs(&regs, (ucontext_t *)context);
-    general_crash_handler(signum, &regs);
+    general_crash_handler(signum, regs);
 }
 
 static void process_crash(Registers* regs)
@@ -535,7 +503,8 @@
     if (!is_gdb_crash_handler_enabled() ||
         !gdb_crash_handler(regs))
     {
-        process_crash(regs);
+        NativeCodePtr callback = (NativeCodePtr)process_crash;
+        port_set_longjump_regs(callback, regs, 1, regs);
     }
 }
 
@@ -543,12 +512,13 @@
 {
     bool replaced = false;
     ucontext_t* uc = (ucontext_t *)context;
+    void* fault_addr = info->si_addr;
     VM_thread* vm_thread = p_TLS_vmthread;
     bool violation =
         (signum == SIGSEGV) && vm_thread && vm_thread->jvmti_thread.violation_flag;
 
     Registers regs;
-    ucontext_to_regs(&regs, uc);
+    port_thread_context_to_regs(&regs, uc);
     void* saved_ip = regs.get_ip();
     void* new_ip = saved_ip;
     bool in_java = false;
@@ -570,7 +540,7 @@
             replaced = true;
             new_ip = vm_get_ip_from_regs(vm_thread);
             regs.set_ip(new_ip);
-            regs_to_ucontext(uc, &regs);
+            port_thread_regs_to_context(uc, &regs);
         }
 
         in_java = (vm_identify_eip(regs.get_ip()) == VM_TYPE_JAVA);
@@ -589,25 +559,25 @@
         (!in_java && signum != SIGSEGV)) &&
         signum != SIGTRAP && signum != SIGINT && signum != SIGQUIT)
     {
-        general_crash_handler(signum, &regs);
         regs.set_ip(saved_ip);
-        regs_to_ucontext(uc, &regs);
+        general_crash_handler(signum, &regs);
+        port_thread_regs_to_context(uc, &regs);
         return;
     }
 
     switch (signum)
     {
     case SIGTRAP:
-        jvmti_jit_breakpoint_handler(signum, info, context);
+        jvmti_jit_breakpoint_handler(signum, &regs, fault_addr);
         break;
     case SIGSEGV:
-        null_java_reference_handler(signum, info, context);
+        null_java_reference_handler(signum, &regs, fault_addr);
         break;
     case SIGFPE:
-        null_java_divide_by_zero_handler(signum, info, context);
+        null_java_divide_by_zero_handler(signum, &regs, fault_addr);
         break;
     case SIGABRT:
-        abort_handler(signum, info, context);
+        abort_handler(signum, &regs, fault_addr);
         break;
     case SIGINT:
         vm_interrupt_handler(signum);
@@ -621,15 +591,13 @@
         break;
     }
 
-    ucontext_to_regs(&regs, 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)
-    {
         regs.set_ip((void*)saved_ip);
-        regs_to_ucontext(uc, &regs);
-    }
+
+    // Update OS context
+    port_thread_regs_to_context(uc, &regs);
 }
 
 void initialize_signals()

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/platform_lowlevel.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/platform_lowlevel.h?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/platform_lowlevel.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/platform_lowlevel.h Tue Mar  4 02:26:56 2008
@@ -50,25 +50,6 @@
 #define _MAX_PATH PATH_MAX
 
 
-#if defined(LINUX)
-
-#include <sys/types.h>
-#include <linux/unistd.h>
-#include <errno.h>
-
-#ifdef _syscall0
-pid_t gettid(void);
-#else // _syscall0
-#include <sys/syscall.h>
-#include <unistd.h>
-#define gettid() ((pid_t)syscall(__NR_gettid))
-#endif
-
-#else // !LINUX
-#define gettid() getpid()
-#endif
-
-
 #ifdef __cplusplus
 }
 #endif

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h Tue Mar  4 02:26:56 2008
@@ -29,23 +29,6 @@
 #ifdef _EM64T_
 // vvvvvvvv EM64T vvvvvvvv
 
-// Prototype: POINTER_SIZE_INT& UC_IP(ucontext_t* uc)
-#define UC_IP(uc) (uc->uc_mcontext.gregs[REG_RIP])
-
-inline void add_red_zone(Registers* pregs) {pregs->rsp -= 0x80;}
-
-void regs_push_param(Registers* pregs, POINTER_SIZE_INT param, int UNREF num);
-
-inline void regs_push_return_address(Registers* pregs, void* ret_addr) {
-    pregs->rsp = pregs->rsp - 8;
-    *((void**)pregs->rsp) = ret_addr;
-}
-
-inline void regs_align_stack(Registers* pregs) {
-    pregs->rsp = pregs->rsp - 8;
-    *((void**)pregs->rsp) = 0;
-}
-
 inline size_t get_mem_protect_stack_size() { return 0x0400; }
 
 inline size_t get_restore_stack_size() {
@@ -58,27 +41,6 @@
 #else // #ifdef _EM64T_
 // vvvvvvvv IA-32 vvvvvvvv
 
-#if defined(LINUX)
-// Prototype: POINTER_SIZE_INT& UC_IP(ucontext_t* uc)
-#define UC_IP(uc) (uc->uc_mcontext.gregs[REG_EIP])
-#elif defined(FREEBSD)
-#define UC_IP(uc) (uc->uc_mcontext.mc_eip)
-#endif
-
-inline void add_red_zone(Registers* pregs) {}
-
-inline void regs_push_param(Registers* pregs, POINTER_SIZE_INT param, int UNREF num) {
-    pregs->esp = pregs->esp - 4;
-    *((uint32*)pregs->esp) = param;
-}
-
-inline void regs_push_return_address(Registers* pregs, void* ret_addr) {
-    pregs->esp = pregs->esp - 4;
-    *((void**)pregs->esp) = ret_addr;
-}
-
-inline void regs_align_stack(Registers* pregs) {}
-
 inline size_t get_mem_protect_stack_size() { return 0x0100; }
 
 inline size_t get_restore_stack_size() {
@@ -99,11 +61,6 @@
 #define STACK_MMAP_ATTRS \
     (MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN)
 #endif
-
-
-
-void ucontext_to_regs(Registers* regs, ucontext_t *uc);
-void regs_to_ucontext(ucontext_t *uc, Registers* regs);
 
 
 #endif // _SIGNALS_COMMON_H_

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/os_wrapper.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/os_wrapper.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/os_wrapper.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/os_wrapper.cpp Tue Mar  4 02:26:56 2008
@@ -50,9 +50,3 @@
 -- which uses SIGUSR1, SIGUSR2 (which conflicts with the java app debugger and vm)
 #endif
 #endif
-
-#ifdef LINUX
-#ifdef _syscall0
-_syscall0(pid_t, gettid)
-#endif
-#endif

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp Tue Mar  4 02:26:56 2008
@@ -75,33 +75,6 @@
 
 #include <semaphore.h>
 
-void ucontext_to_regs(Registers* regs, ucontext_t* uc)
-{
-    memcpy(regs->gr, uc->uc_mcontext.sc_gr, sizeof(regs->gr));
-    memcpy(regs->fp, uc->uc_mcontext.sc_fr, sizeof(regs->fp));
-    memcpy(regs->br, uc->uc_mcontext.sc_br, sizeof(regs->br));
-
-    regs->preds = uc->uc_mcontext.sc_pr;
-    regs->nats  = uc->uc_mcontext.sc_ar_rnat;
-    regs->pfs   = uc->uc_mcontext.sc_ar_pfs;
-    regs->bsp   = (uint64*)uc->uc_mcontext.sc_ar_bsp;
-    regs->ip    = uc->uc_mcontext.sc_ip;
-}
-
-void regs_to_ucontext(ucontext_t* uc, Registers* regs)
-{
-    memcpy(uc->uc_mcontext.sc_gr, regs->gr, sizeof(regs->gr));
-    memcpy(uc->uc_mcontext.sc_fr, regs->fp, sizeof(regs->fp));
-    memcpy(uc->uc_mcontext.sc_br, regs->br, sizeof(regs->br));
-
-    uc->uc_mcontext.sc_pr      = regs->preds;
-    uc->uc_mcontext.sc_ar_rnat = regs->nats;
-    uc->uc_mcontext.sc_ar_pfs  = regs->pfs;
-    uc->uc_mcontext.sc_ar_bsp  = (uint64)regs->bsp;
-    uc->uc_mcontext.sc_ip      = regs->ip;
-}
-
-
 void asm_exception_catch_callback() {
     // FIXME: not implemented
     fprintf(stderr, "FIXME: asm_jvmti_exception_catch_callback: not implemented\n");
@@ -129,7 +102,7 @@
     fprintf(stderr, "SIGABRT in VM code.\n");
     Registers regs;
     ucontext_t *uc = (ucontext_t *)context;
-    ucontext_to_regs(&regs, uc);
+    port_thread_context_to_regs(&regs, uc);
     
     // setup default handler
     signal(signum, SIG_DFL);
@@ -169,7 +142,7 @@
 
     fprintf(stderr, "SIGFPE in VM code.\n");
     Registers regs;
-    ucontext_to_regs(&regs, uc);
+    port_thread_context_to_regs(&regs, uc);
 
     // setup default handler
     signal(signum, SIG_DFL);
@@ -435,7 +408,7 @@
     ucontext_t *uc = (ucontext_t *)context;
     Global_Env *env = VM_Global_State::loader_env;
     Registers regs;
-    ucontext_to_regs(&regs, uc);
+    port_thread_context_to_regs(&regs, uc);
 
     if (!p_TLS_vmthread)
     {

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp Tue Mar  4 02:26:56 2008
@@ -27,6 +27,7 @@
 #include "native_stack.h"
 #include "port_filepath.h"
 #include "port_dso.h"
+#include "port_thread.h"
 #include "stack_dump.h"
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp Tue Mar  4 02:26:56 2008
@@ -82,11 +82,15 @@
     return (native_find_stub(ip) != NULL);
 }
 
+/*
+Now the technique for calling C handler from a signal/exception context
+guarantees that all needed return addresses are present in stack, so
+there is no need in special processing
 static bool native_is_ip_in_breakpoint_handler(void* ip)
 {
     return (ip >= &process_native_breakpoint_event &&
             ip < &jvmti_jit_breakpoint_handler);
-}
+}*/
 /// Helper functions
 //////////////////////////////////////////////////////////////////////////////
 
@@ -311,13 +315,16 @@
 
             VMBreakPoints* vm_breaks = VM_Global_State::loader_env->TI->vm_brpt;
             vm_breaks->lock();
-
+/*
+Now the technique for calling C handler from a signal/exception context
+guarantees that all needed return addresses are present in stack, so
+there is no need in special processing
             if (native_is_ip_in_breakpoint_handler(tmp_regs.get_ip()))
             {
                 regs = *pthread->jvmti_thread.jvmti_saved_exception_registers;
                 flag_breakpoint = true;
             }
-            else
+            else*/
                 regs = tmp_regs;
 
             vm_breaks->unlock();
@@ -433,10 +440,13 @@
 
         VMBreakPoints* vm_breaks = VM_Global_State::loader_env->TI->vm_brpt;
         vm_breaks->lock();
-
+/*
+Now the technique for calling C handler from a signal/exception context
+guarantees that all needed return addresses are present in stack, so
+there is no need in special processing
         if (native_is_ip_in_breakpoint_handler(tmp_regs.get_ip()))
             regs = *pthread->jvmti_thread.jvmti_saved_exception_registers;
-        else
+        else*/
             regs = tmp_regs;
 
         vm_breaks->unlock();

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/exception_handlers.asm
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/exception_handlers.asm?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/exception_handlers.asm (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/exception_handlers.asm Tue Mar  4 02:26:56 2008
@@ -1,12 +1,6 @@
 PUBLIC  vectored_exception_handler
 EXTRN   vectored_exception_handler_internal:PROC
 
-PUBLIC  asm_c_exception_handler
-EXTRN   c_exception_handler:PROC
-
-PUBLIC  asm_process_native_breakpoint_event
-EXTRN   process_native_breakpoint_event:PROC
-
 _TEXT   SEGMENT
 
 vectored_exception_handler PROC
@@ -27,56 +21,6 @@
     ret
 
 vectored_exception_handler ENDP
-
-
-asm_c_exception_handler PROC
-
-; void __cdecl asm_c_exception_handler(Class *exn_class, bool in_java)
-; void __cdecl c_exception_handler(Class* exn_class, bool in_java)
-; Args:
-;   rcx - nt_exception
-;   rdx - in_java (actually in dl)
-;   r8  - none
-;   r9  - none
-
-    pushfq
-    cld
-    push    rax
-    push    rbx
-    push    rcx
-    push    rdx
-    push    r8
-    push    r9
-    push    r10
-    push    r11
-    sub     rsp, 32 ; allocate stack for 4 registers
-    call    c_exception_handler
-    add     rsp, 32
-    pop     r11
-    pop     r10
-    pop     r9
-    pop     r8
-    pop     rdx
-    pop     rcx
-    pop     rbx
-    pop     rax
-    popfq
-    ret
-
-asm_c_exception_handler ENDP
-
-asm_process_native_breakpoint_event PROC
-
-    pushfq
-    cld
-    sub     rsp, 32 ; allocate stack for 4 registers
-    call    process_native_breakpoint_event
-    add     rsp, 32
-    popfq
-    ret
-
-asm_process_native_breakpoint_event ENDP
-
 
 _TEXT   ENDS
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp Tue Mar  4 02:26:56 2008
@@ -15,41 +15,11 @@
  *  limitations under the License.
  */
 
-#include <stdio.h>
 #include "platform_lowlevel.h"
-#include "vm_core_types.h"
 #include "exceptions_jit.h"
 #include "exception_filter.h"
 
 
-void nt_to_vm_context(PCONTEXT context, Registers* regs)
-{
-    regs->eax = context->Eax;
-    regs->ecx = context->Ecx;
-    regs->edx = context->Edx;
-    regs->edi = context->Edi;
-    regs->esi = context->Esi;
-    regs->ebx = context->Ebx;
-    regs->ebp = context->Ebp;
-    regs->eip = context->Eip;
-    regs->esp = context->Esp;
-    regs->eflags = context->EFlags;
-}
-
-void vm_to_nt_context(Registers* regs, PCONTEXT context)
-{
-    context->Esp = regs->esp;
-    context->Eip = regs->eip;
-    context->Ebp = regs->ebp;
-    context->Ebx = regs->ebx;
-    context->Esi = regs->esi;
-    context->Edi = regs->edi;
-    context->Eax = regs->eax;
-    context->Ecx = regs->ecx;
-    context->Edx = regs->edx;
-    context->EFlags = regs->eflags;
-}
-
 LONG __declspec(naked) NTAPI vectored_exception_handler(LPEXCEPTION_POINTERS nt_exception)
 {
     __asm {
@@ -64,40 +34,4 @@
     pop     ebp
     ret     4
     }
-}
-
-void __declspec(naked) asm_c_exception_handler(Class *exn_class, bool in_java)
-{
-    __asm {
-    push    ebp
-    mov     ebp,esp
-    pushfd
-    cld
-    mov     eax, [ebp + 12]
-    push    eax
-    mov     eax, [ebp + 8]
-    push    eax
-    call    c_exception_handler
-    add     esp, 8
-    popfd
-    pop     ebp
-    ret
-    }
-}
-
-void* regs_get_sp(Registers* pregs)
-{
-    return (void*)pregs->esp;
-}
-
-void regs_push_param(Registers* pregs, POINTER_SIZE_INT param, int UNREF num)
-{
-    pregs->esp = pregs->esp - 4;
-    *((uint32*)pregs->esp) = param;
-}
-
-void regs_push_return_address(Registers* pregs, void* ret_addr)
-{
-    pregs->esp = pregs->esp - 4;
-    *((void**)pregs->esp) = ret_addr;
 }

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=633414&r1=633413&r2=633414&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 Mar  4 02:26:56 2008
@@ -27,6 +27,7 @@
 #include "jvmti_break_intf.h"
 #include "m2n.h"
 #include "open/hythread_ext.h"
+#include "port_thread.h"
 
 // Windows specific
 #include <string>
@@ -334,6 +335,7 @@
     return get_restore_stack_size() < available_stack_size;
 }
 
+
 LONG NTAPI vectored_exception_handler_internal(LPEXCEPTION_POINTERS nt_exception)
 {
     DWORD code = nt_exception->ExceptionRecord->ExceptionCode;
@@ -343,7 +345,7 @@
     VM_thread* vmthread = p_TLS_vmthread;
 
     // Convert NT context to Registers
-    nt_to_vm_context(context, &regs);
+    port_thread_context_to_regs(&regs, context);
     POINTER_SIZE_INT saved_eip = (POINTER_SIZE_INT)regs.get_ip();
 
     bool in_java = false;
@@ -361,7 +363,7 @@
         {
             flag_replaced = true;
             regs.set_ip(vm_get_ip_from_regs(vmthread));
-            vm_to_nt_context(&regs, context);
+            port_thread_regs_to_context(context, &regs);
         }
 
         in_java = (vm_identify_eip(regs.get_ip()) == VM_TYPE_JAVA);
@@ -399,12 +401,12 @@
     {
         LONG result = process_crash(&regs, nt_exception, code);
         regs.set_ip((void*)saved_eip);
-        vm_to_nt_context(&regs, context);
+        port_thread_regs_to_context(context, &regs);
         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)));
+        nt_exception->ExceptionRecord->ExceptionCode, regs.get_ip(), regs.get_sp()));
 
     // if HWE occured in java code, suspension should also have been disabled
     bool ncai_enabled = GlobalNCAI::isEnabled();
@@ -421,7 +423,7 @@
         {
             TRACE2("signals",
                 ("StackOverflowError detected at ip = %p, esp = %p",
-                 regs.get_ip(), regs_get_sp(&regs)));
+                 regs.get_ip(), regs.get_sp()));
 
             vmthread->restore_guard_page = true;
             exn_class = env->java_lang_StackOverflowError_Class;
@@ -440,7 +442,7 @@
                 // Mark raised exception in TLS and resume execution
                 exn_raise_by_class(env->java_lang_StackOverflowError_Class);
                 regs.set_ip((void*)saved_eip);
-                vm_to_nt_context(&regs, context);
+                port_thread_regs_to_context(context, &regs);
                 return EXCEPTION_CONTINUE_EXECUTION;
             }
         }
@@ -471,7 +473,7 @@
             bool handled = jvmti_jit_breakpoint_handler(&regs);
             if (handled)
             {
-                vm_to_nt_context(&regs, context);
+                port_thread_regs_to_context(context, &regs);
                 return EXCEPTION_CONTINUE_EXECUTION;
             }
             else
@@ -481,7 +483,7 @@
         // unexpected hardware exception occured in java code
         LONG result = process_crash(&regs, nt_exception, code);
         regs.set_ip((void*)saved_eip);
-        vm_to_nt_context(&regs, context);
+        port_thread_regs_to_context(context, &regs);
         return result;
     }
 
@@ -497,40 +499,30 @@
     // into thread-local registers snapshot
     vm_set_exception_registers(vmthread, regs);
 
-    // __cdecl <=> push parameters in the reversed order
-    // push in_java argument onto stack
-    regs_push_param(&regs, in_java, 1/*2nd arg */);
-    // push the exn_class argument onto stack
     assert(exn_class);
-    regs_push_param(&regs, (POINTER_SIZE_INT)exn_class, 0/* 1st arg */);
-    // imitate return IP on stack
-    regs_push_return_address(&regs, NULL);
-
-    // set up the real exception handler address
-    regs.set_ip(asm_c_exception_handler);
+    // Set up parameters and registers for C handler
+    port_set_longjump_regs(c_exception_handler, &regs,
+                            3, &regs, exn_class, (POINTER_SIZE_INT)in_java);
     // Store changes into NT context
-    vm_to_nt_context(&regs, context);
+    port_thread_regs_to_context(context, &regs);
 
     // exit NT exception handler and transfer
     // control to VM exception handler
     return EXCEPTION_CONTINUE_EXECUTION;
 }
 
-void __cdecl c_exception_handler(Class* exn_class, bool in_java)
+void __cdecl c_exception_handler(Registers* regs, Class* exn_class, bool in_java)
 {
     // this exception handler is executed *after* NT exception handler returned
     DebugUtilsTI* ti = VM_Global_State::loader_env->TI;
     // Create local copy for registers because registers in TLS can be changed
-    Registers regs = {0};
     VM_thread *thread = p_TLS_vmthread;
     assert(thread);
-    if (thread->regs) {
-        regs = *(Registers*)thread->regs;
-    }
+    assert(exn_class);
 
     TRACE2("signals", ("should throw exception %p at IP=%p, SP=%p",
-                exn_class, regs.get_ip(), regs_get_sp(&regs)));
-    exn_athrow_regs(&regs, exn_class, in_java, true);
+                exn_class, regs->get_ip(), regs->get_sp()));
+    exn_athrow_regs(regs, exn_class, in_java, true);
 
     assert(!"si_transfer_control should not return");
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h?rev=633414&r1=633413&r2=633414&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h Tue Mar  4 02:26:56 2008
@@ -36,17 +36,12 @@
 LONG NTAPI vectored_exception_handler_internal(LPEXCEPTION_POINTERS nt_exception);
 
 // Function to throw exception
-void __cdecl c_exception_handler(Class* exn_class, bool in_java);
-// Assembler wrapper for c_exception_handler; is used to clear direction flag
-void asm_c_exception_handler(Class *exn_class, bool in_java);
+void __cdecl c_exception_handler(Registers* regs, Class* exn_class, bool in_java);
 
 // exception catch callback to restore stack after Stack Overflow Error
 void __cdecl exception_catch_callback_wrapper();
 // exception catch support for JVMTI
- void __cdecl jvmti_exception_catch_callback_wrapper();
-// Assembler wrappers; are used to restore registers
-//void asm_exception_catch_callback(); // Declared in exceptions_jit.h
-//void asm_jvmti_exception_catch_callback(); // Declared in exceptions_jit.h
+void __cdecl jvmti_exception_catch_callback_wrapper();
 
 #ifdef __cplusplus
 } // extern "C"
@@ -55,15 +50,6 @@
 
 // Prints register state
 void print_reg_state(Registers* regs);
-
-// Conversion from NT context to VM Registers structure and visa versa
-void nt_to_vm_context(PCONTEXT context, Registers* regs);
-void vm_to_nt_context(Registers* regs, PCONTEXT context);
-
-// Fuctions to manipulate with Registers structure
-void* regs_get_sp(Registers* pregs);
-void regs_push_param(Registers* pregs, POINTER_SIZE_INT param, int num);
-void regs_push_return_address(Registers* pregs, void* ret_addr);
 
 
 #endif // nt_exception_filter_h