From fc80be14c3d220b5c283d04b747f9a69a8d42ccb Mon Sep 17 00:00:00 2001 From: t-mustafin <66252296+t-mustafin@users.noreply.github.com> Date: Fri, 19 Mar 2021 21:32:58 +0300 Subject: [PATCH] [crossgen2] Fix memory leak in _corInfoImpls. (#49764) * [crossgen2] Implement Dispose in Compilation. _corInfoImpls elements keeps _compilation reference which keeps reference to whole table _corInfoImpls. The circular referene together with issue #12255 potentionally leads to memory leak in crossgen2 if that table is created more than once. Dispose() method clears the table and prevents memory leak. Signed-off-by: Timur Mustafin * Update src/coreclr/tools/aot/crossgen2/Program.cs Co-authored-by: Jan Kotas --- .../Compiler/ReadyToRunCodegenCompilation.cs | 9 ++++++++- src/coreclr/tools/aot/crossgen2/Program.cs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs index 99fda28..0573222 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs @@ -23,7 +23,7 @@ using Internal.TypeSystem.Ecma; namespace ILCompiler { - public abstract class Compilation : ICompilation + public abstract class Compilation : ICompilation, IDisposable { protected readonly DependencyAnalyzerBase _dependencyGraph; protected readonly NodeFactory _nodeFactory; @@ -67,6 +67,7 @@ namespace ILCompiler _methodILCache = new ILCache(ilProvider, NodeFactory.CompilationModuleGroup); } + public abstract void Dispose(); public abstract void Compile(string outputFileName); public abstract void WriteDependencyLog(string outputFileName); @@ -218,6 +219,7 @@ namespace ILCompiler { void Compile(string outputFileName); void WriteDependencyLog(string outputFileName); + void Dispose(); } public sealed class ReadyToRunCodegenCompilation : Compilation @@ -638,5 +640,10 @@ namespace ILCompiler } public ISymbolNode GetFieldRvaData(FieldDesc field) => NodeFactory.CopiedFieldRva(field); + + public override void Dispose() + { + _corInfoImpls?.Clear(); + } } } diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index cd906d2..1a13309 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -632,6 +632,8 @@ namespace ILCompiler if (_commandLineOptions.DgmlLogFileName != null) compilation.WriteDependencyLog(_commandLineOptions.DgmlLogFileName); + + compilation.Dispose(); } return 0; -- 2.7.4