Bug 7385 - Randomly occurring "System.ExecutionEngineException: Attempting to JIT compile method"
Summary: Randomly occurring "System.ExecutionEngineException: Attempting to JIT compil...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2012-09-21 11:37 UTC by naerymdan2
Modified: 2012-09-25 17:30 UTC (History)
3 users (show)

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


Attachments
Sample project. Please run on device. Press Unpack button 4-5 times to see issue. (2.29 MB, application/zip)
2012-09-21 11:37 UTC, naerymdan2
Details


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 Developer Community or GitHub 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:
Status:
RESOLVED FIXED

Description naerymdan2 2012-09-21 11:37:16 UTC
Created attachment 2593 [details]
Sample project. Please run on device. Press Unpack button 4-5 times to see issue.

I am using a native static library and the function it is warning is using JIT works about 80% of the time, then suddenly, the same call that worked previously fails with that error.

The actual library is the 'minizip' subset of zlib that I compiled for iOS (AMRv6 + AMRv7 combined static lib)

It uses both managed-to-native "[DllImport ("__Internal", CallingConvention=CallingConvention.Cdecl)]" calls and native-to-managed calls (which I wrapped in [MonoPInvokeCallback (typeof (TestErrorFileFunc))])

The weirdest part is that the error is "System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) zipsharp.OpenFileFunc:wrapper_aot_native (intptr&,intptr,string,int)' while running with --aot-only.", but when I put console logging within the managed delegate it complains about, the console outputs before the error happens.

I made a sample project to easily reproduce the issue. Please run that on an actual iPhone and press the "Unpack" button multiple times. In my case, I start seeing JIT error around the 5th press of the button.

Thanks.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-09-21 21:22:47 UTC
I can reproduce the issue, but I couldn't find out what's going on.

Zoltan, can you have a look?
Comment 2 Zoltan Varga 2012-09-25 02:45:39 UTC
You have to mark the delegates used to wrap native functions, i.e. OpenFileFunc with the
MonoNativeFunctionWrapper attribute, so the AOT compiler knows about them:

[MonoNativeFunctionWrapper]
	internal delegate IntPtr OpenFileFunc (IntPtr opaque, string filename, int mode);

http://docs.xamarin.com/ios/releases/MonoTouch_5/MonoTouch_5.3
Comment 3 Zoltan Varga 2012-09-25 03:55:38 UTC
Added a more useful error message to the ExecutionEngineException in this case.
Comment 4 Zoltan Varga 2012-09-25 04:06:41 UTC
There is still a mono problem here, [MonoNativeFunctionWrapper] and [UnmanagedFunctionPointerAttribute] cannot be specified at the same time. For now, remove the
[UnmanagedFunctionPointerAttribute], its not needed on ios.
Comment 5 naerymdan2 2012-09-25 11:11:25 UTC
This call seems to be Monotouch specific and does not work with Mono for Android. This is slightly problematic as I assume native libraries would probably be called by libraries to be used on multiple platforms.

Can't the [MonoNativeFunctionWrapper] be automatically implied when using [UnmanagedFunctionPointerAttribute]?
Comment 6 Zoltan Varga 2012-09-25 17:30:57 UTC
Implemented that suggestion.