Bug 6467 - CreateDelegate should not JIT method
Summary: CreateDelegate should not JIT method
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-08-08 09:07 UTC by Songtive Team
Modified: 2012-09-04 04:37 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Invalid IL code reproducible example (1.07 KB, text/plain)
2012-08-08 09:08 UTC, Songtive Team

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Songtive Team 2012-08-08 09:07:37 UTC

I was trying to port ServiceStack.Text JSON deserializer and noticed quite strange error with the deserialization of the following class:

		public class HasIndex
			public int Id { get; set; }

			public int this[int id]
				get { return Id; }
				set { Id = value; }

Windows box works as expected but Mono throws an error: 

Unhandled Exception: System.InvalidProgramException: Invalid IL code in (wrapper  dynamic-method) object:_ (object,object): IL_0000: callvirt  0x00000001. 

It was not so easy to extract the specific part of JSON serializer to reproduce it but I was able to get the same error with DynamicMethod class. Please find attached fully reproducible example - I was trying to minimize code as much as possible, so please ignore incorrect ILGenerator sets - I think the reason of that problem is the same as we have for GenericMethods in SericeStack.Text JSON serializer.

Let me know if you need more information.
Comment 1 Songtive Team 2012-08-08 09:08:40 UTC
Created attachment 2327 [details]
Invalid IL code reproducible example
Comment 2 Marek Safar 2012-08-09 04:07:58 UTC
The generated code is invalid. It fails on .NET too when you execute the delegate.

Mono compiles the code more aggressively but that's the only difference.
Comment 3 Songtive Team 2012-08-09 06:52:13 UTC
As I stated I was trying to minimize code as much as possible. Mono will fail without execution at all. The same symptom I've found with serialize and generic methods. I will try to reproduce it without DynamicMethod method. But I think the issues correlate.
Comment 4 Songtive Team 2012-08-09 07:57:11 UTC
Update: Was able to reproduce the issue under serializer. You were right - it seems Mono more aggressive for compilation and notice some issues in my code. But still I think CreateDelegate shouldn't JIT. Thanks for help!
Comment 5 Zoltan Varga 2012-08-09 10:21:05 UTC
The time when the runtime checks for errors in IL code is not specified. It could happen at first execution time, or earlier.
Comment 6 Marek Safar 2012-08-09 10:26:36 UTC
I think .NET does sensible optimization (JIT on Invoke) whereas we JIT straight away in CreateDelegate
Comment 7 Songtive Team 2012-08-09 10:37:02 UTC
Marek, exactly - my tests proven that, since I even didn't notice any issues under Microsoft .NET because that incorrect code has never been invoked so has never been JIT'ed.
Comment 8 Miguel de Icaza [MSFT] 2012-09-02 12:53:56 UTC
Is this related to JsonFx?

See this bug report:


If you find a way to fix your code Sergey, would you mind talking about it with the JsonFx guys?

At this point, I am closing the bug, since we are just stricter
Comment 9 Marek Safar 2012-09-02 12:57:53 UTC
I think it'd be useful to implement same optimisation if possible
Comment 10 Songtive Team 2012-09-04 04:37:10 UTC
Miguel, I've commented regarding that issue in #6821