tunnelvisionlabs / antlr4cs

The original, highly-optimized C# Target for ANTLR 4
Other
445 stars 103 forks source link

iOS does not allow JIT compilation -- happens in the Sharpen utilities #36

Open quietpixel opened 10 years ago

quietpixel commented 10 years ago

I've been working to integrate antlr4cs into a Unity3D project to run on iOS. Several of the classes in the Sharpen namespace rely on Just-in-Time compilation of generic types. Apple forbids using JIT compilation as a safety concern, and more likely, because it would allow developers to go around the App Store, and cut Apple out of the revenue stream.

Since Unity uses .NET v3.5, I have to use the v3.5 target of ANTLR C# that relies on the Sharpen classes to reproduce functionality not available in that version of .NET.

I ran into 3 places where JIT occurs:

  1. ConcurrentDictionary uses the SplitOrderedList generic class.
  2. AtomicReference uses System.Threading.Interlocked, which according the the source code listed at www.dotnetframework.org uses JIT as a hack to get around a problem the developers faced.
  3. Recognizer uses the ConsoleErrorListener generic class.

To fix (1), I found a class from Lucene.Net.Support.Compatibility that replaces ConcurrentDictionary without needing JIT support.

To fix (2), I commented out the Interlocked.CompareExchange () function call, and handled the variable update manually with a spin lock around it.

I didn't spend a lot of time fixing (3), just commented out that line for now.

Would you guys be interested in rolling changes 1 and 2 into the main branch? I do not feel comfortable doing so, as I am new to this code base, and there may be unintended side affects I'm not aware of.

sharwell commented 10 years ago

At this point I'm not comfortable with the impact the suggested changes could have on the performance of the library to cover a rarely-used case. In particular, item 2 you mention above cannot be changed.

Supporting the situation you describe would require creating a new assembly specifically for Unity. However, before I incorporate this support in a release, I would need to address separate concerns regarding the installation process and MSBuild support for Unity projects.

thegoldenmule commented 6 years ago

FWIW I have the same need: running ANTLR on iOS. There is related issue (#96) that also require JIT fixes.