[amd64] Remove the callee saved registers from MonoLMF, save/restore them normally...
[mono-project.git] / mono / mini / devirtualization.cs
blob285eb3f49edbf98ae7ac2b47f5e451f6c2c6e3dd
1 using System;
2 using System.Reflection;
4 /*
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * static int test_<result>_<name> ();
11 * where <result> is an integer (the value that needs to be returned by
12 * the method to make it pass.
13 * <name> is a user-displayed name used to identify the test.
15 * The tests can be driven in two ways:
16 * *) running the program directly: Main() uses reflection to find and invoke
17 * the test methods (this is useful mostly to check that the tests are correct)
18 * *) with the --regression switch of the jit (this is the preferred way since
19 * all the tests will be run with optimizations on and off)
21 * The reflection logic could be moved to a .dll since we need at least another
22 * regression test file written in IL code to have better control on how
23 * the IL code looks.
26 delegate int IntNoArgs();
28 public class Base {
30 public virtual int method1 () {
31 return 1;
34 public virtual int method2 () {
35 return 1;
38 public virtual int method3 () {
39 return 1;
42 public virtual int method4 () {
43 return 1;
46 public virtual int method5 () {
47 return 1;
52 public class Middle : Base {
53 public override int method2 () {
54 return 2;
57 public override int method4 () {
58 return 2;
61 public override sealed int method5 () {
62 return 2;
67 public class OpenFinal : Middle {
68 public override sealed int method4 () {
69 return 3;
72 static public int staticMethod() {
73 return 3;
78 sealed public class SealedFinal : Middle {
79 public override int method1 () {
80 return 4;
83 static public int staticMethod() {
84 return 4;
89 class Tests {
91 static int Main (string[] args) {
92 return TestDriver.RunTests (typeof (Tests), args);
95 static public int test_0_sealed_class_devirt_right_method () {
96 SealedFinal x = new SealedFinal ();
97 if (x.method1 () != 4)
98 return 1;
99 if (x.method2 () != 2)
100 return 2;
101 if (x.method3 () != 1)
102 return 1;
103 return 0;
106 static public int test_0_sealed_method_devirt_right_method () {
107 OpenFinal x = new OpenFinal ();
108 if (x.method4 () != 3)
109 return 1;
110 if (x.method5 () != 2)
111 return 2;
112 return 0;
115 static public int test_0_sealed_class_devirt_right_method_using_delegates () {
116 SealedFinal x = new SealedFinal ();
117 IntNoArgs d1 = new IntNoArgs(x.method1);
118 IntNoArgs d2 = new IntNoArgs(x.method2);
119 IntNoArgs d3 = new IntNoArgs(x.method3);
121 if (d1 () != 4)
122 return 1;
123 if (d2 () != 2)
124 return 2;
125 if (d3 () != 1)
126 return 1;
127 return 0;
130 static public int test_0_sealed_method_devirt_right_method_using_delegates () {
131 OpenFinal x = new OpenFinal ();
132 IntNoArgs d1 = new IntNoArgs(x.method4);
133 IntNoArgs d2 = new IntNoArgs(x.method5);
135 if (d1 () != 3)
136 return 1;
137 if (d2 () != 2)
138 return 2;
139 return 0;
143 static public int test_0_delegate_over_static_method_devirtualize_ok () {
144 IntNoArgs d1 = new IntNoArgs(OpenFinal.staticMethod);
145 IntNoArgs d2 = new IntNoArgs(SealedFinal.staticMethod);
147 if (d1 () != 3)
148 return 1;
149 if (d2 () != 4)
150 return 2;
152 return 0;
155 static public int test_0_npe_still_happens() {
156 OpenFinal x = null;
157 SealedFinal y = null;
159 try {
160 y.method1();
161 return 1;
162 } catch(NullReferenceException e) {
163 ;//ok
166 try {
167 y.method2();
168 return 2;
169 } catch(NullReferenceException e) {
170 ;//ok
173 try {
174 y.method3();
175 return 3;
176 } catch(NullReferenceException e) {
177 ;//ok
180 try {
181 x.method4();
182 return 4;
183 } catch(NullReferenceException e) {
184 ;//ok
187 try {
188 x.method5();
189 return 5;
190 } catch(NullReferenceException e) {
191 ;//ok
194 return 0;