summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKoundinya Veluri <kouvel@users.noreply.github.com>2018-03-15 10:05:42 -0700
committerGitHub <noreply@github.com>2018-03-15 10:05:42 -0700
commit1c5d0281719f2aad04e6738b99c845b4f95c214a (patch)
tree66fdb672bfab2618abd670d5744e1ec3a32bedd9 /tests
parent65d0df04b37ec2679e087d813597cc524b2465c7 (diff)
downloadcoreclr-1c5d0281719f2aad04e6738b99c845b4f95c214a.tar.gz
coreclr-1c5d0281719f2aad04e6738b99c845b4f95c214a.tar.bz2
coreclr-1c5d0281719f2aad04e6738b99c845b4f95c214a.zip
Fix to not reuse preallocated jump stubs for dynamic methods (#16941)
Fix to not reuse preallocated jump stubs for dynamic methods Fixes https://github.com/dotnet/coreclr/issues/16940 - Allocate an extra jump stub per temporary entry points chunk that is shared by all precodes in the chunk. This jump stub always points to PrecodeFixupThunk. - Use that for PrecodeFixupThunk, and use the precode-associated jump stub for pointing to the jitted code - Considered allocating the extra jump stub only if coreclr is far away, but it involves reallocation which may be common in some environments/scenarios. Figured 12 extra bytes per dynamic type is not too significant.
Diffstat (limited to 'tests')
-rw-r--r--tests/src/CoreMangLib/cti/system/reflection/emit/DynMethodJumpStubTests/DynMethodJumpStubTests.cs28
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/src/CoreMangLib/cti/system/reflection/emit/DynMethodJumpStubTests/DynMethodJumpStubTests.cs b/tests/src/CoreMangLib/cti/system/reflection/emit/DynMethodJumpStubTests/DynMethodJumpStubTests.cs
index 1dc717d884..d50d3cedbf 100644
--- a/tests/src/CoreMangLib/cti/system/reflection/emit/DynMethodJumpStubTests/DynMethodJumpStubTests.cs
+++ b/tests/src/CoreMangLib/cti/system/reflection/emit/DynMethodJumpStubTests/DynMethodJumpStubTests.cs
@@ -28,10 +28,11 @@ public static class DynamicMethodJumpStubTests
// framework libraries.
ReserveMemoryAround(new Action(ExecutionContext.RestoreFlow).Method.MethodHandle);
- for (int i = 0; i < 64; ++i)
+ var dynamicMethodDelegates = new Action[64];
+ for (int i = 0; i < dynamicMethodDelegates.Length; ++i)
{
DynamicMethod dynamicMethod = CreateDynamicMethod("DynMethod" + i);
- Action dynamicMethodDelegate = (Action)dynamicMethod.CreateDelegate(typeof(Action));
+ dynamicMethodDelegates[i] = (Action)dynamicMethod.CreateDelegate(typeof(Action));
// Before compiling the dynamic method, reserve memory around its current entry point, which should be its
// precode. Then, when compiling the method, there would be a good chance that the code will be located far from
@@ -44,9 +45,30 @@ public static class DynamicMethodJumpStubTests
null,
dynamicMethod,
null));
+ }
- dynamicMethodDelegate();
+ // Call each dynamic method concurrently from several threads to validate jump stub usage
+ int threadCount = 64;
+ var barrier = new Barrier(threadCount);
+ ThreadStart threadStart = () =>
+ {
+ var dynamicMethodDelegatesLocal = dynamicMethodDelegates;
+ for (int i = 0; i < dynamicMethodDelegatesLocal.Length; ++i)
+ {
+ var dynamicMethodDelegate = dynamicMethodDelegatesLocal[i];
+ barrier.SignalAndWait();
+ dynamicMethodDelegate();
+ }
+ };
+ var threads = new Thread[threadCount];
+ for (int i = 0; i < threads.Length; ++i)
+ {
+ threads[i] = new Thread(threadStart);
+ threads[i].IsBackground = true;
+ threads[i].Start();
}
+ foreach (var t in threads)
+ t.Join();
// This test does not release reserved pages because they may have been committed by other components on the system
}