.NET compiler limitation for addition?
My co-worker and i just found that there seems to be a limitation on the number of parameters that can be used in vb.net code.
What's strange to me is that this code will build but when i run it, it throws an InvalidProgramException saying that the "JIT Compiler encountered an internal limitation".
Has anyone seen anything like this before? Can you point me to why this is happening?
(i'm using .net 4.0 with VS 2010. We found this in VS 2008 and it had a slightly different result.)
Sample code:
Dim bigVariable As Double = 10.35
Dim factor As Double = 1.3
Dim hugeNumberOfArgs As Double = (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVari开发者_StackOverflow中文版able * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) +
(bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor) + (bigVariable * factor)
Console.WriteLine("Result: " & hugeNumberOfArgs)
Console.ReadKey()
After further investigation I don't believe this is a compiler issue. The code crashes in Debug and works fine in Retail. I've diff'd the IL a few times and can't come across a discernable difference.
Also this bug repros in C# as well. If you're trying to repro this yourself make sure you pass /debug+ to the command line compiler.
This appears to be a bug in the JIT compilation. One way to prevent the crash in debug mode is to add the following line of code
<Assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations)>
Once this is added the code will execute successfully. This and reproing in both languages strongly suggests that it's a bug in the JIT process.
精彩评论