Metadata to force. net

Source: Internet
Author: User
Metadata is the core soul of the. NET platform, July 7th, 2010 jzli Leave a comment Go to comments

Dear instructor Li! I attended the. Net Deep training that you gave to our company last year and read your translation:. NET FrameworkProgramThe design (revision) and Objective C # have benefited a lot and admire you as an excellent. Net technical expert. I have read the C # debate in the blog park a few days ago? In particular, one netizen, firelong, wrote several sensational posts and made many criticisms on. NET performance. This topic has aroused a lot of debate in our project team (most of whom have attended your training last year). I would like to hear what Mr. Li thinks about these points ?..........

It was originally replied to this friend by email, but it was written and found that it had been written for a long time. Finally, it was considered to log out as a blog post.

In fact, I did not intend to participate in such a debate because I had a lot of saliva posts and sentiment posts. I simply browsed it and found that all parties involved in the debate (firelong, jeffreyzhao, And. Net)CommunityIn the end, I was excited. Most of the words I spoke with emotion lost the most solid and basic technical principles. HoweverArticleIn addition to saliva, there are indeed some deep technical problems exposed-some even cross. net, and extend to a wider range of fields. However, it is a pity that they have been flooded and have not been discussed in depth. This is why I finally decided to write this article. I hope to discuss some technical issues that have been ignored and share them with you.

First, I want to repeat C? Article 2 of Series 2: performance issues of reflection and metadata. The main points of this article are as follows (and corresponding analysis is given ):
1. High Performance costs when using reflection
2. Even without reflection, metadata generated to support reflection has a high performance cost.

Therefore, the author has come out in "C and C ++ community, will C # repeat the same mistakes?" The conclusion of "deleting reflection" in this article. Regarding the performance issues caused by reflection and metadata, I think no one will deny them, but how bad is the performance issue? I may discuss it in another article later (some of the firelong articles are vague ).

In this article, I want to discuss whether C # will repeat the same mistakes? Article 2 of Series 2: performance issues of reflection and metadataA basic argument in the entire reasoning process: metadata in the. NET platform aims to support reflection.

On the basis of this argument, this article shows that "reflection is not commonly used. The metadata created to support reflection brings many performance problems. Therefore, deleting reflection does not require the creation of metadata, so that. NET will not suffer any performance loss (just like C and C ++ )".

Unfortunately, this basic argument is a big misunderstanding of the. NET platform. In other words, in the. NET platform, the existence of metadata is definitely not only support reflection. In fact, the support for reflection is only a small application of metadata, and metadata is the whole. NET platform is a core infrastructure, which is. NET platform has a wide range of applications, is.. NET platform.

Why? Only by starting from the context of the entire software age when. Net was created can we fully understand this point .. Before the creation of net, the software technology of the Windows platform has gone through the following stages: DDE, Ole, ActiveX/COM. The core goals of these technologies are:Reusability of software components-this is the core proposition of software development and the focus of software platform vendors.The reusability of software components has the following meanings:

1. Emphasize Binary-level multiplexing (Black Box multiplexing), insteadSource codeLevel multiplexing (white box multiplexing ).
For example, if I want to integrate the PDF Reader capabilities in my software, I don't need to find the source of the PDF Reader from Adobe.CodeInstead, ask adobe for a binary component that supports reading PDF-and use it through interfaces.
2. Emphasize the reuse between components created in multiple languages, rather than between components created in a single language.
For example, if I write an email sending and receiving component in C ++, it can be directly used in VB.

DDE, Ole, and ActiveX/COM are all about this goal. Com is a peak of these technological developments. However, the development of COM technology has exposed many problems. The first chapter of Don box in "essential. Net", "the CLR as a better com", has profound anatomy of COM.

First, to achieve the "Component Reuse" goal, there must be contracts to regulate various agreements between components and the execution environment, and between components and components. Com uses IDL or TLB as a component contract, but it has several deep-rooted disadvantages:

1. IDL/TLB standardizes physical semantics (such as V-Table offset, stack frame, parameter, data structure, alignment, and other memory details ), in addition, a subset Convention of C ++ is used.
2. The IDL/TLB Specification Description is separated from the component Code itself.
3. The IDL/TLB specifications are chaotic and fail to meet industry-specific standards (it is difficult for third parties to expand development)

Among them, the 3rd problem is caused by Microsoft's lack of consistent system planning for com-which can be solved in time. However, the problems at the first 1 and 2 points are the deep-rooted problems of COM, leading to various difficult-to-solve problems in the later stages of COM components-it is difficult to implement COM-oriented compilation in different languages, because it meets the Reuse Model of COM, it is often necessary to break the reuse defined in the language model. At the same time, it is difficult to maintain two sets of compilation models and reuse mechanisms in one language (the pain of Developing COM components in C ++, VB, Delphi, and other languages I believe many people will have a deep understanding ).

At this time, the well-known Java in-98 gave Microsoft a great inspiration. In particular, the metadata, Microsoft's technical elites found that metadata is the best component contract definition body. Metadata has the following outstanding features (these overcome the disadvantages of describing IDL/TLB by COM components ):

1. metadata describes the logical structure and does not involve any physical details (such as V-Table offset, stack frame, parameter, data structure, alignment, method address, and other physical details, it is not determined until it is loaded or executed on a specific platform. For example, the myclass: mymethod following the call command that is often seen in the Il code is the logical metadata, instead of the physical address of the specific method)
2. Metadata and component code are merged into a file (assembly) that contains component dependencies, versions, and other information.
3. Metadata has been systematically and carefully designed from the very beginning and is part of the CLI industry standard (facilitating third-party development of related applications)

These features make metadata ideal for contract specifications between. NET components and the execution environment (CLR), components and components (components without language development. In particular, at, the "metadata virtual logical attribute" enables component contracts to focus on the "logical semantic layer" rather than "physical implementation details ". A brief explanation:
1. Reuse of components and components is concentrated on the "logical semantic layer". For example, call myclass method mymethod in C1 method M1 and call myclass: mymethod in semantics. Or C1 class inherits C2 class: Class C1 extends C2 is expressed in semantics. Or call the virtual method: callvirt myclass: virtualmethod ....
2. the reuse of components and components is no longer entangled in "physical implementation details". For example, to call a method, you must know its entry point address, such as JMP 0 × 000688; inherit a class, it must be clear about its Field Layout and so on. To call the virtual method, you must be clear about the V-Table offset rules .....

Why is "contract focusing on logical semantics" better than "contract focusing on physical implementation details?

This will go back to the previous goal of "reusability of software components. To put it simply, if you want to achieve "reusability of software components (pay attention to binary and multi-language attributes)" and "focus on physical implementation details" for Compiler vendors in various languages, the requirements are too high. compiler vendors must coordinate the physical details of an execution body (V-Table offset, stack frame, parameter, data structure, alignment, method address, etc ..... All at once)-so many detailed requirements make it extremely difficult for everyone to coordinate-the disadvantages of COM in the later stage stem from this.

While "Focus on the logical semantic layer" to Achieve Component reusability, the execution bodies generated by each compiler vendor (that is. the Assembly in. Net) only needs to "use metadata to express the logic-Semantics reuse specification"-This greatly reduces the number of coordinated specifications of each compiler vendor, it is much easier to implement. It is not easy to have vulnerabilities in various details-because a large number of physical details are determined by CLR execution.

To sum up, the fundamental role of metadata is to support "Component reuse based on logical semantics"-which is the core goal of. Net to build a software development platform. Reflection is only a small derivative function of metadata, not a major function.

In fact, in addition to the core goal of "Component reuse based on logical semantics", metadata. NET platform also plays an important role (some are extension requirements of Component Reuse, such as JIT and cross-platform ):

1. Metadata is the basis for JIT compilation and cross-platform. Net implementation.
Note: Metadata is referenced in large numbers in the Il code. The methoddef metadata table stores the semantic information of a method. Many il commands are directly embedded with metadata tokens. JIT cannot be implemented without metadata.

2. Metadata is the basis for. Net to support garbage collection and GC.
Note: Metadata marks the reference relationship between objects. This is the key basis for GC to traverse object graphs (determining whether objects can be collected. Without metadata, GC will not know that 0x000688 is a pointer (need to continue traversing )? Or an integer (no need to continue traversing )?

3. Metadata is the basic information describing type contracts, identifiers, and specifications.
Note: The strongly-named assembly (described in metadata) uniquely identifies the component when the compiler was originally compiled, so that it does not lead to runtime counterfeiting or version tampering (that is, DLL hell problems)

4. Metadata is the basis for. Net management component security (runtime type check and component download)
Description: metadata tells the CLR execution environment the security boundary of a component to manage malicious code.

5. Metadata is the reference relationship for. Net management components and the basis for loading
Note: Metadata will tell a component which components (versions) need to be referenced )? This is the basis for component loading.

As you can see from this, metadata is the cornerstone of the. NET platform. Metadata for. Net platforms is like vitamins as for organisms. In other words, deleting reflection does not eliminate metadata. To eliminate metadata, the entire design foundation of the. NET platform (Component Reuse and other functions described above) will no longer exist.

Finally, I pointed out that "C # will repeat the same mistakes? The core argument in Series 2: performance issues of reflection and metadata is incorrect, not to refute firelong. We recommend that firelong, jeffreyzhao, and netizens in many technical fields involved in the debate (whether it's firelong, jeffreyzhao supporter or opponent) to drop the strange atmosphere of "winning or losing a fight, breaking points between high and low, instead, we come to some solid technical Reasoning Processes and believe they will make more sense.Technical CommunityGrowing!

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.