dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc_call.c...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog engine/jitc.c engine/jitc_call.c...
Date: Sun, 25 Jun 2006 11:56:32 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      06/06/25 11:56:32

Modified files:
        .              : ChangeLog 
        engine         : jitc.c jitc_call.c jitc_except.c thread.c 

Log message:
        2006-06-25  Klaus Treichel  <address@hidden>
        
                * engine/jitc.c: Add the handling of the managed safepoint 
flags. Add a
                function to rethrow an existing exception. Add Functions to 
emit the code
                to be executed before and after a native call is made.
        
                * engine/jitc_call.c: Call the new functions in jitc.c before 
and after
                the native calls for inlined calls.
        
                * engine/jitc_except.c: Add support to handle the 
ThreadAbortException and
                propagating it (rethrow the exception automatically after it 
was handled in
                a catch block). Add support for the rethrow instruction.
                
                * engine/thread.c: Move the code to register the libjit 
exceptionhandler
                from ILThreadRegisterForManagedExecution to 
_ILThreadSetExecContext so
                that the handler is set correctly for finalizers too.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3328&r2=1.3329
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc.c?cvsroot=dotgnu-pnet&r1=1.40&r2=1.41
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_call.c?cvsroot=dotgnu-pnet&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc_except.c?cvsroot=dotgnu-pnet&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/thread.c?cvsroot=dotgnu-pnet&r1=1.41&r2=1.42

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3328
retrieving revision 1.3329
diff -u -b -r1.3328 -r1.3329
--- ChangeLog   18 Jun 2006 13:09:35 -0000      1.3328
+++ ChangeLog   25 Jun 2006 11:56:31 -0000      1.3329
@@ -1,3 +1,20 @@
+2006-06-25  Klaus Treichel  <address@hidden>
+
+       * engine/jitc.c: Add the handling of the managed safepoint flags. Add a
+       function to rethrow an existing exception. Add Functions to emit the 
code
+       to be executed before and after a native call is made.
+
+       * engine/jitc_call.c: Call the new functions in jitc.c before and after
+       the native calls for inlined calls.
+
+       * engine/jitc_except.c: Add support to handle the ThreadAbortException 
and
+       propagating it (rethrow the exception automatically after it was 
handled in
+       a catch block). Add support for the rethrow instruction.
+       
+       * engine/thread.c: Move the code to register the libjit exceptionhandler
+       from ILThreadRegisterForManagedExecution to _ILThreadSetExecContext so
+       that the handler is set correctly for finalizers too.
+
 2006-06-18  Kirill Kononenko  <address@hidden>
 
        * engine/jitc.c: Add signatures for ILStringToUTF8 and ILStringCreate.

Index: engine/jitc.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/jitc.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- engine/jitc.c       18 Jun 2006 13:09:35 -0000      1.40
+++ engine/jitc.c       25 Jun 2006 11:56:32 -0000      1.41
@@ -144,6 +144,11 @@
 static ILJitType _ILJitSignature_ILJitGetExceptionStackTrace = 0;
 
 /*
+ * void ILRuntimeExceptionRethrow(ILObject *exception)
+ */
+static ILJitType _ILJitSignature_ILRuntimeExceptionRethrow = 0;
+
+/*
  * void ILRuntimeExceptionThrow(ILObject *exception)
  */
 static ILJitType _ILJitSignature_ILRuntimeExceptionThrow = 0;
@@ -221,6 +226,11 @@
 static ILJitType _ILJitSignature_ILGetClrType = 0;
 
 /*
+ * void ILRuntimeHandleManagedSafePointFlags(ILExecThread *thread)
+ */
+static ILJitType _ILJitSignature_ILRuntimeHandleManagedSafePointFlags = 0;
+
+/*
  * char *ILStringToUTF8(ILExecThread *thread, ILString *str)
  */
 static ILJitType _ILJitSignature_ILStringToUTF8 = 0;
@@ -1287,6 +1297,23 @@
 }
 
 /*
+ * Rethrow the given exception.
+ */
+void ILRuntimeExceptionRethrow(ILObject *object)
+{
+       ILExecThread *thread = ILExecThreadCurrent();
+
+       if(thread)
+       {
+               thread->thrownException = object;
+       }
+       if(object)
+       {
+               jit_exception_throw(object);
+       }
+}
+
+/*
  * Throw the given exception.
  */
 void ILRuntimeExceptionThrow(ILObject *object)
@@ -1347,6 +1374,30 @@
 }
 
 /*
+ * Handle the managed safepoint flags after a native call was made.
+ */
+void ILRuntimeHandleManagedSafePointFlags(ILExecThread *thread)
+{
+       if((thread->managedSafePointFlags & _IL_MANAGED_SAFEPOINT_THREAD_ABORT) 
&& ILThreadIsAbortRequested())
+       {
+               if(_ILExecThreadSelfAborting(thread) == 0)
+               {
+                       jit_exception_throw(thread->thrownException);
+               }
+       }
+       else if(thread->managedSafePointFlags & 
_IL_MANAGED_SAFEPOINT_THREAD_SUSPEND)
+       {
+               ILThreadAtomicStart();
+               thread->managedSafePointFlags &= 
~_IL_MANAGED_SAFEPOINT_THREAD_SUSPEND;
+               ILThreadAtomicEnd();
+               if(ILThreadGetState(thread->supportThread) & 
IL_TS_SUSPEND_REQUESTED)
+               {
+                       _ILExecThreadSuspendThread(thread, 
thread->supportThread);
+               }
+       }
+}
+
+/*
  * Handle an exception thrown in an internal call.
  */
 static void _ILJitHandleThrownException(ILJitFunction func,
@@ -1947,6 +1998,14 @@
 
        args[0] = _IL_JIT_TYPE_VPTR;
        returnType = _IL_JIT_TYPE_VOID;
+       if(!(_ILJitSignature_ILRuntimeExceptionRethrow =
+               jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType, 
args, 1, 1)))
+       {
+               return 0;
+       }
+
+       args[0] = _IL_JIT_TYPE_VPTR;
+       returnType = _IL_JIT_TYPE_VOID;
        if(!(_ILJitSignature_ILRuntimeExceptionThrow =
                jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType, 
args, 1, 1)))
        {
@@ -2050,6 +2109,14 @@
        }
 
        args[0] = _IL_JIT_TYPE_VPTR;
+       returnType = _IL_JIT_TYPE_VOID;
+       if(!(_ILJitSignature_ILRuntimeHandleManagedSafePointFlags =
+               jit_type_create_signature(IL_JIT_CALLCONV_CDECL, returnType, 
args, 1, 1)))
+       {
+               return 0;
+       }
+
+       args[0] = _IL_JIT_TYPE_VPTR;
        args[1] = _IL_JIT_TYPE_VPTR;
        returnType = _IL_JIT_TYPE_VPTR;
        if(!(_ILJitSignature_ILStringToUTF8 =
@@ -2295,6 +2362,18 @@
 }
 
 /*
+ * Get the ILClass pointer from an object reference.
+ */
+static ILJitValue _ILJitGetObjectClass(ILJitFunction func, ILJitValue object)
+{
+       ILJitValue classPrivate = _ILJitGetObjectClassPrivate(func, object);
+
+       return jit_insn_load_relative(func, classPrivate, 
+                                                                 
offsetof(ILClassPrivate, classInfo),
+                                                                 
_IL_JIT_TYPE_VPTR);
+}
+
+/*
  * Get the evaluation stack type for the given ILJitType.
  */
 static ILJitType _ILJitTypeToStackType(ILJitType type)
@@ -2334,6 +2413,48 @@
 }
 
 /*
+ * Emit the code that has to run before a native function is executed.
+ */
+static void _ILJitBeginNativeCall(ILJitFunction func, ILJitValue thread)
+{
+       ILJitValue zero = jit_value_create_nint_constant(func,
+                                                                               
                         jit_type_sys_int,
+                                                                               
                         (jit_nint)0);
+
+       jit_insn_store_relative(func, thread,
+                                                       offsetof(ILExecThread, 
runningManagedCode),
+                                                       zero);
+}
+
+/*
+ * Emit the code that has to run after a native function is executed.
+ */
+static void _ILJitEndNativeCall(ILJitFunction func, ILJitValue thread)
+{
+       ILJitValue one = jit_value_create_nint_constant(func,
+                                                                               
                         jit_type_sys_int,
+                                                                               
                         (jit_nint)1);
+       ILJitValue temp = jit_insn_load_relative(func,
+                                                                               
        thread,
+                                                                               
        offsetof(ILExecThread, managedSafePointFlags),
+                                                                               
        jit_type_sys_int);
+       jit_label_t label = jit_label_undefined;
+
+       jit_insn_store_relative(func, thread,
+                                                       offsetof(ILExecThread, 
runningManagedCode),
+                                                       one);
+       jit_insn_branch_if_not(func, temp, &label);
+       jit_insn_call_native(func,
+                                                
"ILRuntimeHandleManagedSafePointFlags",
+                                                
ILRuntimeHandleManagedSafePointFlags,
+                                                
_ILJitSignature_ILRuntimeHandleManagedSafePointFlags,
+                                                &thread, 1, 0);
+
+       jit_insn_label(func, &label);
+       _ILJitHandleThrownException(func, thread);
+}
+
+/*
  * Check if a function is implemented by an internalcall.
  * Returns 0 if the function is not implemented by an internal call,
  * 1 if the function is implemented by an internal call and the function
@@ -2475,6 +2596,7 @@
                                                                                
                  totalParams, 1);
 
                _ILJitSetMethodInThread(func, thread, method);
+               _ILJitBeginNativeCall(func, thread);
                if(!hasStructReturn)
                {
                        returnValue = jit_insn_call_native(func, methodName, 
nativeFunction,
@@ -2489,7 +2611,7 @@
                }
                jit_type_free(callSignature);
        }
-       _ILJitHandleThrownException(func, thread);
+       _ILJitEndNativeCall(func, thread);
 
        return returnValue;
 }

Index: engine/jitc_call.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/jitc_call.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- engine/jitc_call.c  10 Jun 2006 12:38:45 -0000      1.19
+++ engine/jitc_call.c  25 Jun 2006 11:56:32 -0000      1.20
@@ -1114,12 +1114,13 @@
                        /* Pop the object from the stack. */
                        JITC_ADJUST(jitCoder, -1);
 
+                       _ILJitBeginNativeCall(jitCoder->jitFunction, args[0]);
                        jit_insn_call_native(jitCoder->jitFunction,
                                                                 
"_IL_Monitor_Enter",
                                                                 
_IL_Monitor_Enter,
                                                                 
_ILJitSignature_ILMonitorEnter,
                                                                 args, 2, 0);
-                       _ILJitHandleThrownException(jitCoder->jitFunction, 
args[0]);
+                       _ILJitEndNativeCall(jitCoder->jitFunction, args[0]);
 
                        return 1;
                }
@@ -1136,12 +1137,13 @@
                        /* Pop the object from the stack. */
                        JITC_ADJUST(jitCoder, -1);
 
+                       _ILJitBeginNativeCall(jitCoder->jitFunction, args[0]);
                        jit_insn_call_native(jitCoder->jitFunction,
                                                                 
"_IL_Monitor_Exit",
                                                                 
_IL_Monitor_Exit,
                                                                 
_ILJitSignature_ILMonitorExit,
                                                                 args, 2, 0);
-                       _ILJitHandleThrownException(jitCoder->jitFunction, 
args[0]);
+                       _ILJitEndNativeCall(jitCoder->jitFunction, args[0]);
 
                        return 1;
                }
@@ -1163,12 +1165,13 @@
 
                        args[0] = _ILJitCoderGetThread(jitCoder);
                        args[1] = returnValue;
+                       _ILJitBeginNativeCall(jitCoder->jitFunction, args[0]);
                        temp = jit_insn_call_native(jitCoder->jitFunction,
                                                                                
"_ILGetClrType",
                                                                                
_ILGetClrType,
                                                                                
_ILJitSignature_ILGetClrType,
                                                                                
args, 2, 0);
-                       _ILJitHandleThrownException(jitCoder->jitFunction, 
args[0]);
+                       _ILJitEndNativeCall(jitCoder->jitFunction, args[0]);
                        jit_insn_store(jitCoder->jitFunction,
                                                   returnValue, 
                                                   temp);

Index: engine/jitc_except.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/jitc_except.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- engine/jitc_except.c        27 May 2006 12:10:51 -0000      1.7
+++ engine/jitc_except.c        25 Jun 2006 11:56:32 -0000      1.8
@@ -106,6 +106,125 @@
 }
 
 /*
+ * Check if the current exception thrown is a ThreadAblorException
+ * and save it to the threadAbortException in the current ILExecThread.
+ * 
+ * Because the ThreadAbortException is a sealed class we can simply compare the
+ * two ILClass pointers.
+ */
+static void _ILJitSetThreadAbortException(ILJITCoder *jitCoder,
+                                                                               
  ILJitValue thread,
+                                                                               
  ILJitValue exception)
+{
+       ILJitValue threadAbortException;
+       ILJitValue exceptionClass;
+       ILJitValue temp;
+       jit_label_t allreadyAbortingLabel = jit_label_undefined;
+       ILJitValue threadAbortExceptionClass = 
+               jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                          
_IL_JIT_TYPE_VPTR,
+                                                                          
(jit_nint)jitCoder->process->threadAbortClass);
+
+       /* Get the current ThreadAbortException of the thread. */
+       threadAbortException = jit_insn_load_relative(jitCoder->jitFunction,
+                                                                               
                  thread,
+                                                                               
                  offsetof(ILExecThread, threadAbortException),
+                                                                               
                  _IL_JIT_TYPE_VPTR);
+
+       /* if there is one then there is nothing else todo. */
+       jit_insn_branch_if(jitCoder->jitFunction, 
+                                          threadAbortException,
+                                          &allreadyAbortingLabel);
+
+       /* Get the class of the current exception */
+       exceptionClass = _ILJitGetObjectClass(jitCoder->jitFunction, exception);
+
+       /* Is the class not the ThreadAbortException class ? */
+       temp = jit_insn_ne(jitCoder->jitFunction,
+                                          exceptionClass,
+                                          threadAbortExceptionClass);
+
+       /* If it's not a ThreadAbortException then we are ready. */
+       jit_insn_branch_if(jitCoder->jitFunction, 
+                                          temp,
+                                          &allreadyAbortingLabel);
+
+       /* otherwise save the exception to the threadAbortException in the */
+       /* current thread. */
+       jit_insn_store_relative(jitCoder->jitFunction,
+                                                       thread,
+                                                       offsetof(ILExecThread, 
threadAbortException),
+                                                       exception);
+
+       jit_insn_label(jitCoder->jitFunction, &allreadyAbortingLabel);
+}
+
+/*
+ * Propagate the ThreadAbortException if present.
+ */
+static void _ILJitPropagateThreadAbort(ILJITCoder *jitCoder,
+                                                                          
ILException *exception)
+{
+       /* TODO: Handle the case if the thread is not in the signature.*/
+       ILJitValue thread = _ILJitCoderGetThread(jitCoder);
+       jit_label_t label = jit_label_undefined;
+       ILJitValue currentException = (ILJitValue)(exception->ptrUserData);
+       ILJitValue nullException = 
+                       jit_value_create_nint_constant(jitCoder->jitFunction,
+                                                                               
   _IL_JIT_TYPE_VPTR,
+                                                                              
(jit_nint)0);
+       ILJitValue exceptionObject;
+       ILJitValue temp;
+
+#if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
+       if (jitCoder->flags & IL_CODER_FLAG_STATS)
+       {
+               ILMutexLock(globalTraceMutex);
+               fprintf(stdout,
+                       "PropagateThreadAbortException\n");
+               ILMutexUnlock(globalTraceMutex);
+       }
+#endif
+
+       /* Check if the thread is aborting. */
+       temp = jit_insn_load_relative(jitCoder->jitFunction, thread,
+                                                                 
offsetof(ILExecThread, aborting),
+                                                                 
jit_type_sys_int);
+       jit_insn_branch_if_not(jitCoder->jitFunction,
+                                                  temp,
+                                                  &label);
+
+       /* Get the threadAbortException object. */
+       exceptionObject = jit_insn_load_relative(jitCoder->jitFunction, thread,
+                                                                               
         offsetof(ILExecThread, threadAbortException),
+                                                                               
         _IL_JIT_TYPE_VPTR);
+
+       /* Check if they are the same. */
+       temp = jit_insn_eq(jitCoder->jitFunction,
+                                          exceptionObject,
+                                          currentException);
+
+       jit_insn_branch_if_not(jitCoder->jitFunction,
+                                                  temp,
+                                                  &label);
+
+       /* Clear the ThreadAbortException. */
+       jit_insn_store_relative(jitCoder->jitFunction,
+                                                       thread,
+                                                       offsetof(ILExecThread, 
threadAbortException),
+                                                       nullException);
+
+       jit_insn_call_native(jitCoder->jitFunction,
+                                                "ILRuntimeExceptionRethrow",
+                                                ILRuntimeExceptionRethrow,
+                                                
_ILJitSignature_ILRuntimeExceptionRethrow,
+                                                &exceptionObject, 1, 
JIT_CALL_NORETURN);
+
+       jit_insn_label(jitCoder->jitFunction, &label);
+}
+
+
+/*
  * Set up exception handling for the current method.
  */
 static void JITCoder_SetupExceptions(ILCoder *_coder, ILException *exceptions,
@@ -170,6 +289,10 @@
                        _ILJitLabelGet(jitCoder, exceptions->handlerOffset,
                                                                         
_IL_JIT_LABEL_STARTCATCH);
                        jitCoder->stackTop = 0;
+
+                       /* We save the created value in the exception too for 
rethrow or */
+                       /* propagating a ThreadAbortException. */
+                       exceptions->ptrUserData = (void *)exception;
                }
                exceptions = exceptions->next;
        }
@@ -219,6 +342,7 @@
 static void JITCoder_Rethrow(ILCoder *coder, ILException *exception)
 {
        ILJITCoder *jitCoder = _ILCoderToILJITCoder(coder);
+       ILJitValue exceptionObject;
 
 #if !defined(IL_CONFIG_REDUCE_CODE) && !defined(IL_WITHOUT_TOOLS)
        if (jitCoder->flags & IL_CODER_FLAG_STATS)
@@ -229,6 +353,25 @@
                ILMutexUnlock(globalTraceMutex);
        }
 #endif
+
+       /* The rethrow instruction is allowed in a catch block. */
+       if((exception->flags & (IL_META_EXCEPTION_FILTER |
+                                                       
IL_META_EXCEPTION_FINALLY |
+                                                       
IL_META_EXCEPTION_FAULT)) == 0)
+       {
+               /* Get the current exception object. */
+               /* We saved the exception in the userData of the ILException. */
+               exceptionObject = (ILJitValue)(exception->ptrUserData);
+
+               jit_insn_call_native(jitCoder->jitFunction,
+                                                        
"ILRuntimeExceptionRethrow",
+                                                        
ILRuntimeExceptionRethrow,
+                                                        
_ILJitSignature_ILRuntimeExceptionRethrow,
+                                                        &exceptionObject, 1, 
JIT_CALL_NORETURN);
+       }
+       /* If the instruction is outside a catch handler an exception should */
+       /* be thrown. */
+       /* TODO */
 }
 
 /*
@@ -378,17 +521,11 @@
        }
 #endif
 
-       /* Get the current exception bject. */
+       /* Get the current exception object. */
        exceptionObject = jit_insn_load_relative(jitCoder->jitFunction, thread,
                                                                                
         offsetof(ILExecThread, thrownException),
                                                                                
         _IL_JIT_TYPE_VPTR);
 
-       /* Push the exception object on the stack. */
-       jitCoder->jitStack[0] = exceptionObject;
-       jitCoder->stackTop = 1;
-       catchBlock = _ILJitLabelGet(jitCoder, exception->handlerOffset,
-                                                                               
  _IL_JIT_LABEL_STARTCATCH);
-
        /* Look if the object can be casted to the cought exception type. */
        args[0] = method;
        args[1] = exceptionObject;
@@ -399,6 +536,16 @@
                                                                           
_ILJitSignature_ILRuntimeCanCastClass,
                                                                           
args, 3, JIT_CALL_NOTHROW);
        jit_insn_branch_if_not(jitCoder->jitFunction, returnValue, &label);
+
+       /* Save the exception in the threadAbortException if it is one. */
+       _ILJitSetThreadAbortException(jitCoder, thread, exceptionObject);
+
+       /* Push the exception object on the stack. */
+       jitCoder->jitStack[0] = exceptionObject;
+       jitCoder->stackTop = 1;
+       catchBlock = _ILJitLabelGet(jitCoder, exception->handlerOffset,
+                                                                               
  _IL_JIT_LABEL_STARTCATCH);
+
        jit_insn_store_relative(jitCoder->jitFunction, thread, 
                                                        offsetof(ILExecThread, 
thrownException),
                                                        nullException);
@@ -428,6 +575,12 @@
        #endif
                jit_insn_return_from_finally(jitCoder->jitFunction);
        }
+       else if((exception->flags & (IL_META_EXCEPTION_FILTER |
+                                                                
IL_META_EXCEPTION_FINALLY |
+                                                                
IL_META_EXCEPTION_FAULT)) == 0)
+       {
+               _ILJitPropagateThreadAbort(jitCoder, exception);
+       }
 }
 
 /*

Index: engine/thread.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/thread.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- engine/thread.c     12 Mar 2006 17:57:06 -0000      1.41
+++ engine/thread.c     25 Jun 2006 11:56:32 -0000      1.42
@@ -163,6 +163,12 @@
                }
        #endif
 
+#ifdef IL_USE_JIT
+       /* Set the exception handler which converts builtin
+          libjit exceptions into clr exceptions */
+       jit_exception_set_handler(_ILJitExceptionHandler);
+#endif
+
        context->execThread->supportThread = thread;
 }
 
@@ -250,12 +256,6 @@
        /* Register a cleanup handler for the thread */
        ILThreadRegisterCleanup(thread, ILExecThreadCleanup);
 
-#ifdef IL_USE_JIT
-       /* Set the exception handler which converts builtin
-          libjit exceptions into clr exceptions */
-       jit_exception_set_handler(_ILJitExceptionHandler);
-#endif
-
        return execThread;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]