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
)
18 int* values
= stackalloc int [20];
19 aptr
= new IntPtr (values
);
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.
34 NoPinActionHelper (depth
- 1, act
);
38 public static void PerformNoPinAction (Action act
)
40 Thread thr
= new Thread (() => NoPinActionHelper (128, act
));
46 public static class OOMHelpers
{
47 public static void RunTest (string test
)
49 Assembly asm
= Assembly
.Load (test
);
52 // Support both (void) and (string[]) signatures
53 if (asm
.EntryPoint
.GetParameters ().Length
== 1)
54 asm
.EntryPoint
.Invoke (null, new string[] { null }
);
56 asm
.EntryPoint
.Invoke (null, null);
57 } catch (TargetInvocationException e
) {
58 if (e
.InnerException
is OutOfMemoryException
)
59 Console
.WriteLine ("Catched oom");