dotnet/runtime

JIT: conditionalize COMPlus variable setting

Open

#11,854 建立於 2019年1月19日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)C# (5,445 fork)batch import
area-CodeGen-coreclrhelp wanted

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

Most JIT COMPlus variables are either:

  1. enabled for all methods,
  2. enabled for all methods that match a class/method pattern, or a method hash

Altjit is a little tricky, as it "takes over" some of the variables, thus the settings apply to the altjit compiler, and the non-altjit compiler leaves the variables disabled (e.g., COMPlus_JitDump).

Often, I find myself wanting to enable a variable for a set of methods (which actually can be done for those that take a pattern, although it's cumbersome for more than a few, since they're all specified on the same line).

JITMinOpts has some additional magic, to allow for binary searching by method count, if you can figure out the magic hex numbers to use, and the function method count remains stable and less than 0x1000 (see Compiler::compSetOptimizationLevel()).

There is some other ad-hoc code to implement ranges: look for minoptshashlo, minoptshashhi, JitStressRegsHashLo/JitStressRegsHashHi, etc.

I needed to do a binary search with a new COMPlus variable. I implemented a new mechanism as follows:

  1. set COMPlus_JitFunctionFile to the name of a file that contains entries kind of like what JitFunctionTrace emits:
System.CLRConfig:GetBoolValue(ref,byref):bool (MethodHash=3c54d35e)
   -- use the MethodHash, not the function name

System.CLRConfig:GetBoolValue(ref,byref):bool
    -- use just the name

Also, there are leading comment characters.

  1. Then, made my new variable first check this list. If no list, use the default behavior. If there is a list, check to see if the method being compiled is in this list of "active" functions, then apply the variable only to those functions.
  2. Then I could easily binary search by editing the file.

I was thinking if we could have a more general solution, that could conditionalize any variable in a number of ways (I'm sure there will be exceptions to "any"). E.g., conditionalize based on a file, like above. Or conditionalize based on method count, like JITMinOpts does. One possible syntax:

COMPlus_JitConditionalizeFile=file.txt COMPlus_foo=1 -- only set COMPlus_foo=1 for functions that match in file.txt COMPlus_JitConditionalizeMethodCnt=1-10,60-1000,2000- COMPlus_bar=1 -- only set COMPlus_bar=1 for function counts in the specified ranges.

Comments?

@dotnet/jit-contrib

category:implementation theme:jit-coding-style skill-level:beginner cost:small

貢獻者指南