[CLR via C # 3rd Reading Notes] 4.4 how things relate at runtime

Source: Internet
Author: User

Before JIT

When CLR calls a method for the first time, the JIT code is required first.

Previously, the CLR was required to ensure that all required assemblies can be loaded successfully. If load succeeds, CLR will use metadata in Assembly to create the type itself (type object) to be used on the managed stack)

The structure of the type object, which consists of two parts:

The first part includes the type object pointer, the sync block index (all objects on the managed stack will have these two fields), and the static filed defined by this type.

The second part is the method table defined by the type (including the static method)

Then start JIT

Runtime

After JIT, you can start execution.

First, execute prologue code (almost all methods are available). The local variable is allocated memory on the stack and initialized to null or 0.

Run

When you need to create an object

Create on managed stacks, including type object pointer, sync block index, and instance Field

Next, point the type object pointer to the created type object, initialize the sync block index and the instance field is null or 0, and then call the constructor.

After the preceding steps, the new operator returns the address of the object on the managed stack.

When the static method is called

The JIT compiler finds the method entry in the method table of the type object, and runs the JIT method (if required)

When a non-virtual instance method is called

The JIT compiler tries to find the method table entry of the type object. If the entry cannot be found along the inheritance tree of the object to the parent class, it will execute

When you call a virtual instance method

At this time, the JIT compiler will execute some additional code (this method will be executed every time it is called). First, find the object of the caller on the hosting stack, and its type object pointer locates the caller's type object, and then continues to find the method entry balabala.

Finally, execute the epilogue code (almost all methods are available) and perform some cleanup.

At the beginning of the process


CLR will immediately create a system in the managed heap. type object (whose type Object Pointer Points to itself). All the type object pointers created at runtime point to this system. type type object

In fact, the object. GetType method returns the address stored in the type object pointer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.