Reasons for implementing a cross-platform mechanism in the Java language

Source: Internet
Author: User

JVM (The history of Java Virtual machines):

(1) Sun Classic

    1. The classic JVM either interprets the execution with a pure interpreter, or executes with JIT compilation, and once JIT is compiled, the interpreter is no longer in effect
    2. If you use JIT-compiled code, JIT compiles each method, each line of code, and is JIT-compiled for code that runs only once and does not have compile value. Due to the pressure of the program response time, this stage of JIT dare not compile time-consuming optimization technology, so timely use of JIT output local code, his execution efficiency and C code there is a big gap. Be criticized "Java language is slow"

(2) Exact VM

    1. Exact VM enters the era of high-performance virtual machines and starts using compiler interpreter blending mode
    2. Exact VM uses precise memory management to determine what type of data is in memory. Eg: there is a number in memory 12345,EXACTVM can determine whether he is an int number, or a reference to a memory 12345 address. This precise memory management, when GC, can directly reclaim the reference type of data, less like the classic VM era GC when the data type lookup process

(3) Hotspot virtual machine

    1. Hot spot is a virtual machine used by the current JDK (1.4 later)
    2. Hot spot code probing technology: Use counter to find the most compiled value code, notify JIT to compile in the method unit. If the method is called frequently, the standard compilation is triggered, and if there are many loops in the method, the compiler action is replaced on the trigger stack.
    3. The hotspot does not have to wait for the local code output to execute the program, which reduces the immediate compilation pressure and facilitates the adoption of more code optimization techniques. Output high-quality operating system native code

How to achieve cross-platform performance:

(1). As we all know, there is a mechanism in the Java language that can be run on other platforms, regardless of the platform on which the code is written. Some languages, such as the language written under the Windows platform can not be run under the Linux system, this reason first from the platform of the mechanism.

What we call the platform is composed of CPU and operating system, there are many kinds of CPU, such as INTER,AMD and so on. These different brands of CPU use the instruction set. While the operating system is the interface software that acts as the interaction between the user and the computer, different operating systems support different CPUs, and in a strict sense, different operating systems support different CPU instruction sets. For example, both Windows and LIUNX support complex instruction sets for Intel and AMD, but do not support the thin instruction set used by PowerPC, and older Macs use PowerPC processors, so they cannot install Windows directly under a Mac. It was not until 05 that MAC switched to Intel's CPU to make it possible to install Windows under a Mac. But the problem comes, the original Mac operating system also only support PowerPC, on Intel also can not install, how to do? So Apple has to rewrite its Mac operating system to support this change. Finally, we want to know that different operating systems support different CPU instruction sets, and now Windows,liunx,mac,solaris supports both Intel and AMD CPU instruction sets.

(2). We generally say that language cross-platform is said to be compiled after the file cross-platform, not the source program cross-platform. In general, programs compiled by a particular compiler can only run on a specific platform. The Java compiler compiles files that are not machine language, but Unicode-based bytecode files (. Class). The bytecode file is then translated into a machine code under a specific platform and then run using a Java Virtual machine (JVM). That is, as long as the corresponding JVM is installed on different platforms, you can run the bytecode file and run the Java program we wrote. In this process, the Java program that we write does not make any changes, just through the JVM, the "middle layer" can be run on different platforms, and really achieve the "compile once, run everywhere" purpose. Therefore, running the Java program must have the support of the JVM, because the result of the compilation is not machine code, it must be re-translated by the JVM to execute. Even if you package a Java program as an executable file (for example,. exe), you still need the JVM's support.

Reasons for implementing a cross-platform mechanism in the Java language

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.