[Java Virtual Machine Structure (Part 1) runtime data Zone] Abstract: Java Virtual Machine

Source: Internet
Author: User

[Java Virtual Machine Structure (Part 1) runtime data Zone] Abstract: Java Virtual Machine

Java virtual machine specification (Java SE 7) Author: Tim Lindholm, Frank Yellin, Gilad Bracha, Alex Buckley Abstract: Chapter 2 Java Virtual Machine Structure (Part 1)

This specification describes the act of an abstract virtual machine, rather than any widely used virtual machine.

2.5 runtime data Zone

The Java Virtual Machine defines several data partitions used during the running of the program, some of which will be created as the virtual machine starts and destroyed as the Virtual Machine exits. Others correspond to the threads one by one. The data areas corresponding to the threads will be created and destroyed as the threads start and end.

2.5.1 PC register

Each Java Virtual Machine thread has its own PC (Program Counter) Register.

The PC register capacity should be able to store at least one returnAddress type data or a platform-related local pointer value.

  • If a non-native method is being executed by a thread, the register will save the address of the bytecode instruction being executed by the Java Virtual Machine.
  • If this method is native, the PC register value is undefined.
2.5.2 Java Virtual Machine Stack

Each Java Virtual Machine thread has its own private Java Virtual Machine stack (Java Virtual Machine)Stack), This stack is created together with the thread to store stack frames.

Java Virtual Machine Stack: used to store local variables and some process results. In addition, it also plays an important role in method calls and responses.

In addition to the stack frames, the Java Virtual Machine stack will not be affected by other factors, so Stack frames can be allocated in the stack.

The memory used by the Java Virtual Machine stack does not need to be continuous.

2.5.3 Java heap

In the Java virtual machine (HeapIs the runtime memory area that can be shared by each thread, and is also the area where memory is allocated for all class instances and array objects.

The Java heap is created when the VM is started. It stores (Garbage CollectorManagement Objects. These managed objects do not need to be explicitly destroyed.

2.5.4 Method Area

The Method Area is the runtime memory Area that can be shared by each thread.

The method area stores the structure information of each class, such as the Runtime Constant Pool), field and method data, constructor and common method bytecode content, also includes some special methods used in class, instance, interface Initialization

The method area is created when the VM is started, although the Method Area isLogical composition of heapBut you can choose not to implement garbage collection in this area for Simple Virtual Machine implementation.

2.5.5 runtime constant pool

Runtime frequent volume pool: The runtime representation of every constant pool of classes or interfaces, including methods or field references that can be obtained only after parsing at runtime from the literal volume of values known during compilation.

Each runtime pool is allocated to the Java Virtual MachineMethod AreaWhen classes and interfaces are loaded to virtual machines, the corresponding runtime constant pool is created.

2.5.6 local method Stack

Java Virtual Machine implementation may use the traditional Stack to support native Method execution. This Stack is a local Method Stack ).

If the local method stack is supported, the stack is generally allocated by thread when the thread is created.



Detailed explanation of Java Virtual Machine?

1 Java technology and Java Virtual Machine
Speaking of Java, people first think of Java programming language. However, Java is actually a technology, which consists of four aspects: java programming language, Java file format, Java Virtual Machine and Java application interface (Java API ). Shows the relationship between them:

Figure 1 Relationship between four aspects of Java
The runtime environment represents the Java platform. Developers compile Java code (. java file) and compile it into bytecode (. class file ). The final bytecode is loaded into the memory. Once the bytecode enters the virtual machine, it will be interpreted and executed by the interpreter, or converted to the machine code by the real-time code generator. We can also see that the Java platform is built by the Java Virtual Machine and Java application interface, and the Java language is the channel to this platform. programs compiled and compiled in Java can run on this platform. Shows the structure of the Platform:

In the structure of the Java platform, it can be seen that the Java Virtual Machine (JVM) is at the core position and is the key for programs to be irrelevant to the underlying operating system and hardware. Below it is A porting interface, which consists of an adapter and a Java operating system. The platform-dependent part is called an adapter; JVM is implemented on a specific platform and operating system by porting interfaces. Above the JVM is the basic Java class library, extended class library, and their APIs, applications and applets compiled using Java APIs can run on any Java platform without considering the underlying platform) java platform independence is achieved by separating programs from operating systems.
So what is a Java Virtual Machine (JVM? When we talk about JVM, we may mean:
Abstract description of JVM specifications;

Specific implementation of JVM;

A jvm instance generated during the running of the program.
Abstract descriptions of JVM specifications are a collection of concepts that have been described in detail in The book The Java Virtual Machine Specification (Java Virtual Machine specifications; the specific implementation of JVM is either software or a combination of software and hardware, which has been implemented by many manufacturers and coexist on multiple platforms; java program running tasks are undertaken by a single JVM runtime instance. The Java Virtual Machine (JVM) discussed in this article is mainly applicable to the third scenario. It can be regarded as an imaginary machine, which is realized through software simulation on an actual computer. It has its own imaginary hardware, such as the processor, stack, and register, you can also use your own command system.
JVM has a clear task in its life cycle, that is, to run Java programs. Therefore, when a Java program is started, an instance of JVM is generated. When the program runs, the instance also disappears. Next we will conduct a more in-depth study on the JVM architecture and its running process.
2 architecture of Java Virtual Machine
As mentioned earlier, JVM can be implemented by different vendors. Due to vendor differences, the implementation of JVM is different. However, JVM can still implement cross-platform features, thanks to the architecture during JVM design.
We know that the behavior of a JVM instance is not only about itself, but also about its subsystems, storage areas, data types, and commands, they describe an abstract internal architecture of JVM. The purpose is not only to specify the internal architecture when JVM is implemented, but also to provide a way, it is used to strictly define external behaviors during implementation. Each JVM has two mechanisms: one is to load a class (class or interface) with the appropriate name, called the class loading subsystem; the other one is responsible for executing commands contained in loaded classes or interfaces, called the running engine. Each JVM also includes five parts: Method Area, heap, Java stack, program counter, and local method stack. The architecture of these parts is composed of the class loader and running engine mechanism:
... The remaining full text>


Working principle of Java Virtual Machine

Java Virtual Machine
1. What is a Java Virtual Machine?

A Java virtual machine is an imaginary machine that is simulated by software on an actual computer. The Java Virtual Machine has its own hardware, such as the processor, stack, and register. It also has the corresponding command system.

1. Why should I use a Java Virtual Machine?

A very important feature of Java is its independence from the platform. The use of Java virtual machines is the key to achieving this feature. General advanced languages must at least compile different target codes to run on different platforms. After the Java Virtual Machine is introduced, the Java language does not need to be re-compiled when running on different platforms. Java language usage mode: the Java Virtual Machine shields information related to specific platforms, so that the Java language compiler only needs to generate the target code (bytecode) that runs on the Java Virtual Machine ), it can be run on multiple platforms without modification. When executing the bytecode, the Java Virtual Machine interprets the bytecode as a machine instruction execution on a specific platform.

2. Who needs to know about the Java Virtual Machine?

Java Virtual Machine (VM) is the underlying implementation basis of the Java language. Anyone interested in the Java language should have a general understanding of the Java Virtual Machine. This helps you understand the nature of Java and the use of Java. For software developers who want to implement Java virtual machines on a specific platform, compiler authors of Java language and those who want to implement Java virtual machines using hardware chips, they must have a deep understanding of the specifications of Java virtual machines. In addition, if you want to expand the Java language or compile other languages into the bytecode of the Java language, you also need to have a deep understanding of the Java Virtual Machine.

3. Data Types supported by Java Virtual Machine

Java Virtual Machine supports the following basic data types:

Byte: // complement of a signed integer in 1 byte
Short: // 2byte 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 checks are completed at compilation. The raw data types listed above do not need to be marked with hardware during Java execution. * The bytecode (Instruction) used for the raw data type has already pointed out * the Data Type of the number. For example, the iadd, ladd, fadd, and dadd commands add the two numbers, its * operation types are int, long, float, and double. The VM does not set separate commands for the boolean type. Boolean data is processed by integer commands, including integer return. Boolean arrays are processed using byte arrays. The VM uses a floating point number in IEEE754 format. Older computers in IEEE format are not supported. It may be very slow when running Java numeric computing programs.

Other data types supported by virtual machines include:
Object // 4-byte reference to a Javaobject
ReturnAddress // 4 bytes for the jsr/ret/jsr-w/ret-w command
Note: Java arrays are processed as objects.

The specifications of virtual machines have no special requirements on the internal structure of objects. In Sun's implementation, an object reference is a handle, which contains a pair of pointers: one pointer points to the object's method table, and the other points to the object's data. Programs represented by bytecode of Java virtual machines should comply with Type rules. Java Virtual Machine implementation should reject the execution of bytecode programs that violate the type regulations. The Java Virtual Machine can only run on 32-bit address space machines due to the bytecode definition restrictions. However, you can create a Jav ...... the remaining full text>

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.