我有这段代码:RyuJIT C#错误和结果与/优化
private void AnswerToCe(int currentBlock, int totalBlock = 0)
{
byte[] bufferToSend;
byte[] macDst = mac;
byte[] macSrc = ConnectionManager.SInstance.GetMyMAC();
byte[] ethType;
byte[] header;
if (Function == FlashFunction.UPLOAD_APPL || Function == FlashFunction.UPLOAD_BITSTREAM)
{
ethType = BitConverter.GetBytes((ushort)EthType.ETH_TYPE_UPLOAD);
ethType = new byte[] { ethType[1], ethType[0] };
header = Header.GetBytes((ushort)binaryBlocks.Count, (ushort)(currentBlock + 1), (ushort)binaryBlocks[currentBlock].Length);
int index = 0;
bufferToSend = new byte[macDst.Length + macSrc.Length + ethType.Length + header.Length + binaryBlocks[currentBlock].Length];
Array.Copy(macDst, 0, bufferToSend, index, macDst.Length);
index += macDst.Length;
Array.Copy(macSrc, 0, bufferToSend, index, macSrc.Length);
index += macSrc.Length;
Logger.SInstance.Write(index.ToString(), "test index pre");
Array.Copy(ethType, 0, bufferToSend, index, ethType.Length);
index += ethType.Length;
Logger.SInstance.Write(index.ToString(), "test index post");
Array.Copy(header, 0, bufferToSend, index, header.Length);
index += header.Length;
Array.Copy(binaryBlocks[currentBlock], 0, bufferToSend, index, binaryBlocks[currentBlock].Length);
}
如果我建立我在调试模式下一切应用正常,test index pre
版画12和test index post
打印14.版本相同模式与Optimize code
未选中。如果我使用Optimize code
进行检测test index post
打印18而不是14.
如果我用替换index += 2;
,结果相同。似乎只有index++;index++;
正在工作。
我试过这个代码在一个空的应用程序和总结都没问题。
应用程序是多线程的,但这里并不存在并发性。
从DLL反编译的代码似乎没问题。
任何想法,为什么会发生这种情况?
编辑: 只有当应用程序编译为x64时才会发生。 x86是好的。
编辑3:构建ENV的一些信息:
Visual Studio的15.0.0 - RTW + 26228.4
框架4.7.02053
可以在框架4.6.2和4.7触发此问题。其他框架未经测试。
编辑5:new, smaller example project。不需要依赖关系。
编辑6:拆卸测试项目here。 (太长而无法发布)
“应用程序是多线程的,但这里没有并发性。”很难说,因为这只是你的代码的一部分,它使用了这个函数之外的一些变量。 –
https://msdn.microsoft.com/zh-cn/library/c151dt3s.aspx – StefanE
@PawełŁukasik断点仅击中一次。索引变量不是外部的。 – rmbq