.NET MSIL:命令如何检测操作数的大小? [英] .NET MSIL: How commands detect size of operands?

查看:75
本文介绍了.NET MSIL:命令如何检测操作数的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSIL中有一个 add 命令,用于添加两个参数(从堆栈弹出,添加,压入堆栈)。如何知道它是否必须弹出2个字节或4或8个字节?

There is a single add command in MSIL to add two arguments (pop from stack, add, push into stack). How does it know whether it has to pop 2 bytes or 4 or 8 bytes?

在Java中,不同的字节码(fadd,dadd,iadd等)如何执行?他们在.NET中处理此问题?

In java different bytecodes (fadd, dadd, iadd, ...) but how do they handle this in .NET?

推荐答案

Java字节码经过优化,可以由解释器执行,早期的JVM还没有Hotspot 。 .NET msil从一开始就设计为始终保持不变,不需要为不同的操作数类型使用特殊的操作码。

Java bytecode was optimized to be executed by an interpreter, early JVMs did not have Hotspot yet. .NET msil was designed from day one to always be jitted, no special opcodes for different operand types were necessary.

抖动知道操作数从堆栈状态键入。任何将代码值压入堆栈的操作码都将指示类型。说一个Opcodes.Ldarg_0,抖动从方法签名中知道类型。在解释器中永远不需要跟踪堆栈状态,它会显着减慢代码执行速度,只需执行一次抖动即可。

The jitter knows the operand type from the stack state. Whatever opcode pushed a value onto the stack indicates the type as well. Say an Opcodes.Ldarg_0, the jitter knows the type from the method signature. Keeping track of the stack state is something you never want to have to do in an interpreter, it slows down code execution significantly, a jitter only has to do it once.

这篇关于.NET MSIL:命令如何检测操作数的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆