Home

Awesome

JIT Inspector

A tool for inspecting Mono JIT code in Unity.

Usage

Open the tool from the Window -> JIT Inspector View menu option.

JIT Configuration

You can configure the JIT using the following class:

#if ENABLE_MONO
using System.Text;
using System.Runtime.InteropServices;

internal static unsafe class MonoJitConfig
{
    private const string Optimizations = "-float32";

    [DllImport("__Internal")]
    private static extern void mono_jit_parse_options(int argc, byte** argv);

#if UNITY_EDITOR
    [UnityEditor.InitializeOnLoadMethod]
#else
    [UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
#endif
    private static void ParseOptions()
    {
        fixed (byte* arg = Encoding.UTF8.GetBytes("-O=" + Optimizations + "\0"))
        {
            mono_jit_parse_options(1, &arg);
        }
    }
}
#endif

The Optimizations string is a comma-separated (without spaces) list of optimization passes for the JIT to perform. Prefixing an optimization with a minus (-) will disable it.

You may use all to enable all optimizations and -all to disable all optimizations.

Entries later in the list will override entries before them, meaning -branch,branch will result in branch being enabled. -all,branch will result in only branch being enabled.

Available optimization passes are:

NameDescriptionEnabled By Default
peepholePeephole postpassYes
branchBranch optimizationsYes
inlineInline method callsYes
cfoldConstant foldingYes
conspropConstant propagationYes
copypropCopy propagationYes
deadceDead code eliminationYes
linearsLinear scan global reg allocationYes
cmovConditional movesYes
sharedEmit per-domain codeNo<sup>1</sup>
schedInstruction schedulingNo
intrinsIntrinsic method implementationsYes
tailcTail recursion and tailcallsNo
loopLoop related optimizationsYes
fcmovFast x86 FP comparesNo
leafLeaf procedures and optimizationsNo
aotUsage of Ahead Of Time compiled codeYes
precompPrecompile all methods before executingNo<sup>1</sup>
abcremArray bound checks removalNo
ssapreSSA based Partial RedundancyNo
exceptionOptimize exception catch blocksYes
ssaUse plain SSA formNo
float32Use 32 bit float arithmetic if possibleNo<sup>2</sup>
sse2SSE2 instructions on x86No
gsharedvtGeneric sharing for valuetypesNo<sup>1</sup>
gsharedGeneric SharingYes
simdSimd intrinsicsYes
unsafeRemove bound checks and perform other dangerous changesNo<sup>1</sup>
alias-analysisAlias analysis of localsYes
aggressive-inliningAggressive InliningNo

<sup>1</sup> These optimizations are not enabled by all and must be specified manually.

<sup>2</sup> Enabled by default in Mono, disabled by default in Unity.