forked from dotnet/coreclr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test that triggers stack probing.
This test exercises the JIT's ability to probe the stack on windows for dynamic allocation. It uses multiple threads and a two-stage allocation pattern to try and hit various boundary cases.
- Loading branch information
1 parent
f37c4d4
commit 6618428
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using System.Threading; | ||
|
||
public class ThreadData | ||
{ | ||
public AutoResetEvent autoEvent; | ||
public int initialAllocation; | ||
public int result; | ||
|
||
public unsafe void Run() | ||
{ | ||
autoEvent.WaitOne(); | ||
int* buffer = stackalloc int[initialAllocation]; | ||
int last = initialAllocation - 1; | ||
buffer[0] = 100; | ||
buffer[last] = 200; | ||
|
||
for (int i = 2; i < 1026; i++) | ||
{ | ||
result += AllocateMore(i); | ||
} | ||
|
||
result += buffer[last] - buffer[0]; | ||
} | ||
|
||
public unsafe int AllocateMore(int n) | ||
{ | ||
int* buffer = stackalloc int[n]; | ||
int last = n - 1; | ||
buffer[0] = n + 1; | ||
buffer[last] = n - 1; | ||
return buffer[last] - buffer[0] + 2; | ||
} | ||
} | ||
|
||
public class BringUpTest | ||
{ | ||
const int Pass = 100; | ||
const int Fail = -1; | ||
|
||
public static bool RunTest(int n) | ||
{ | ||
ThreadData data = new ThreadData(); | ||
data.autoEvent = new AutoResetEvent(false); | ||
data.initialAllocation = n; | ||
|
||
Thread t = new Thread(data.Run); | ||
t.Start(); | ||
if (!t.IsAlive) | ||
{ | ||
return false; | ||
} | ||
data.autoEvent.Set(); | ||
t.Join(); | ||
bool ok = data.result == 100; | ||
return ok; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
for (int j = 2; j < 1024 * 100; j += 33) | ||
{ | ||
bool b = RunTest(j); | ||
if (!b) return Fail; | ||
} | ||
return Pass; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters