Skip to content

Commit

Permalink
Add support for generating asm diffs using an altjit
Browse files Browse the repository at this point in the history
e.g., `jit-diff --altjit protononjit.dll ...`
  • Loading branch information
BruceForstall committed Dec 11, 2017
1 parent 7402ff8 commit f0cf8cc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 57 deletions.
115 changes: 60 additions & 55 deletions doc/diffs.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,59 +131,63 @@ The "jit-diff diff" command has this help message:
usage: jit-diff diff [-b [arg]] [-d [arg]] [--crossgen <arg>] [-o <arg>] [--noanalyze] [-s]
[-t <arg>] [-c] [-f] [--benchmarks] [--tests] [--gcinfo] [-v] [--core_root <arg>]
[--test_root <arg>] [--base_root <arg>] [--diff_root <arg>] [--arch <arg>]
[--build <arg>]
-b, --base [arg] The base compiler directory or tag. Will use clrjit from this directory.
-d, --diff [arg] The diff compiler directory or tag. Will use clrjit from this directory.
[--build <arg>] [--altjit <arg>]
-b, --base [arg] The base compiler directory or tag. Will use crossgen or clrjit from this
directory.
-d, --diff [arg] The diff compiler directory or tag. Will use crossgen or clrjit from this
directory.
--crossgen <arg> The crossgen compiler exe. When this is specified, will use clrjit from
the --base and --diff directories with this crossgen.
the --base and --diff directories with this crossgen.
-o, --output <arg> The output path.
--noanalyze Do not analyze resulting base, diff dasm directories. (By default, the
directories are analyzed for diffs.)
directories are analyzed for diffs.)
-s, --sequential Run sequentially; don't do parallel compiles.
-t, --tag <arg> Name of root in output directory. Allows for many sets of output.
-c, --corelib Diff System.Private.CoreLib.dll.
-f, --frameworks Diff frameworks.
--benchmarks Diff core benchmarks. Must pass --test_root.
--tests Diff all tests. Must pass --test_root.
--benchmarks Diff core benchmarks.
--tests Diff all tests.
--gcinfo Add GC info to the disasm output.
-v, --verbose Enable verbose output.
--core_root <arg> Path to test CORE_ROOT.
--test_root <arg> Path to test tree. Use with --benchmarks or --tests.
--base_root <arg> Path to root of base dotnet/coreclr repo.
--diff_root <arg> Path to root of diff dotnet/coreclr repo.
--arch <arg> Architecture to diff (x86, x64).
--build <arg> Build flavor to diff (checked, debug).
--build <arg> Build flavor to diff (Checked, Debug).
--altjit <arg> If set, the name of the altjit to use (e.g., protononjit.dll).
Examples:
jit-diff diff --output c:\diffs --corelib --core_root c:\coreclr\bin\tests\Windows_NT.x64.release\Tests\Core_Root --base c:\coreclr_base\bin\Product\Windows_NT.x64.checked --diff c:\coreclr\bin\Product\Windows_NT.x86.checked
Generate diffs of System.Private.CoreLib.dll by specifying baseline and
diff compiler directories explicitly.
jit-diff diff --output c:\diffs --base c:\coreclr_base\bin\Product\Windows_NT.x64.checked --diff
If run within the c:\coreclr git clone of dotnet/coreclr, does the same
as the prevous example, using defaults.
jit-diff diff --output c:\diffs --base --base_root c:\coreclr_base --diff
Does the same as the prevous example, using -base_root to find the base
directory (if run from c:\coreclr tree).
jit-diff diff --base --diff
Does the same as the prevous example (if run from c:\coreclr tree), but uses
default c:\coreclr\bin\diffs output directory, and `base_root` must be specified
in the config.json file in the directory pointed to by the JIT_UTILS_ROOT
environment variable.
jit-diff diff --diff
Only generates asm using the diff JIT -- does not generate asm from a baseline compiler
using all computed defaults.
jit-diff diff --diff --arch x86
Generate diffs, but for x86, even if there is an x64 compiler available.
jit-diff diff --diff --build debug
Generate diffs, but using a debug build, even if there is a checked build available.
jit-diff diff --output c:\diffs --corelib --core_root c:\coreclr\bin\tests\Windows_NT.x64.Release\Tests\Core_Root --base c:\coreclr_base\bin\Product
\Windows_NT.x64.Checked --diff c:\coreclr\bin\Product\Windows_NT.x86.Checked
Generate diffs of System.Private.CoreLib.dll by specifying baseline and
diff compiler directories explicitly.
jit-diff diff --output c:\diffs --base c:\coreclr_base\bin\Product\Windows_NT.x64.Checked --diff
If run within the c:\coreclr git clone of dotnet/coreclr, does the same
as the prevous example, using defaults.
jit-diff diff --output c:\diffs --base --base_root c:\coreclr_base --diff
Does the same as the prevous example, using -base_root to find the base
directory (if run from c:\coreclr tree).
jit-diff diff --base --diff
Does the same as the prevous example (if run from c:\coreclr tree), but uses
default c:\coreclr\bin\diffs output directory, and `base_root` must be specified
in the config.json file in the directory pointed to by the JIT_UTILS_ROOT
environment variable.
jit-diff diff --diff
Only generates asm using the diff JIT -- does not generate asm from a baseline compiler --
using all computed defaults.
jit-diff diff --diff --arch x86
Generate diffs, but for x86, even if there is an x64 compiler available.
jit-diff diff --diff --build Debug
Generate diffs, but using a Debug build, even if there is a Checked build available.
```

The "jit-diff list" command has this help message:
Expand Down Expand Up @@ -434,23 +438,24 @@ prebuilt base from the CI builds, or building it locally.
Sample help command line:
```
$ jit-dasm --help
usage: jit-dasm [-c <arg>] [-j <arg>] [-o <arg>] [-t <arg>] [-f <arg>]
[--gcinfo] [-v] [-r] [-p <arg>...] [--] <assembly>...
-c, --crossgen <arg> The crossgen compiler exe.
-j, --jit <arg> The full path to the jit library.
-o, --output <arg> The output path.
-t, --tag <arg> Name of root in output directory. Allows
for many sets of output.
-f, --file <arg> Name of file to take list of assemblies
from. Both a file and assembly list can
be used.
--gcinfo Add GC info to the disasm output.
-v, --verbose Enable verbose output.
-r, --recursive Scan directories recursively.
-p, --platform <arg>... Path to platform assemblies
<assembly>... The list of assemblies or directories to
scan for assemblies.
usage: jit-dasm [--altjit <arg>] [-c <arg>] [-j <arg>] [-o <arg>]
[-f <arg>] [--gcinfo] [-v] [-r] [-p <arg>...] [--]
<assembly>...
--altjit <arg> If set, the name of the altjit to use
(e.g., protononjit.dll).
-c, --crossgen <arg> The crossgen compiler exe.
-j, --jit <arg> The full path to the jit library.
-o, --output <arg> The output path.
-f, --file <arg> Name of file to take list of assemblies
from. Both a file and assembly list can
be used.
--gcinfo Add GC info to the disasm output.
-v, --verbose Enable verbose output.
-r, --recursive Scan directories recursively.
-p, --platform <arg>... Path to platform assemblies
<assembly>... The list of assemblies or directories to
scan for assemblies.
```

## packages
Expand Down
17 changes: 17 additions & 0 deletions src/jit-dasm/jit-dasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace ManagedCodeGen
public class Config
{
private ArgumentSyntax _syntaxResult;
private string _altjit = null;
private string _crossgenExe = null;
private string _jitPath = null;
private string _rootPath = null;
Expand All @@ -52,6 +53,7 @@ public Config(string[] args)
{
_syntaxResult = ArgumentSyntax.Parse(args, syntax =>
{
syntax.DefineOption("altjit", ref _altjit, "If set, the name of the altjit to use (e.g., protononjit.dll).");
syntax.DefineOption("c|crossgen", ref _crossgenExe, "The crossgen compiler exe.");
syntax.DefineOption("j|jit", ref _jitPath, "The full path to the jit library.");
syntax.DefineOption("o|output", ref _rootPath, "The output path.");
Expand Down Expand Up @@ -142,6 +144,7 @@ private void Validate()
public bool DoVerboseOutput { get { return _verbose; } }
public string CrossgenExecutable { get { return _crossgenExe; } }
public string JitPath { get { return _jitPath; } }
public string AltJit { get { return _altjit; } }
public string RootPath { get { return _rootPath; } }
public IReadOnlyList<string> PlatformPaths { get { return _platformPaths; } }
public string FileName { get { return _fileName; } }
Expand Down Expand Up @@ -339,6 +342,7 @@ private class DisasmEngine
private string _rootPath = null;
private IReadOnlyList<string> _platformPaths;
private string _jitPath = null;
private string _altjit = null;
private List<AssemblyInfo> _assemblyInfoList;
public bool doGCDump = false;
public bool verbose = false;
Expand All @@ -354,6 +358,7 @@ public DisasmEngine(string executable, Config config, string outputPath,
_rootPath = outputPath;
_platformPaths = config.PlatformPaths;
_jitPath = config.JitPath;
_altjit = config.AltJit;
_assemblyInfoList = assemblyInfoList;

this.doGCDump = config.DumpGCInfo;
Expand Down Expand Up @@ -452,6 +457,18 @@ public void GenerateAsm()
generateCmd.EnvironmentVariable("COMPlus_NgenGCDump", "*");
}

if (this._altjit != null)
{
generateCmd.EnvironmentVariable("COMPlus_AltJit", "*");
generateCmd.EnvironmentVariable("COMPlus_AltJitNgen", "*");
generateCmd.EnvironmentVariable("COMPlus_AltJitName", _altjit);

if (this.verbose)
{
Console.WriteLine("Setting AltJit for {0}", _altjit);
}
}

if (this.verbose)
{
Console.WriteLine("Running: {0} {1}", _executablePath, String.Join(" ", commandArgs));
Expand Down
20 changes: 18 additions & 2 deletions src/jit-diff/diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,20 @@ private List<string> ConstructArgs(List<string> commandArgs, string clrPath)
dasmArgs.Add(crossgenPath);
}

var jitPath = Path.Combine(clrPath, GetJitLibraryName(m_config.PlatformMoniker));
string jitName;
if (m_config.AltJit != null)
{
jitName = m_config.AltJit;
}
else
{
jitName = GetJitLibraryName(m_config.PlatformMoniker);
}

var jitPath = Path.Combine(clrPath, jitName);
if (!File.Exists(jitPath))
{
Console.Error.WriteLine("clrjit not found at {0}", jitPath);
Console.Error.WriteLine("JIT not found at {0}", jitPath);
return null;
}

Expand Down Expand Up @@ -235,6 +245,12 @@ public static int DiffCommand(Config config)
commandArgs.Add("--verbose");
}

if (config.AltJit != null)
{
commandArgs.Add("--altjit");
commandArgs.Add(config.AltJit);
}

List<AssemblyInfo> assemblyWorkList = GenerateAssemblyWorklist(config);

DiffTool diffTool = new DiffTool(config);
Expand Down
3 changes: 3 additions & 0 deletions src/jit-diff/jit-diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class Config
private string _diffRoot = null;
private string _arch = null;
private string _build = null;
private string _altjit = null;
private bool _corelib = false;
private bool _frameworks = false;
private bool _benchmarks = false;
Expand Down Expand Up @@ -163,6 +164,7 @@ public Config(string[] args)
syntax.DefineOption("diff_root", ref _diffRoot, "Path to root of diff dotnet/coreclr repo.");
syntax.DefineOption("arch", ref _arch, "Architecture to diff (x86, x64).");
syntax.DefineOption("build", ref _build, "Build flavor to diff (Checked, Debug).");
syntax.DefineOption("altjit", ref _altjit, "If set, the name of the altjit to use (e.g., protononjit.dll).");

// List command section.
syntax.DefineCommand("list", ref _command, Commands.List,
Expand Down Expand Up @@ -1153,6 +1155,7 @@ public int ListCommand()
public string RID { get { return _rid; } }
public string Number { get { return _number; } }
public string BranchName { get { return _branchName; } }
public string AltJit { get { return _altjit; } }
}

private static string[] s_testDirectories =
Expand Down

0 comments on commit f0cf8cc

Please sign in to comment.