General understanding C #(24. Controlled execution environment)

Source: Internet
Author: User

24. Controlled execution environment

Comparing [C #/IL code/CLR] and [Java/bytecode/JVM] is inevitable and legitimate. I think the best way is to first figure out why these technologies are created.

Write programs in C and C ++. Generally, the source code is compiled into assembly language code, which can only run on a specific processor and a specific operating system. The compiler needs to know the target processor because different processor instruction sets are different. The compiler also needs to know the target operating system, because different operating systems have different basic C/C ++ concepts, such as how to execute work and how to implement memory allocation. C/C ++ has achieved great success (most of the software you use may be compiled in this way), but it also has its limitations:

L the program does not have rich interfaces to interact with other programs (Microsoft's COM was created to overcome this restriction)

L programs cannot be distributed across platforms

L The program cannot be restricted to execution in a secure operation sandbox

To solve these problems, Java adopts the Smalltalk method, which is compiled into bytecode and runs in a virtual machine. Before compilation, the bytecode maintains the basic structure of the program. This makes it possible for Java programs to interact with other programs. Bytecode is also machine-neutral, which means that the same class file can run on different platforms. Finally, the fact that Java does not have explicit memory operations (via pointers) makes it suitable for compiling "sandbox programs ".

The original virtual machine used an interpreter to convert bytecode commands into machine codes. However, this process is so slow that it is never attractive to performance-focused programmers. Today, most JVMs use the JIT compiler to basically compile machine code before the scope of the class framework and before the execution of the method body. Before running the program, it is also possible to convert the Java program into an assembly language, which can avoid the startup time and memory load of instant compilation. Compared with compiling a Visual C ++ program, this process does not need to remove the program dependency on the runtime. Java Runtime (this term is hidden under the term Java Virtual Machine) will process many crucial aspects of program execution, such as garbage collection and security management. The runtime is also considered as a controlled execution environment.

Although the term is vague and never used as an interpreter, the basic. NET model also uses the method described above .. The important improvement of NET will come from the improvement of IL's own design. The only way that Java can rival is to modify the bytecode specification to achieve strict compatibility. I don't want to discuss the details of these improvements. This should be left to some developers who know both bytecode and IL code. 99% of developers like me do not intend to study the IL code specification. Here we list some IL design decisions intended to improve bytecode:

L provides better type-neutral (helps implement the template );

L provide better language neutrality;

L always compiled into an assembly language before execution, never explained;

L can add additional declarative information to classes and methods. See 15. features;

Currently, CLR also provides support for multiple operating systems, and provides support for better JVM interconnectivity in other fields. See 26. interoperability.

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.