コード例 #1
0
ファイル: JITExtensions.cs プロジェクト: jorik041/PowerUp
        ToAsm(this MethodInfo methodInfo, Action action)
        {
            RuntimeHelpers.PrepareMethod(methodInfo.MethodHandle);
            var decompiler = new JitCodeDecompiler();
            var decompiled = decompiler.DecompileMethod(methodInfo);

            int runCount   = 10_000_000;
            int checkCount = 100;

            for (int i = 0; i < checkCount; i++)
            {
                for (int n = 0; n < runCount; n++)
                {
                    action();
                }

                var decompiledAfter = decompiler.
                                      DecompileMethod(
                    decompiled.CodeAddress,
                    decompiled.CodeSize,
                    methodInfo.Name);

                if (decompiledAfter.CodeAddress != decompiled.CodeAddress)
                {
                    return(decompiled, decompiledAfter);
                }
            }

            return(decompiled, decompiled);
        }
コード例 #2
0
ファイル: JITExtensions.cs プロジェクト: jorik041/PowerUp
        /// <summary>
        /// Extracts native assembly code from method.
        /// This method will only provide a tier0 or optimizedTier (for loops) native assembly
        /// when JIT Tiered compilation is on.
        ///
        /// For optimized build you should build your project with:  <TieredCompilation>false</TieredCompilation>
        /// </summary>
        /// <param name="methodInfo"></param>
        /// <returns></returns>
        public static DecompiledMethod ToAsm(this MethodInfo methodInfo)
        {
            RuntimeHelpers.PrepareMethod(methodInfo.MethodHandle);
            var decompiler = new JitCodeDecompiler();
            var decompiled = decompiler.DecompileMethod(methodInfo);

            return(decompiled);
        }