Thursday, July 19, 2012

A bug of JIT

 

Long time no update my blogSmile

Recently, one of our 32bit product experiences a weird crashing problem, the callstack shows crash happens during JITting a c# function. While if starting from debugger or disable JIT optimization from the config file, it works well.

After experiments, we isolated the specific statements causing the crashing problem:

   1: fixed(Point* pPoint = ...)
   2: {
   3:     ...
   4:     pPoint[index] = GetPoint();
   5:     ...
   6: }


The GetPoint is another c# function, returning a Point instance, which is a value type.


And just JITting the above codes with optimization enabled will cause troubles. And one work-around is to rewrite with a temp variable first, then assign with the temp var.



   1: Point thePoint = GetPoint();
   2: pPoints[index] = thePoint;


Though seems to be strange, it works well.


Sorry for not providing the callstack and debugging logs, since this happened one month ago, and I could not find detailed logs.


Some other things related to this interesting bug:


First, Obfuscator will remove the [MethodImplOptions.NoOptimization] attribute after obfuscating our assemblies, maybe there are some other settings, while finding the root reason is always the best solution than work-aroundsSmile


Second, the above exception thrown from JITting will be translated to first-chance ManagedException if attached with Visual Studio 2010, while show no CLR exception from windbg, maybe the CLR exception notification which is translated from JIT will not be sent to windbg.

No comments:

Post a Comment