The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Weird runtime errors and the just in time compiler

There is an old compiler writer’s motto that says: Making a wrong program worse is no sin. There is another motto that says: A bug free program doesn’t exist.
Well it seems the Microsoft .NET runtime JIT team has combined the two motto’s allowing perfectly good code to go wrong :-( And I have recently been bitten multiple times by this.
 
So what happens? Well I have code that runs perfectly well from within Visual Studio 2005, both debug and release build that is. Now I run the release build as a standalone application on the same machine and it starts failing in strange ways. The sort of error you might get is invalid casts, I had one that claimed it couldn’t cast to System.__Canon. Now I have no idea what System.__Canon is used for but I am very sure I don’t use it in my code as it is an internal class in mscorelib.
 
Another runtime error I had was a System.EntryPointNotFoundException. Again exactly the same release build works fine from within Visual Studio 2005. Recently Bill McCarthy reported a similar problem with the String.IsNullOrEmpty() method, see http://msmvps.com/blogs/bill/archive/2006/04/04/89234.aspx for more details or http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=113102 for the bug report. Note that the status of this bug is fixed but will only be released in a future build :-(
 
So how do I work around these issues?
Well so far the only way I have found is to disable the JIT inlining for specific functions, usually a little higher up in the call stack, normally found by trial and error. Use the MethodImpl(MethodImplOptions.NoInlining) attribute on the function to disable the JIT.
 
So where does this leave me? Well with a certain distrust of the .NET runtime. Clearly I can’t trust the results after testing either in Visual Studio itself or a debug build. Now I am a fan of creating unit tests but being forced to run these outside the normal development environment and only on release builds is a major PITA. Not only does this waste a lot of time the very fact that it is needed makes me a little wary of releasing code to customers. After all I never know if some obscure JIT bug like this is going to be machine dependent and only bite me on the customer’s machine.
 
 
Maurice de Beijer
Published Tue, Jun 27 2006 14:38 by Maurice
Filed under:

Comments

# Weird runtime errors and the just in time compiler part 2@ Wednesday, June 28, 2006 9:08 AM

Yesterday I blogged about some if the weird runtime errors we had been experiencing. Well some colaberatiosn...

# re: Weird runtime errors and the just in time compiler@ Wednesday, July 05, 2006 12:58 AM

I tried dropping you an email (and I posted to one of your posts regarding this that seems abandoned now). I would like to go through this code a bit to actually figure out where and more importantly why things are failing (i.e. get in with windbg etc).

Bill's issue is a bit different than this one but if the JIT is emitting bad calls (or stomping on a method table) that could be very bad.

Cheers,

Greg

gxrxexgxoxrxyxyxoxuxnxgx1@gmail.com
remove x's :)

# re: Weird runtime errors and the just in time compiler@ Friday, May 30, 2008 1:21 AM

28jzgtmcyw [URL=www.876276.com/310768.html] lq0k89pk [/URL] aky0ptdzaj

# re: Weird runtime errors and the just in time compiler@ Monday, July 14, 2008 4:00 AM

when i play games sometimes the microsoft visual studio just in time compiler pops up and asks whether to debug the application or not.Sometimes this happens with my web browser and sometimes with softwares as well.

help me how to disable jit .

by Ranjith