From: noahfalk Date: Fri, 15 Sep 2017 02:33:29 +0000 (-0700) Subject: Fix test StackCommitCommon X-Git-Tag: accepted/tizen/base/20180629.140029~1066^2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b5e12c59d37778d98156ae19298b2152b886c6d;p=platform%2Fupstream%2Fcoreclr.git Fix test StackCommitCommon This test will hang if run with non-optimized jitted code because it takes a dependency on exactly when locally allocated objects go out of scope. Although I doubt CLI spec guarantees the new code will always work either, it does work with the runtime/JIT as currently implemented. --- diff --git a/tests/src/baseservices/threading/commitstackonlyasneeded/StackCommitCommon.cs b/tests/src/baseservices/threading/commitstackonlyasneeded/StackCommitCommon.cs index fef88b1..d97f9c2 100644 --- a/tests/src/baseservices/threading/commitstackonlyasneeded/StackCommitCommon.cs +++ b/tests/src/baseservices/threading/commitstackonlyasneeded/StackCommitCommon.cs @@ -236,9 +236,19 @@ namespace StackCommitTest public static void Run(Action action) { - new Finalizer(action); + //We need to allocate the object inside of a seperate method to ensure that + //the reference will be eliminated before GC.Collect is called. Technically + //even across methods we probably don't make any formal guarantees but this + //is sufficient for current runtime implementations. + CreateUnreferencedObject(action); GC.Collect(); GC.WaitForPendingFinalizers(); } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + private static void CreateUnreferencedObject(Action action) + { + new Finalizer(action); + } } -} \ No newline at end of file +}