Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

sandreenko
Copy link

@sandreenko sandreenko commented Apr 16, 2018

Jit can extend lifetime of temp objects after call to GC.Collect(), so we should not have any temp in the same scope with final GC.Collect();.

incorrect example 1:

var a = new Object(); // Jit can create a temp that will be alive after GC.Collect().
a = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

incorrect example 2:

SetLink();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

void SetLink() // this method could be inlined, we will get the first example.
{
       var a = new Object();
       a = null;
}

Incorrect example 3:

var a = SetLink(); // Jit can create a temp here with a long lifetime.
a = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

[MethodImpl(MethodImplOptions.NoInlining)]
Object SetLink()
{
       return new Object();
}

correct example 1:

SetLink();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

[MethodImpl(MethodImplOptions.NoInlining)]
void SetLink() // All temps are in this method and it is protected with NoInlining attribute.
{
       var a = new Object();
       a = null;
}

Fixes #17588.

The same problem as #15156.

@sandreenko sandreenko added the test bug Problem in test source code (most likely) label Apr 16, 2018
@sandreenko sandreenko added this to the 2.1.0 milestone Apr 16, 2018
@sandreenko sandreenko force-pushed the fixGSTests2 branch 2 times, most recently from cd662af to 69a18b1 Compare April 16, 2018 21:30
@sandreenko sandreenko changed the title Fix GS tests. Fix GC tests. Apr 16, 2018
@sandreenko
Copy link
Author

@dotnet-bot test Windows_NT arm Cross Checked r2r_jitstressregs3 Build and Test
@dotnet-bot test Windows_NT arm Cross Checked jitstress2_jitstressregs3 Build and Test

@sandreenko
Copy link
Author

cc @Maoni0

@Maoni0
Copy link
Member

Maoni0 commented Apr 16, 2018

thanks!

@sandreenko sandreenko merged commit 34c7fe6 into dotnet:master Apr 17, 2018
sandreenko pushed a commit to sandreenko/coreclr that referenced this pull request Apr 17, 2018
* Fix dlbigleak

* cleanup dlstack

* Fix doublinknoleak

* Fix doublinkstay

* Fix dlcollect

* Fix doublinkgen

* Fix dlbigleakthd
sandreenko pushed a commit that referenced this pull request Apr 18, 2018
* Fix dlbigleak

* cleanup dlstack

* Fix doublinknoleak

* Fix doublinkstay

* Fix dlcollect

* Fix doublinkgen

* Fix dlbigleakthd
@sandreenko sandreenko deleted the fixGSTests2 branch November 2, 2018 22:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
test bug Problem in test source code (most likely)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants