Behind C# compilations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    Behind C# compilations

    As I understand, initially we compile csharp code into intermediate
    language called IL, and then during runtime, only used parts, are
    compiled into the native code by CLR using JIT compiler, hence making
    the code portable on different OS with small executables.

    Question:

    When we build .dll or an executable, prior to running the code, does
    it only contain IL, and during the runtime it's parts compiled into
    the native machine code -- will this make make exe, dll, etc., bigger
    with introduction of native code? Where will native code reside?

    please explain the process, from compile to the runtime.


    Thanks
  • Duggi

    #2
    Re: Behind C# compilations

    On Sep 27, 11:15 am, puzzlecracker <ironsel2...@gm ail.comwrote:
    As I understand,  initially we compile csharp code into intermediate
    language called IL, and then during runtime, only used parts, are
    compiled into the native code by CLR using JIT compiler, hence making
    the code portable on different OS with small executables.
    >
    Question:
    >
    When we build .dll or an executable, prior to running the code, does
    it only contain IL, and during the runtime it's parts   compiled into
    the native machine code -- will this make  make exe, dll, etc., bigger
    with introduction of native code? Where will native code reside?
    >
    please  explain the process, from compile to the runtime.
    >
    Thanks
    Hi

    IMO, your undersnading was correct.
    and during the runtime it's parts compiled into
    the native machine code -- will this make make exe, dll, etc., bigger
    with introduction of native code? Where will native code reside?
    the IL is converted / compiled to native code and it would be part of
    executing proces... it(native code) would not get stored back to the
    assembly. so there is no question of growing dll or exe.
    >Where will native code reside?
    as far as my knowledge goes, its in volatile memory.

    -Cnu

    Comment

    • puzzlecracker

      #3
      Re: Behind C# compilations

      On Sep 27, 2:26 pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
      On Sep 27, 11:15 am, puzzlecracker <ironsel2...@gm ail.comwrote:
      >
      As I understand, initially we compile csharp code into intermediate
      language called IL, and then during runtime, only used parts, are
      compiled into the native code by CLR using JIT compiler, hence making
      the code portable on different OS with small executables.
      >
      Question:
      >
      When we build .dll or an executable, prior to running the code, does
      it only contain IL, and during the runtime it's parts compiled into
      the native machine code -- will this make make exe, dll, etc., bigger
      with introduction of native code? Where will native code reside?
      >
      please explain the process, from compile to the runtime.
      >
      Thanks
      >
      Hi
      >
      IMO, your undersnading was correct.
      >
      and during the runtime it's parts compiled into
      the native machine code -- will this make make exe, dll, etc., bigger
      with introduction of native code? Where will native code reside?
      >
      the IL is converted / compiled to native code and it would be part of
      executing proces... it(native code) would not get stored back to the
      assembly. so there is no question of growing dll or exe.
      >
      Where will native code reside?
      >
      as far as my knowledge goes, its in volatile memory.
      >
      -Cnu
      I see, how does manifest come into the picture?

      How does executable know what IL has been or needs to be built? Does
      build processes restarts upon application shutdown and restart? what
      if a different instance of the same application starts up - would the
      built parts be available?


      Thanks

      Comment

      • Peter Duniho

        #4
        Re: Behind C# compilations

        On Sat, 27 Sep 2008 11:34:17 -0700, puzzlecracker <ironsel2000@gm ail.com>
        wrote:
        I see, how does manifest come into the picture?
        >
        How does executable know what IL has been or needs to be built? Does
        build processes restarts upon application shutdown and restart? what
        if a different instance of the same application starts up - would the
        built parts be available?
        Not normally. In the default case, every time your application is run,
        methods are compiled as they are called. You can, however, use a tool
        called ngen.exe to precompile the code and save the results in the global
        assembly cache. Code that's there can be shared among multiple processes
        that need it.

        Pete

        Comment

        • Peter Duniho

          #5
          Re: Behind C# compilations

          On Sat, 27 Sep 2008 11:15:49 -0700, puzzlecracker <ironsel2000@gm ail.com>
          wrote:
          As I understand, initially we compile csharp code into intermediate
          language called IL, and then during runtime, only used parts, are
          compiled into the native code by CLR using JIT compiler, hence making
          the code portable on different OS with small executables.
          Small clarification: the main space savings involved is simply the fact
          that .NET programs can take advantage of the .NET Framework. On an
          implementation-for-implementation comparison, I don't think there's a
          significant difference between IL byte code and x86 (for example). But,
          because so much of the functionality of a program can be found in the .NET
          Framework itself, that doesn't need to be replicated in a program, which
          allows the program to be much smaller.
          Question:
          >
          When we build .dll or an executable, prior to running the code, does
          it only contain IL, and during the runtime it's parts compiled into
          the native machine code -- will this make make exe, dll, etc., bigger
          with introduction of native code? Where will native code reside?
          Inasmuch as you wind up having to load the IL first, and then generating
          the native code from that, sure...the overall memory footprint for the
          implemented functionality in your program will be larger for .NET than for
          native applications. Though, I would guess .NET is smart about not
          keeping IL around after it's been compiled to native, so hopefully such an
          increase in size is transient.

          That said, because of the issue I describe above, even with this
          additional overhead, most programs will enjoy a significant net size
          savings.
          please explain the process, from compile to the runtime.
          The short version is: your application has enough information in it to
          "bootstrap" .NET and get the compilation going. As methods are called, if
          they aren't compiled yet, the "just-in-time" compiler does just that.
          Eventually, you get to a point where the bulk of your code has been
          compiled to native and basically runs as a native program linked to the
          ..NET Framework, with the .NET runtime (the "common-language runtime", or
          CLR) providing a layer of services under the managed code that's running.

          For a detailed description of the process, I recommend the various
          articles available on the MSDN web site.

          Pete

          Comment

          • Pavel Minaev

            #6
            Re: Behind C# compilations

            On Sep 27, 10:34 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
            How does executable know what IL has been or needs to be built? Does
            build processes restarts upon application shutdown and restart? what
            if a different instance of the same application starts up - would the
            built parts be available?
            To elaborate a bit on how JITting is actually done in present versions
            of the CLR: vtable method entries point to stubs that invoke JIT, and
            rewrite the corresponding entry to point to JITted code.

            Comment

            Working...