KirillOsenkov / RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
http://roslynquoter.azurewebsites.net
Apache License 2.0
922 stars 118 forks source link

OOM exception #25

Closed kzu closed 7 years ago

kzu commented 7 years ago

Source:

public bool TryAdd(ref int x, ref int y, out int z)
{
    z = default(int);
    var returns = pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod(), x, y, z));

    x = (int)returns.Outputs["x"];
    y = (int)returns.Outputs["y"];
    z = (int)returns.Outputs["z"];

    return (bool)returns.ReturnValue;
}

Exception:

System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
   at System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb)
   at System.Reflection.Internal.NativeHeapMemoryBlock..ctor(Int32 size)
   at System.Reflection.Internal.StreamMemoryBlockProvider.ReadMemoryBlockNoLock(Stream stream, Boolean isFileStream, Int64 start, Int32 size)
   at System.Reflection.PortableExecutable.PEReader..ctor(Stream peStream, PEStreamOptions options, Int32 size)
   at Microsoft.CodeAnalysis.ModuleMetadata.CreateFromStream(Stream peStream, PEStreamOptions options)
   at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
   at Microsoft.CodeAnalysis.Scripting.Hosting.RuntimeMetadataReferenceResolver.<>c.<.ctor>b__8_0(String path, MetadataReferenceProperties properties)
   at Microsoft.CodeAnalysis.Scripting.Hosting.RuntimeMetadataReferenceResolver.CreateResolvedMissingReference(String fullPath)
   at Microsoft.CodeAnalysis.Scripting.Hosting.RuntimeMetadataReferenceResolver.ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity)
   at Microsoft.CodeAnalysis.CommonReferenceManager`2.ResolveAndBindMissingAssemblies(TCompilation compilation, ImmutableArray`1 explicitAssemblies, ImmutableArray`1 explicitModules, ImmutableArray`1 explicitReferences, ImmutableArray`1 explicitReferenceMap, MetadataReferenceResolver resolver, MetadataImportOptions importOptions, Boolean supersedeLowerVersions, ArrayBuilder`1 referenceBindings, Dictionary`2 assemblyReferencesBySimpleName, ImmutableArray`1& allAssemblies, ImmutableArray`1& metadataReferences, ImmutableArray`1& resolvedReferences, DiagnosticBag resolutionDiagnostics)
   at Microsoft.CodeAnalysis.CommonReferenceManager`2.Bind(TCompilation compilation, ImmutableArray`1 explicitAssemblies, ImmutableArray`1 explicitModules, ImmutableArray`1 explicitReferences, ImmutableArray`1 explicitReferenceMap, MetadataReferenceResolver resolverOpt, MetadataImportOptions importOptions, Boolean supersedeLowerVersions, Dictionary`2 assemblyReferencesBySimpleName, ImmutableArray`1& allAssemblies, ImmutableArray`1& implicitlyResolvedReferences, ImmutableArray`1& implicitlyResolvedReferenceMap, DiagnosticBag resolutionDiagnostics, Boolean& hasCircularReference, Int32& corLibraryIndex)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.ReferenceManager.CreateAndSetSourceAssemblyFullBind(CSharpCompilation compilation)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.ReferenceManager.CreateSourceAssemblyForCompilation(CSharpCompilation compilation)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.BindScriptClass()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetEntryPointAndDiagnostics(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetEntryPoint(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonGetEntryPoint(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptBuilder.Build[T](Compilation compilation, DiagnosticBag diagnostics, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.ScriptBuilder.CreateExecutor[T](ScriptCompiler compiler, Compilation compilation, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.GetExecutor(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Scripting.Script`1.RunAsync(Object globals, Func`2 catchException, CancellationToken cancellationToken)
   at Quoter.Evaluate(String apiCallString, Boolean normalizeWhitespace)
   at Quoter.AddModifyingCall(ApiCall apiCall, MethodCall methodCall)
   at Quoter.AddModifyingCalls(Object treeElement, ApiCall apiCall, List`1 values)
   at Quoter.QuoteNode(SyntaxNode node, String name)
   at Quoter.Quote(Object treeElement, String name)
   at Quoter.<QuoteList>b__31_0(Object o)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at Quoter.QuoteList(IEnumerable syntaxList, String name)
   at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
   at Quoter.<>c__DisplayClass28_0.<QuotePropertyValues>b__2(PropertyInfo propertyInfo)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at Quoter.QuotePropertyValues(SyntaxNode node)
   at Quoter.QuoteNode(SyntaxNode node, String name)
   at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
   at Quoter.<>c__DisplayClass28_0.<QuotePropertyValues>b__2(PropertyInfo propertyInfo)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at Quoter.QuotePropertyValues(SyntaxNode node)
   at Quoter.QuoteNode(SyntaxNode node, String name)
   at Quoter.Quote(Object treeElement, String name)
   at Quoter.<QuoteList>b__31_0(Object o)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at Quoter.QuoteList(IEnumerable syntaxList, String name)
   at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
   at Quoter.<>c__DisplayClass28_0.<QuotePropertyValues>b__2(PropertyInfo propertyInfo)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at Quoter.QuotePropertyValues(SyntaxNode node)
   at Quoter.QuoteNode(SyntaxNode node, String name)
   at Quoter.Quote(Object treeElement, String name)
   at Quoter.Quote(SyntaxNode node)
   at QuoterService.Controllers.QuoterController.Get(String sourceText, NodeKind nodeKind, Boolean openCurlyOnNewLine, Boolean closeCurlyOnNewLine, Boolean preserveOriginalWhitespace, Boolean keepRedundantApiCalls, Boolean avoidUsingStatic)
kzu commented 7 years ago

Funny, wrapping the method in a class, works

public class Foo
{
 public bool TryAdd(ref int x, ref int y, out int z)
 {
    z = default(int);
    var returns = pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod(), x, y, z));

    x = (int)returns.Outputs["x"];
    y = (int)returns.Outputs["y"];
    z = (int)returns.Outputs["z"];

    return (bool)returns.ReturnValue;
 }
}
KirillOsenkov commented 7 years ago

I've seen this before a couple of times and had to restart the service once, but it seems intermittent... your example works for me. I'll keep this open maybe I'll have time to investigate.

KirillOsenkov commented 7 years ago

Still not sure what is going on, so closing for now. Holler if you ever see this again.