Bug 7848 - Unexpected AOT limitiation JIT
Summary: Unexpected AOT limitiation JIT
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: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-10-15 12:35 UTC by Jochen Hansmeyer
Modified: 2012-10-19 12:11 UTC (History)
3 users (show)

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


Attachments
Testcase (1.86 MB, application/x-tar)
2012-10-16 04:57 UTC, Jochen Hansmeyer
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 Jochen Hansmeyer 2012-10-15 12:35:59 UTC
I get an exception:

System.ExecutionEngineException: Attempting to JIT compile method 'Accord.Math.Tools:Hypotenuse (double,double)' while running with --aot-only.

Accord.Math.Tools:Hypotenuse is called from an unsafe method:

        public unsafe SingularValueDecompositionF(Single[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) {

}



Please see method definition below:


       /// <summary>
        ///   Hypotenuse calculus without overflow/underflow
        /// </summary>
        /// 
        /// <param name="a">first value</param>
        /// <param name="b">second value</param>
        /// <returns>The hypotenuse Sqrt(a^2 + b^2)</returns>
        /// 
        public static double Hypotenuse(double a, double b)
        {
            double r = 0.0;
            double absA = System.Math.Abs(a);
            double absB = System.Math.Abs(b);

            if (absA > absB)
            {
                r = b / a;
                r = absA * System.Math.Sqrt(1 + r * r);
            }
            else if (b != 0)
            {
                r = a / b;
                r = absB * System.Math.Sqrt(1 + r * r);
            }

            return r;
        }

        /// <summary>
        ///   Hypotenuse calculus without overflow/underflow
        /// </summary>
        /// 
        /// <param name="a">first value</param>
        /// <param name="b">second value</param>
        /// <returns>The hypotenuse Sqrt(a^2 + b^2)</returns>
        /// 
        public static decimal Hypotenuse(decimal a, decimal b)
        {
            decimal r = 0;
            decimal absA = System.Math.Abs(a);
            decimal absB = System.Math.Abs(b);

            if (absA > absB)
            {
                r = b / a;
                r = absA * (decimal)System.Math.Sqrt((double)(1 + r * r));
            }
            else if (b != 0)
            {
                r = a / b;
                r = absB * (decimal)System.Math.Sqrt((double)(1 + r * r));
            }

            return r;
        }

        /// <summary>
        ///   Hypotenuse calculus without overflow/underflow
        /// </summary>
        /// 
        /// <param name="a">first value</param>
        /// <param name="b">second value</param>
        /// <returns>The hypotenuse Sqrt(a^2 + b^2)</returns>
        /// 
        public static float Hypotenuse(float a, float b)
        {
            double r = 0;
            float absA = System.Math.Abs(a);
            float absB = System.Math.Abs(b);

            if (absA > absB)
            {
                r = b / a;
                r = absA * System.Math.Sqrt(1 + r * r);
            }
            else if (b != 0)
            {
                r = a / b;
                r = absB * System.Math.Sqrt(1 + r * r);
            }

            return (float)r;
        }
Comment 1 Zoltan Varga 2012-10-15 13:44:54 UTC
Could you attach a test project ?
Comment 2 Jochen Hansmeyer 2012-10-16 04:57:49 UTC
Created attachment 2751 [details]
Testcase

This will fail on a device in SingularValueDecomposition line 293. The commented block below is the equivalent code of the function and works.
Comment 3 Zoltan Varga 2012-10-16 06:20:05 UTC
This looks like an mcs problem in 2.10.9, master seems to work fine.
Testcase:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System;

class Driver {
       public T[,] Concatenate<T>(this T[,] a, T[,] b)
        {
            return Concatenate(new[] { a, b });
        }

        public T[,] Concatenate<T>(params T[][,] matrices)
        {
			return new T[0,0];
		}

    static void Main () {
    }
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Compile it using smcs bug.cs, the run monodis on it:
	IL_000f:  call Missing method Driver::Concatenate<[1]>(!!0[2][]) in assembly /Users/vargaz/git/mono/mono/mini/bug.exe, referenced in assembly /Users/vargaz/git/mono/mono/mini/bug.exe
Missing method Driver::Concatenate<[1]>(!!0[2][]) in assembly /Users/vargaz/git/mono/mono/mini/bug.exe, referenced in assembly /Users/vargaz/git/mono/mono/mini/bug.exe
* Assertion at get.c:2097, condition `mh' not met
Comment 4 Zoltan Varga 2012-10-16 06:20:45 UTC
Marek, could you look at this ?
Comment 5 Marek Safar 2012-10-16 07:13:22 UTC
This looks to me like runtime bug.

Master mcs does not use SRE, so the array is encoded slightly differently than 2.10. You can compile it with 2.10 gmcs/dmcs to get same crash but same exe runs and peverifies on .NET.

Looking at the difference Mono runtime seems to have issue with !!T[,] format but works fine with !!T[0...,0...] format of multi-dimensional array.
Comment 6 Zoltan Varga 2012-10-19 12:11:30 UTC
Fixed in master/2.10/mobile-master/ios6.