2

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 but is native (not compiled to IL). Are GC and IL code somehow tightly coupled?

user67457
  • 43
  • 3
  • The presence of a JIT compiler is an implementation detail (it doesn't matter to the run program's semantics, save perhaps undefined behaviour and bugs in the JIT). *Technically*, the same applies to whether code is compiled to bytecode or to native code, though it's far less likely to change during the lifetime of an implementation, and for many languages is even consistent among most or all implementations. –  Sep 27 '11 at 16:34

3 Answers3

2

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.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
1

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.

P.T.
  • 24,557
  • 7
  • 64
  • 95
1

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.

Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119