Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:02:40+00:00 2026-06-12T08:02:40+00:00

Per my understanding, both instance methods and static methods are treated same by CLR

  • 0

Per my understanding, both instance methods and static methods are treated same by CLR compiler and the IL code is JITted whenever the method is called first time. Today I had a discussion with my colleague and he told me that the static methods are not treated the same way as instance methods. i.e. Static methods are JITted as soon as the assembly is loaded into application domain whereas instance methods are JITted as they are called for the first time.

I am actually confused and do not see a reason as to why the static methods should be eagerly compiled by CLR? I understand about static constructors or finalizer methods of the Critical Finalizer Objects or when constrained execution regions are used. But if some class has a combination of static and instance methods, I am really not sure why all static methods would be JITted as soon as the assembly containing the class would be loaded into memory?

Please help me in understanding this behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:02:42+00:00Added an answer on June 12, 2026 at 8:02 am

    Looking at when the methods get JIT compiled using WinDbg/SOS shows that static methods are not compiled prior to calling them.

    Consider the following class:

    class SomeType
    {
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void InstanceMethod()
        {
            Console.WriteLine("instance");
        }
    
        [MethodImpl(MethodImplOptions.NoInlining)]
        public static void TypeMethod()
        {
            Console.WriteLine("type");
        }
    }
    

    I use the NoInlining option to prevent the compiler from inlining these methods in a release build.

    If I run a small app like below and attach the WinDbg I can observe when the methods get JIT compiled.

    var st = new SomeType();
    
    Console.WriteLine("attach");
    Console.ReadLine();
    
    Console.WriteLine("calling methods");
    st.InstanceMethod();
    SomeType.TypeMethod();
    
    Console.ReadLine();
    

    At the point of attach the method table for SomeType looks like this:

    0:004> !dumpmt -md 0041387c
    EEClass:         004114d4
    Module:          00412e94
    Name:            ConsoleApplication2.SomeType
    mdToken:         02000007
    File:                c:\temp\ConsoleApplication1\ConsoleApplication1\bin\Release\ConsoleApplication1.exe
    BaseSize:        0xc
    ComponentSize:   0x0
    Slots in VTable: 7
    Number of IFaces in IFaceMap: 0
    --------------------------------------
    MethodDesc Table
       Entry MethodDe    JIT Name
    6d374960 6d076728 PreJIT System.Object.ToString()
    6d368790 6d076730 PreJIT System.Object.Equals(System.Object)
    6d368360 6d076750 PreJIT System.Object.GetHashCode()
    6d3616f0 6d076764 PreJIT System.Object.Finalize()
    0041c035 00413874   NONE ConsoleApplication2.SomeType..ctor()
    0041c02d 0041385c   NONE ConsoleApplication2.SomeType.InstanceMethod()
    0041c031 00413868   NONE ConsoleApplication2.SomeType.TypeMethod()
    

    After the methods have been explicitly invoked it looks like this:

    0:007> !dumpmt -md 0041387c
    EEClass:         004114d4
    Module:          00412e94
    Name:            ConsoleApplication2.SomeType
    mdToken:         02000007
    File:            c:\temp\ConsoleApplication1\ConsoleApplication1\bin\Release\ConsoleApplication1.exe
    BaseSize:        0xc
    ComponentSize:   0x0
    Slots in VTable: 7
    Number of IFaces in IFaceMap: 0
    --------------------------------------
    MethodDesc Table
       Entry MethodDe    JIT Name
    6d374960 6d076728 PreJIT System.Object.ToString()
    6d368790 6d076730 PreJIT System.Object.Equals(System.Object)
    6d368360 6d076750 PreJIT System.Object.GetHashCode()
    6d3616f0 6d076764 PreJIT System.Object.Finalize()
    0041c035 00413874   NONE ConsoleApplication2.SomeType..ctor()
    004700e0 0041385c    JIT ConsoleApplication2.SomeType.InstanceMethod()
    00470110 00413868    JIT ConsoleApplication2.SomeType.TypeMethod()
    

    I.e. the methods are not JIT compiled until they are actually invoked.

    (For the record this was done on .NET 4.5)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've alway had trouble understanding the the documentation on how S3 methods are called,
As per my understanding for each and every local varible define in method 1
As per my understanding stateless session beans are used to code the business logic.
As per my understanding the following generic function in java: public static <T> T
As per my understanding there will be one jvm instance and one class loader
As per my understanding both Factory class and Spring DI follows the Dependency injection.
As per my understanding a lock is not released until the runtime completes the
Per the code below, I am getting the following message. I am fairly certain
As per http://www.w3schools.com/cssref/sel_last-child.asp When i am trying to apply :last-child for my code, the
As per Scott Meyers, to prevent repetition of code in the const version of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.