summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Methodical/refany/virtcall.cs
blob: e8a335e2ee6fadd18e7ddb07328ba7aa97607126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace JitTest
{
    internal class StressTest
    {
        private const int ITERATIONS = 2000;
        private const ulong MAGIC = 0x7700001492000077;

        public virtual ulong UnpackRef(TypedReference _ref, int iterCount)
        {
            if (iterCount++ == ITERATIONS)
            {
                if (__refvalue(_ref, ulong) == MAGIC)
                {
                    throw new ArgumentException();  //cleanup in an unusual way
                }
                else
                {
                    throw new Exception();
                }
            }
            else
                return __refvalue(_ref, ulong);
        }

        public virtual void PackRef(TypedReference _ref, int iterCount)
        {
            if (++iterCount == ITERATIONS)
            {
                UnpackRef(_ref, iterCount);
            }
            else
            {
                ulong N = UnpackRef(_ref, 0);
                PackRef(__makeref(N), iterCount);
            }
        }

        private static int Main()
        {
            try
            {
                ulong N = MAGIC;
                new StressTest().PackRef(__makeref(N), 0);
                return 2;
            }
            catch (ArgumentException)
            {
                return 100;
            }
            catch (Exception)
            {
                return 1;
            }
        }
    }
}