Limit crossgen2 instantiating depth (#791)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 12 Dec 2019 17:24:12 +0000 (18:24 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Dec 2019 17:24:12 +0000 (18:24 +0100)
commite8a90ceee4a8979e1fa51c2c93374a922b544197
treef3ca8daa6494c91aaf311693ff09246b858dc152
parent395107644e961b0ffc2973c1d27d409295f0cdf9
Limit crossgen2 instantiating depth (#791)

Two coreclr pri1 tests were causing the crossgen2 to run until all
memory was depleeted due to the fact that we were not limiting depth of
instantiations of methods and those tests had recursive instantiation.
An example taken from one of the tests is this:
```
private static T meth<T>(int v, T x)
{
   //Recursive generic
   return ((v >= 0) ? meth<Tuple<T, T>>(v - 1, new Tuple<T, T>(x, x)).Field0 : x);
}
```

This change fixes it by adding the instantiation depth check for
function calls. If the level of instantiation for any of the generic
parameters exceeds a preset value (currently 10, taken from old
crossgen), the caller is not compiled by crossgen2. Such a method will
be compiled at runtime by JIT instead.
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs