Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mixed.cs « mini « mono - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8ee0ac460febb5c60336a61111a75288ab2d93a4 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Diagnostics;

/*
 * Regression tests for the mixed-mode execution.
 * Run with --interp=jit=JitClass
 */

struct AStruct {
	public int i;
}

struct GStruct<T> {
	public int i;
}

class InterpClass
{
	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static void entry_void_0 () {
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static int entry_int_int (int i) {
		return i + 1;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public int entry_int_this_int (int i) {
		return i + 1;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static string entry_string_string (string s1, string s2) {
		return s1 + s2;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static AStruct entry_struct_struct (AStruct l) {
		return l;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static List<string> entry_ginst_ginst (List<string> l) {
		return l;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static GStruct<string> entry_ginst_ginst_vtype (GStruct<string> l) {
		return l;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static void entry_void_byref_int (ref int i) {
		i = i + 1;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static int entry_8_int_args (int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
		return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static int entry_9_int_args (int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9) {
		return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static IntPtr entry_intptr_intptr (IntPtr i) {
		return i;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static int entry_deep_generic_vt (int i, decimal? b) {
		return i;
	}


	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static StackTrace get_stacktrace_interp () {
		var o = new object ();
		return new StackTrace (true);
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static StackTrace get_stacktrace_interp2 () {
		return JitClass.get_stacktrace_jit ();
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static void throw_ex () {
		JitClass.throw_ex ();
	}
}

/* The methods in this class will always be JITted */
class JitClass
{
	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static int entry () {
		InterpClass.entry_void_0 ();
		InterpClass.entry_void_0 ();
		int res = InterpClass.entry_int_int (1);
		if (res != 2)
			return 1;
		var c = new InterpClass ();
		res = c.entry_int_this_int (1);
		if (res != 2)
			return 2;
		var s = InterpClass.entry_string_string ("A", "B");
		if (s != "AB")
			return 3;
		var astruct = new AStruct () { i = 1 };
		var astruct2 = InterpClass.entry_struct_struct (astruct);
		if (astruct2.i != 1)
			return 4;
		var l = new List<string> ();
		var l2 = InterpClass.entry_ginst_ginst (l);
		if (l != l2)
			return 5;
		var gstruct = new GStruct<string> () { i = 1 };
		var gstruct2 = InterpClass.entry_ginst_ginst_vtype (gstruct);
		if (gstruct2.i != 1)
			return 6;
		int val = 1;
		InterpClass.entry_void_byref_int (ref val);
		if (val != 2)
			return 7;
		res = InterpClass.entry_8_int_args (1, 2, 3, 4, 5, 6, 7, 8);
		if (res != 36)
			return 8;
		res = InterpClass.entry_9_int_args (1, 2, 3, 4, 5, 6, 7, 8, 9);
		if (res != 45)
			return 9;
		var ptr = new IntPtr (32);
		var ptr2 = InterpClass.entry_intptr_intptr (ptr);
		if (ptr != ptr2)
			return 10;
		var edgvt_ret = InterpClass.entry_deep_generic_vt (1337, 2m);
		if (edgvt_ret != 1337)
			return 11;
		return 0;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static AStruct exit_vtype (AStruct s) {
		return s;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static List<string> exit_ginst (List<string> l) {
		return l;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static GStruct<string> exit_ginst_vtype (GStruct<string> l) {
		return l;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static void exit_byref (ref int i) {
		i += 1;
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static void throw_ex () {
		throw new Exception ();
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static StackTrace get_stacktrace_jit () {
		return InterpClass.get_stacktrace_interp ();
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static StackTrace get_stacktrace_jit2 () {
		return InterpClass.get_stacktrace_interp2 ();
	}

	[MethodImplAttribute (MethodImplOptions.NoInlining)]
	public static string string_from_interp ()
	{
		char [] buf = new char [10];
		for (int i = 0; i < buf.Length; i++)
			buf [i] = (char) ((int) 'a' + i);
		return new string (buf, 0, 10);
	}
}

#if __MOBILE__
class MixedTests
#else
class Tests
#endif
{

#if !__MOBILE__
	public static int Main (string[] args) {
		return TestDriver.RunTests (typeof (Tests), args);
	}
#endif

	public static int test_0_entry () {
		// This does an interp->jit transition
		return JitClass.entry ();
	}

	public static int test_0_exit () {
		var astruct = new AStruct () { i = 1};
		var astruct2 = JitClass.exit_vtype (astruct);
		if (astruct2.i != 1)
			return 1;
		var ginst = new List<string> ();
		var ginst2 = JitClass.exit_ginst (ginst);
		if (ginst != ginst2)
			return 2;
		var gstruct = new GStruct<string> () { i = 1 };
		var gstruct2 = JitClass.exit_ginst_vtype (gstruct);
		if (gstruct2.i != 1)
			return 3;
		var anint = 1;
		JitClass.exit_byref (ref anint);
		if (anint != 2)
			return 4;
		return 0;
	}

	public static int test_0_throw () {
		// Throw an exception from jitted code, catch it in interpreted code
		try {
			JitClass.throw_ex ();
		} catch {
			return 0;
		}
		return 1;
	}

	public static int test_0_throw_child () {
		try {
			InterpClass.throw_ex ();
		} catch {
			return 0;
		}
		return 1;
	}

	static bool finally_called;

	public static void call_finally () {
		try {
			JitClass.throw_ex ();
		} finally {
			finally_called = true;
		}
	}

	public static int test_0_eh2 () {
		finally_called = false;

		// Throw an exception from jitted code, execute finally in interpreted code
		try {
			call_finally ();
		} catch {
			return 0;
		}
		if (!finally_called)
			return 2;
		return 1;
	}

	[Category ("!WASM")] //Stack traces / EH are super broken on WASM + Interpreter
	public static int test_0_stack_traces () {
		//
		// Get a stacktrace for an interp->jit->interp call stack
		//
		StackTrace st = JitClass.get_stacktrace_jit2 ();

		var frame0 = st.GetFrame (0);
		var frame1 = st.GetFrame (1);
		var frame2 = st.GetFrame (2);
		var frame3 = st.GetFrame (3);
		var frame4 = st.GetFrame (4);

		if (frame0.GetMethod ().Name != "get_stacktrace_interp")
			return 1;

		if (frame1.GetMethod ().Name != "get_stacktrace_jit")
			return 2;

		if (frame2.GetMethod ().Name != "get_stacktrace_interp2")
			return 3;

		if (frame3.GetMethod ().Name != "get_stacktrace_jit2")
			return 4;

		if (frame4.GetMethod ().Name != "test_0_stack_traces")
			return 5;
		return 0;
	}

	// Finally exception will be thrown from this stack : interp -> jit -> eh -> interp
	// Test that we propagate the finally exception over the jitted frames
	public static int test_0_finex () {
		bool called_finally = false;
		try {
			try {
				JitClass.throw_ex ();
				return 3;
			} finally {
				called_finally = true;
				throw new Exception ("E2");
			}
		} catch (Exception) {
			if (!called_finally)
				return 1;
			return 0;
		}
		return 2;
	}

	public static int test_0_stringctor () {
		string s = JitClass.string_from_interp ();
		return s == "abcdefghij" ? 0 : 1;
	}
}