[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mono / mini / TestHelpers.cs
blob8e477b69ab4620f9b018938bcc71f1d41e369ebe
1 using System;
2 using System.Threading;
3 using System.Reflection;
5 namespace MonoTests.Helpers {
7 // False pinning cases are still possible. For example the thread can die
8 // and its stack reused by another thread. It also seems that a thread that
9 // does a GC can keep on the stack references to objects it encountered
10 // during the collection which are never released afterwards. This would
11 // be more likely to happen with the interpreter which reuses more stack.
12 public static class FinalizerHelpers {
13 private static IntPtr aptr;
15 private static unsafe void NoPinActionHelper (int depth, Action act)
17 // Avoid tail calls
18 int* values = stackalloc int [20];
19 aptr = new IntPtr (values);
21 if (depth <= 0) {
23 // When the action is called, this new thread might have not allocated
24 // anything yet in the nursery. This means that the address of the first
25 // object that would be allocated would be at the start of the tlab and
26 // implicitly the end of the previous tlab (address which can be in use
27 // when allocating on another thread, at checking if an object fits in
28 // this other tlab). We allocate a new dummy object to avoid this type
29 // of false pinning for most common cases.
31 new object ();
32 act ();
33 } else {
34 NoPinActionHelper (depth - 1, act);
38 public static void PerformNoPinAction (Action act)
40 Thread thr = new Thread (() => NoPinActionHelper (128, act));
41 thr.Start ();
42 thr.Join ();
46 public static class OOMHelpers {
47 public static void RunTest (string test)
49 Assembly asm = Assembly.Load (test);
51 try {
52 // Support both (void) and (string[]) signatures
53 if (asm.EntryPoint.GetParameters ().Length == 1)
54 asm.EntryPoint.Invoke (null, new string[] { null });
55 else
56 asm.EntryPoint.Invoke (null, null);
57 } catch (TargetInvocationException e) {
58 if (e.InnerException is OutOfMemoryException)
59 Console.WriteLine ("Catched oom");
60 else
61 throw;