开发者

Does managed code mean JIT or GC?

I've seen several explanations on what "managed" code means, and some target the idea of managed code being compiled to an intermediate language and JITed and others talk about GC and memory management. Which actually makes a language managed, or is it both or neither?

The answer of GC makes a lot of sense since the memory is managed (henced "managed code"), but couldn't there hypothetically be a language that has GC开发者_StackOverflow社区 but is native (not compiled to IL). Are GC and IL code somehow tightly coupled?


No, I would not say the the GC and IL are tightly coupled. In fact, one can exist without the other - and sometimes that is the case.

IL's major purpose is to make it platform agnostic, and to allow the JIT to make very specific optimizations that depend on the platform. For example, x86, x64, ARM, etc. The JIT's purpose is to turn that IL into native machine code for the architecture, and optimize it correctly.

You couldn't optimize for x86 and ARM because the platforms are too different. That's why there is a JIT for each specific platform. The JIT has the luxury of knowing what platform it's going to run against. As a code author, you may not know.

GC on the otherhand is about memory management. There are plenty of Garbage Collector libraries for software that does not compile to an intermediate language. Take for example this one, which is small but gets the job done. There have been plenty of papers on the subject as well.

It is possible for one to exist without the other, that's just not how we see it very often.

So what makes a "managed" language? To me, it means there is a virtual machine of some type involved. In .NET's case, the CLR. It provides various services, such as GC, Jit, Code Access Security (CAS), etc.


http://en.wikipedia.org/wiki/Managed_code

This makes it pretty clear that its the code that is managed (by running under a virtual machine), and not the memory.


Managed code means it is run by a virtual runtime machine and typically implies memory management. This is what people mean when they say "managed code". System resources (such as memory allocation) are managed for you among a few other things.

JIT has nothing to do with it. JIT is a feature of some virtual runtime machines but not a requirement. Visual Basic 6 uses a runtime but not JIT - it is interpreted line by line. JIT compiles a unit of code at the time of invocation. A .NET language, however, will use the .NET runtime which implements JIT compilation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜