".NET Programming Pioneer C #" Chapter 2 Theoretical Basics - Public Language Operation Environment CHRISTOPH WILLE | 2001-9-1
Chapter II Theory Basic - Public Language Operation Environment Since you already have C # comprehensive impression, I also want you to know the full picture of NGWS Runtime. C # relies on the runtime provided by NGWS; therefore, it is necessary to know how to work at runtime and the concepts contained behind it. So, this chapter is divided into two parts - they are all concepts and use of the basis. Although the contents of the two are some overlap, it helps to deepen the understanding of the concept being learning. 2.1 NGWS Runtimengws and NGWS Runtime provide you with a runtime environment. This runtime manages execution code and provides services that make programming easier. As long as your compiler supports this runtime, you will benefit from this managed execution environment. You guess the C # compiler supports NGWS runtime is correct, but not only supports NGWS Runtime, VB, and C . These are called "managed code" for supporting runtime. The following is your application from the benefits of NGWS Runtime: Cross-language integration (through universal language specification) Automatic memory management (garbage collection) Cross-language exception handling (including type security) version support ("" DLL Hell "Terminator) Component Interaction Simplified Mode Because NGWS Runtime provides all these benefits, the compiler must send the meta file and the managed code. The type in the meta-file description code, it is with your code (similar to PE --- PE as a variable position) As you can see from many cross-language functions, NGWS Runtime is mainly about high integration. Integration Across Multiple Different Programming Languages. This support can reach the extent to which you have a C # class from a VB object (I will give an article to be discussed later). A function that C # programmers will like is that they don't have to worry about memory management - that is to say, don't worry about the notorious memory leak. NGWS Runtime provides memory management, and the garbage collector releases them when the life of the objects and variables (no longer referenced). I really like this feature, because memory management in COM has always been a piece of heart disease. You should encourage a management application or component. Because the management application contains metadata files, NGWS Runtime can take advantage of this information to ensure that your application has the various provisions it needs. The obvious effect produced is that because your code does not have the dependence, it is rare to interrupt. This chapter will be divided into two parts, and each part discusses all aspects of NGWS Runtime until your C # application can perform. 1. Intermediate Language (Intermediate Language, Abblast IL) and metadata 2, the Instant Compiler (JITERS) 2.1.1 Intermediate Language and Metadata Manufactured by the C # Compiler are not original Code, but it is an intermediate language (IL) code. This IL code itself becomes the entry of the managed execution process of NGWS Runtime. The obvious advantage of IL code is that it is a CPU, which means that you want to convert the IL code into the original code with a compiler on the target machine. Although the IL code is generated by the compiler, it is not something that the compiler is provided to the runtime. The compiler also produces metadata about your code, tells the runtime about more things about your code, such as various types of definitions, signs of various types, and other data. Basically, metadata is a type library, registry content, and other information for COM. Despite this, the metadata is also combined with the execution code, and is not in the location of the isolation. IL and metadata stored in a file extended in the PE format (PE format for .exe and .dll files). When such a PE file is loaded, position and separate the metadata and IL from the file when running.
Before further illustrate, I want to give your existing IL instructions short directory. Although it is not a full list, you don't need you to be familiar with, but it lists the knowledge base based on what you are necessary. Arithmetic and Logical Operators Control Stream Direct Memory Access Stack Operation Parameters and Local Variable Stack Assignment Object Mode Instance Type Value Critical Area Architective Position Instant Compiler (Jitters) 2.1 Implement Compiler (Jitters) by C # or other The managed code generated by the compiler of the managed code is the IL code. Although the IL code is packaged in an effective PE file, you still can't execute it unless it is converted into a managed original code. This is when the NGWS runtime instant compiler (also known as jitters) is a big show. Why do you feel more than instant compiled code? Why don't you compile the entire IL PE file into the original code? The answer is time - you need to compile the IL code to the code of the CPU specification. This compilation will be more efficient because some blocks have never been executed. For example, in my word processor, the mail merge function has never been compiled. As a result, all processing processes are as follows: When a type is loaded, the loader creates a stub and connects it to each type. When a method is called for the first time, the stub gives the control over the JIT. JIT compiles IL as the original code and points the stub pointer to the original code. Then the call will perform the original code. In some positions (At some point), all IL is converted into original code, and Jitter is idle. As I mentioned earlier, the JIT compiler has a lot, more than one. On the Windows platform, NGWS Runtime has 3 different JIT compilers. JIT - This is the JIT compiler used by NGWS Runtime default. It is a back end-optimized compiler, implements data flow analysis in the reception (UP Front), and created highly optimized managed original code as output results. JIT can use uncompected IL instruction sets, but the required resources will be considerable. The main limit is that the memory footprint, the resulting work set, and the time to implement the optimization. Compared to the main JIT, ECONJIT's goal is to convert the IL to the host code. It allows the original code generated to be buffered, but the output code is not optimized as the code generated by the primary JIT. When the memory is tight, the advantage of the fast code generation scheme will disapperse. By permanently abandon useless JIT-free code, you can load larger IL programs into the code buffer. Because JIT compilation is fast, the execution speed is still very fast. Prejit - Although it is based on the primary JIT, it is more like a prominent compiler. You have installed the NGWS component, which can run before you can compile the IL code into a managed original code. Of course, the final result is, faster load time and faster application start time (no more JIT compilation). In the Jitters listed, there are two Jitters when running. But how do you decide which JIT want to use, how do it use memory? There is a small application called "JIT Compile Manager", which is stored in the bin directory in the NGWS SDK installation directory. When the program is executed, it adds an icon to the system task bar and double-click the icon to open the program dialog (see Figure 2.1). Figure 2.1 JIT Compilation Manager Allows you to set up a variety of related performance options although it is a small dialog, you have chosen the option functionality is quite powerful. Each option will be described below. Use econojit Only Options - When the check box is not selected, NGWS Runtime uses the default normal JIT compiler. The difference between two Jitter has been explained earlier. Max Code Pitch Overhead (%) Option - This setting is only reserved to ECONJIT.
It controls the percentage of JIT compilation time and execution code time. If the set domain value is exceeded, the code buffer is expanded to shorten the time consumed by JIT compilation. Limit size of code cache option - This default is not selected. No choice This means means that the buffer will use the memory it can get. If you want to limit the buffer size, check this option, which will allow you to use the max size of cache (bytes) option. Max size of cache (bytes) option - Controls the maximum value of the buffer that accommodates the JIT code. Although you can limit this value very strictly, you should also be careful, you can't exceed the maximum of this buffer. Otherwise, the JIT compilation of the method will fail. Optimize for size option - telling the JIT compiler, optimized to make the code smaller rather than can be implemented faster. This setting is turned off by default. Enable Concurrent GC [Garbage Collection] Options - Garbage Collection (GC) runs in the thread of user code by default. When the GC occurs, it may notice that the response has a slight delay. To prevent this phenomenon, open the current GC. Note that the current GC is slower than the standard GC, which is only valid when writing on Windows 2000 (The Time of Writing). When you create an item with a C #, you may use different setup tests. When you create a UI-INTENSIVE application, you will see the maximum difference that allows the current GC. 2.2 Virtual Object System (VOS) So far, you only see how NGWS runtime work, but does not understand the technical background of it work and why it works like this. This section is about the NGWS virtual object system (VOS). The following is a rule of NGWS Runtime when forming a statement, use and management type model in VOS. The idea behind the VOS is to create a framework that cannot sacrifice performance when performing code, allowing cross-language integration and type security. The framework I mentioned is the basis of the runtime architecture. In order to help you know it better, I will tell it four areas. Understanding them is important when developing C # applications and components. VOS Type System - provides a rich type of system, which intends to support full implementation of comprehensive programming languages. Metadata - describes and references the type defined by the VOS type system. The permanent format of metadata is independent of the programming language, but metadata is used as an interchange mechanism (NTERCHANGE MECHANISM), which is between the tool and NGWS virtual execution system. Universal Language Normative (CLS) - CLS defines subsets of the type in VOS, which also define conventional usage. If a class library complies with the rule of CLS, it ensures that the class library can be used on all other programming languages that enable CLS. Virtual Execution System (VES) - This is a VOS real-time implementation. VES is responsible for loading and executing the program written as NGWS. These four parts form the NGWS Runtime architecture. Each portion is described in the following section. 2.2.1 VOS Type System VOS Type System provides a rich type of system, which is intended to support the full implementation of multiple programming languages. Therefore, VOS must support object-oriented language and process programming languages. There are now many types of approximate but a bit incompatible. Take the integer as an example, in VB, it is 16-bit long, and in C , it is 32 bits. There are more examples, especially in dates and times, and database data types. This incompatibility makes the application's creation and maintenance unnecessarily complex, especially when the program uses a variety of programming languages. Another problem is that because there is some difference between programming languages, you cannot reuse the types created in another language in a language. (COM solves this problem in part of the binary standard interface). Today's code reuse is definitely limited. The biggest obstacle to publishing applications is that the object model of various programming languages is not uniform. There is almost every aspect: event, attribute, permanent preservation (PERSISTENCE), etc.
VOS will change this phenomenon. VOS defines the type of description value and specifies a contract that must be supported by all values of the type. There are two values and objects due to the supported object-oriented and process programming languages mentioned earlier. For values, the type is stored in the representation, and the same operation is also implemented. The object is more powerful because it explicitly in the expression. Each object has an identification number distinguished from other objects. Supports different VOS types in Chapter 4, "C # Type". 2.2.2 Metadata Although metadata is used to describe and reference the type defined by the VOS type system, it cannot lock to this single goal. When you write a program, by using the type declaration, you declare the type (assuming that they are numeric or reference types) is introduced to the NGWS Runtime type system. Type declarations are described in metadata stored inside the PE executable file. Basically, metadata is used for various tasks: the information used to represent the NGWS runtime use, such as positioning and loading classes, these classes in memory, resolve calls, translation IL is the original code, strengthen security and set up the context boundary . You don't have to care about the generation of metadata. Metadata is generated by C # "Code-to-IL Compiler, not JIT compiler). The code transfer IL compiler sends binary metadata information to the PE file, which is sent in a standard manner, which is not like the C compiler, and creates their own modified names for the exit function. The main advantages you obtained from metadata and executable code are, the same type of information is fixed with type, which will not spread a lot. It also helps to solve the problem that exists in CoM. Further, you can use a different repository in the same context, because the library is not only registered reference, but also included in the executable code. 2.2.3 Universal Language Normative General Language Normative (CLS) is not a virtual object system (VOS) true part, it is special. CLS defines a subset in VOS, which also defines conventional usage that must comply with CLS. So what is confused about this? If a class library complies with CLS rules, other programming languages also follow CLS rules, then other programming languages can also use the class library. CLS is an interactive operability of the language (Interoperability). Therefore, conventional usage must only follow external accessible items such as methods, attributes, and events, and more. The advantage of what I have described is that you can do the following. Write a component with C #, derived it in VB, because the functionality added in VB is so powerful, derived from the VB class again in C #. As long as all external accessible items follow the CLS rules, it is feasible. I don't care about the CLS protocol in this book. But when building your class library, you should pay attention to the CLS protocol. I have provided Table 2.1 to define an agreement rule for the type and external accessible item. This list is incomplete. It contains only some important projects. I don't point out that there is a CLS agreement that appears in this book, so there is a good idea: When you look for a CLS protocol, you should at least use it to see which features are valid. Don't worry that you are not familiar with every meaning in this chapter, you will learn them in this book. Table 2.1 The type and function of the Function Language specification BoolCharbyteshortintlongfloatDoubleStringObject (all objects) Arrays arrays must be known (> = 1), and the minimum score must be 0. Feature Types must be a CLS type. Type (Types) can be abstract or hidden. Zero or more interfaces can be implemented. Different interfaces allow for a way to have the same name and signature. A type can be derived accurately from a type. Allow members to be covered and hidden. There can be zero or more members, they are fields (Fields), methods, events, or types. Types can have zero or more constructor.
One type of accessibility can be a public or for NGWS », it is part of it; however, only public members can think of a part of the type interface. All value types must be inherited from system value type. An exception is an enumeration - it must inherit from system enum. Type member type members allow hidden or override other members in another type. The types of parameters and return values must be a CLS protocol type. Constructor, methods, and attributes can be overloaded. A type can have abstract members, but only when the type is not packaged. One method can be static, virtual, or instances. Virtual and instance methods can be abstract or one implementation. The static method must always have an implementation. The virtual method may be the last (or not). Field (fields) can be static or non-static. Static fields can be described or only initialized. Attributes can be disclosed when obtaining and setting methods rather than using attribute syntax. The first parameter of the returned type and setting method must be the same CLS type-attribute type. Attribute names must be different, different attribute types are used to distinguish it is not sufficient. Since the use method implements attribute access, if PropertyName is a property defined in the same class, you cannot realize how to name Get_PropertyName and SET_PROPERTYNAME. Properties can be indexed. Property Access must follow this name format: get_proname, set_propname. Enumerations emphasizes the type must be byte, short, int or long. Each member is an enumerated type of static description field. An enumeration cannot implement any interface. You allow multiple fields to set the same value. An enumeration must inherit the system enumeration (implied in C #) exception can be triggered and captured. Custom exception must inherit the system anomaly. Interfaces require other interfaces. An interface can define attributes, events, and virtual methods. The implementation depends on the derived class. Event increase and cancellation methods must be provided or not, each method uses a parameter, which is a class that is derived from the system delegate. Custom properties can be used only more types: Type, CHAR, CHAR, BOOL, BYTE, SHORT, INT, Long, Float, Double, ENUM (a CLS type), And Object. Representative Yuan (Delegates) The first letter of an identifier that is created and activated Identifiers must come from a restricted set. By size in a single range, it is impossible to uniquely distinguish two or more identifiers (case insensitive). 2.2.4 Virtual Execution System (VES) Virtual Execution System implements a virtual object system. Create VES by implementing an execution engine responsible for NGWS Runtime (Execution Engine, Abblast EE). This execution engine performs your application you write and compile with C #. The following components are part of VES. 1. Intermediate Language (IL) - is designed to be easily compatible with a variety of compilers. In addition to this frame, both C , VB, and C # compilers can generate IL. 2, load the managed code - this includes resolving the names in memory, laying out classes, and creates the stub necessary for JIT compilation. By performing a regular check, including strengthening some access rules, the type loader also enhances security. 3, use JIT conversion IL into the original code - IL code is not designed to become a traditional interpretation byte code or tree code, IL conversion is a true compilation. 4, load metadata, check type security, and method of integrity 5, garbage collection (GC) and exception processing - both are based on stack formats. The managed code allows you to dynamically track the stack. To dynamically identify each stack framework, Jitter or other compiler must provide a code manager. 6, depicting and checking the wrong service - both depend on the information generated by the source language compiler. Two mappings must be issued: a mapping from the source language structure to the address in the instruction stream, a mapping from the address to the position of the stack frame. These mappings are recalculated when the conversion from IL to the original code is performed.