Chapter 2 NGWS Runtime technical basis

Source: Internet
Author: User

Chapter 2 NGWS runtime technical basis

Now that you are fully impressed by C #, I want to give you a full picture of NGWS runtime. C # depends on the runtime provided by NGWS; therefore, it is necessary
Know how to work during runtime and the concepts behind it.
Therefore, this chapter is divided into two parts-they are the basis of all concepts and usage. Although the content of the two parts overlaps, it helps to deepen understanding of positive
Learning Concepts.

2.1 NGWS Runtime
NGWS and NGWS Runtime provide you with a Runtime environment. This runtime manages the Execution Code and provides services that make programming easier. As long as your
When the compiler supports such running, you will benefit from this Managed execution environment.
You can guess that the C # compiler supports NGWS runtime correctly, but not only does it support NGWS runtime, but it also supports VB and C ++. These are created during the runtime.
The code is called "managed code ). The following are the benefits your application has gained from NGWS runtime:

Cross-language integration (using general language specifications)
Automatic Memory Management (garbage collection)
Cross-language Exception Handling (uniform expansion)
Enhanced security (including type security)
Version support ("DLL hell" Terminator)
Simplified component Interaction Mode

Because NGWS runtime must provide all these benefits, the compiler must issue the Metafile along with the managed code. The metadata file describes the type in the code. It
It exists with your code (similar to PE-PE is a variable-bit execution file)
As you can see from many cross-language functions, NGWS runtime is mainly about tight integration
Extends SS multiple different programming languages ). This support allows you to derive a C # class from a VB object (my post
The article to be discussed ).
C # A feature programmers will like is that they don't have to worry about memory management-that is, they don't have to worry about notorious memory leaks. NGWS runtime Extraction
For memory management, when the life cycle of objects and variables ends (no longer referenced), the garbage collector releases them. I really like this feature, because
Memory Management has always been my heart disease.
You should be encouraged to configure a management application or component. Because the management application contains metadata files, NGWS runtime can use this information
Make sure that your application has the required versions. The obvious result is that, because your code does not depend on each other, it is rare to see
Interrupted.
The remainder of this chapter is divided into two parts, each of which discusses various aspects of NGWS runtime until your C # application can be executed.
1. Intermediate Language (IL) and metadata
2. Instant Compiler (just-in-time compliers)

2.1.1 intermediate language and metadata
The managed code generated by the C # compiler is not the original code, but it is the intermediate language (IL) code. This IL code becomes the subject of NGWS runtime.
Execution Process entry. The obvious advantage of IL code is that it is CPU-independent, which means that you must use a compiler on the target machine to convert the IL code.
Original code.
Although the IL code is generated by the compiler, it is not the only thing the compiler provides to the runtime. The compiler also generates metadata about your code.
More things about your code during runtime, such as definitions of various types, signatures of various types of members, and other data. Basically, metadata is type
Library, registry content, and other information used for COM. Even so, metadata is directly merged with the Execution Code and is not isolated.
Iland metadata are stored in files that extend the pegex format (the pegex is used in .exe and. dll files ). When such a PE file is loaded
Locate and separate the metadata and IL.
Before proceeding, I would like to give you a short directory of the existing IL commands. Although it is not a complete list and you do not need to memorize and understand it
It lists the knowledge bases you need for C # programs.

Arithmetic and logical operators
Control Flow
Direct Memory Access
Stack operations
Parameters and local variables
Stack allocation
Object Mode
Instance type value
Critical Section
Array
Classification position
Instant Compiler (JITters)

2.1.2 instant Compiler (JITters)
The managed code generated by C # or other compilers that can generate the managed code is the IL code. Although the IL code is encapsulated in a valid PE file
You still cannot execute it unless it is converted to the managed original code. This is the time when the NGWS runtime instant Compiler (also known as JITters) is amazing.
Why are you tired of compiling code in real time? 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.
The time when the code is translated into the CPU specification. This compilation will be more efficient, because some program segments have never been executed. For example, in my word processor, mail
The component merging function has never been compiled.
Technically, the entire processing process is as follows: when a type is loaded, the loader creates a stub and connects it to each type of party
Method. When a method is called for the first time, the stub gives the control to JIT. JIT compiles IL as the original code and points the pointer to the buffered original code.
The subsequent call will execute the original code. At some point, all the IL is converted into the original code, and the JITter is idle.
As I mentioned earlier, there are many JIT compilers. On Windows, NGWS runtime has three different JIT compilers.
JIT -- this is the default JIT compiler used by NGWS runtime. It is a back-end optimized compiler, which implements the number
Data Stream analysis, and a highly optimized managed original code is created as the output result. JIT can use non-strict IL instruction set encoding, but the required resources are very good.
View. The main limits are the memory footprint, the result working set, and the time consumed by optimization.
Economy JIT -- compared with the main JIT, EconJIT aims to convert IL into the managed original code at high speed. It allows buffering of the original code,
The output code is not as optimized (the code is small) as the code generated by the main JIT ). When the memory is insufficient, the advantages of the quick code generation solution will disappear. Abandon permanently
Useless JIT code, you can load a larger IL program into the code buffer. Because JIT compilation is fast, the execution speed is still fast.
PreJIT-although it is based on the main JIT, it operates more like a unified compiler. You have installed the NGWS component before it can run.
The IL code is compiled into the managed original code. Of course, the final result is faster loading time and faster application startup time (no more JIT compilation is required ).
In the listed JITters, there are two JITters at runtime. But how do you decide which JIT to use and how to use the memory? There is a name
The small application (jitman.exe) for the JIT compilation manager, which is stored in the bin directory under the ngws sdk installation directory. When the program is executed
Add the icon to the system task bar. Double-click the icon to open the program dialog box (see figure 2.1 ).

Figure 2.1 JIT compilation Manager allows you to set various performance options

Although it is a small dialog box, the options you select are quite powerful. Each option is described below.
Use Economy JIT only option -- if this check box is not selected, NGWS runtime uses the default normal JIT compiler. I have explained before
The difference between the two JITter types.
Max Code Pitch Overhead (%) option -- this setting is reserved only for the economy JIT. It controls the JIT compilation time and the percentage of code execution time. For example
If the specified domain value is exceeded, the Code buffer is expanded to shorten the time consumed by JIT compilation.
Limit Size of Code Cache option -- this option is not selected by default. If this option is not selected, the buffer will use the memory it can obtain. If you
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 holds JIT code. Although you can strictly limit this value
You should be careful not to exceed the maximum value suitable for this buffer zone. Otherwise, the JIT compilation of this method will fail.
Optimize For Size Option-tells the JIT compiler that the optimization is intended to make the code smaller than to execute faster. This setting is disabled by default.
.
Enable Concurrent GC [garbage collection] Option -- garbage collection (GC) runs in the user code thread by default. GC occurs
May notice a slight delay in response. To prevent this problem, open the current GC. Note that the current GC is slower than the standard GC, and it is only available in windows
2000 the time of writing is valid.
When using C # To create a project, you may have tried it using different settings. When you create a UI-intensive application, you will see the maximum number allowed for the current GC
Difference.

2.2 Virtual Object System (VOS)
So far, you have only seen how NGWS runtime works, but you do not know the technical background of NGWS and why it works like this. This section
It is about the NGWS Virtual Object System (VOS ).
Below

Related Article

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.