Java Virtual machines

Source: Internet
Author: User
Tags integer reference

One, what is Java Virtual machine

The Java Virtual machine is an imaginary machine that is implemented by software simulations on the actual computer. Java virtual machines have their own imagined hardware, such as processors, stacks, registers, and so on, but also has the corresponding instruction system.

1. Why use Java virtual machines?

A very important feature of the Java language is the independence of the platform. The use of Java virtual machines is the key to achieving this feature. In general, high-level languages need to be compiled into different target codes if they are to run on different platforms. When the Java language virtual machine is introduced, the Java language does not need to be recompiled when it runs on different platforms.

The Java Virtual machine masks information related to specific platforms, enabling the Java language compiler to generate only the object code (bytecode) that runs on the Java Virtual machine, which can be run unmodified on a variety of platforms. When executing bytecode, the Java Virtual Machine interprets the bytecode as a machine instruction execution on a specific platform.

2. Who needs to know about Java virtual machines

Java Virtual machines are the foundation of the Java language's underlying implementation, and people who are interested in the Java language should have a rough idea of the Java Virtual machine. This helps to understand some of the properties of the Java language and also helps with the Java language.

For software personnel who want to implement Java virtual machines on specific platforms, compiler authors of the Java language, and those who want to implement Java virtual machines with hardware chips, must have a deep understanding of the specifications of Java virtual machines.

In addition, if you want to extend the Java language, or compile other languages into the Java language bytecode, you also need to have a deep understanding of Java virtual machines.

Data types supported by 3.Java virtual machines

The basic data types for Java virtual machines that support the Java language are as follows:

Complement of BYTE://1 byte signed integer SHORT://2 byte signed integer complement INT://4 byte signed integer complement LONG://8 byte signed integer complement FLOAT://4 byte IEEE754 single precision floating-point number double:// 8-byte IEEE754 double-precision floating-point number char://2 byte unsigned Unicode character

Almost all Java type checking is done at compile time. Data of the original data type listed above need not be marked with hardware in Java execution. The byte Code (Directive) that operates on these raw data type data already indicates the data type of the operand, such as the Iadd, Ladd, Fadd, and Dadd directives, which add two numbers to their operand types, especially int, long, float, and double.

The virtual machine does not have a separate directive for a Boolean type. Boolean data is processed by an integer instruction, including an integer return. A Boolean array is processed with a byte array.

The virtual machine uses floating-point numbers in IEEE754 format. Older computers that do not support IEEE format can be very slow when running a Java numeric calculation program.

Other data types supported by virtual machines include:

object//a 4-byte reference to a Javaobject (object) Returnaddress//4 byte, used for jsr/ret/jsr-w/ret-w directives

Note: Java arrays are treated as object.

The specification of the virtual machine does not have any special requirements for the structure inside the object. In Sun's implementation, the reference to object is a handle that contains a pair of pointers: one pointer to the method table for that object, and the other to the data for that object.

Programs represented by the bytecode of Java virtual machines should comply with the type rules. The implementation of the Java Virtual machine should reject the execution of a byte code program that violates the type rules.

Java virtual machines can only run on machines with a 32-bit address space because of the limitations of bytecode definitions. But you can create a Java virtual machine that automatically converts the bytecode into 64-bit form.

As can be seen from the data types supported by Java virtual machines, Java's internal format for data types is strictly defined, which makes the implementation of various Java virtual machines the same as the interpretation of data, thus ensuring the Java platform-independent and portability.

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.