Chapter 5 Java Virtual Machines (Chapter Five: The Java Virtual Machine)

xiaoxiao2021-04-08  407

First, what is Java virtual machine

When you talk about the Java virtual machine, you may mean:

1. Abstract Java virtual machine specification

2, a specific Java virtual machine implementation

3, a running Java virtual machine instance

Second, the life cycle of Java virtual machine

A clear task has a clear task: Execute the Java program. When the program started to execute, he stopped at the end of the program. You run three programs on the same machine, there will be three Java virtual machines in run.

Java virtual machine always starts in a main () method, this method must be public, return VOID, directly by a string array. When execution is executed, you must indicate this type name of this encryption main () method to the Java virtual machine.

The main () method is the starting point of the program, and the thread he executed is initialized to the initial thread of the program. Other threads in the program are started by him. Threads in Java are divided into two: daemon and Non-daemon. The daemon is the thread it uses by the Java virtual machine. For example, the thread responsible for garbage collection is a daemon. Of course, you can also set your own program to a daemon. The initial thread containing the main () method is not a daemon.

As long as there is an ordinary thread in the Java virtual machine, the Java virtual machine will not stop. If there is enough permissions, you can call the exit () method termination program.

Third, Java virtual machine architecture

A series of subsystems, memory areas, data types, and usage guides are defined in the Java virtual machine specification. These components constitute an internal structure of the Java virtual machine, not only provides a clear internal structure for the implementation of Java virtual machines, but also strictly regulate external behavior implemented by Java virtual machines.

Each Java virtual machine is constructed by a class loader subsystem, which is responsible for the type (class and interface) in the plus program and gives the unique name. Each Java virtual machine has an execution engine (Execution Engine) responsible for executing instructions included in the loaded class.

The execution of the program requires a certain memory space, such as the bytecode, other additional information of the loaded class, the objects in the program, the parameters of the method, the return value, the local variable, the intermediate variable, the intermediate variable, and the like. The Java virtual machine is saved in the data area (Data Areas). Although the implementation of each Java virtual machine contains the data area, the Java virtual machine specification is very abstract. Many structural details have been left to the Java virtual machine implementation themselves. The memory structure in different Java virtual machines is very different. Part of the implementation may take up a lot of memory, while others may only occupy little memory; some implementations may use virtual memory, while others are not used. This comparison of refined Java virtual machine memory can make Java virtual machines can be implemented on a wide platform.

Part of the data area is the entire program, and other parts are controlled by separate threads. Each Java virtual machine contains Method Area and Heap, they are shared throughout the program. The Java virtual machine is loaded and parsed, and after saving the information parsed from the class file and the method area. The objects created when the program execute is saved in the heap.

When a thread is created, it is assigned to belong to his own PC register "PC Register" and Java Stack. When the thread does not drop the local method, the next instruction execution in the PC register is saved. The Java Stack holds a state when a thread modifier method, including the local variable, the parameter of the method, the return value, and the intermediate variable. Status When you call your local approach, you are saved in your local method stack, possibly register or other non-platform independent memory. The Java stack has a stack frame (or frames)). The stack block contains the status of the Java method called. When a thread calls a method, the Java virtual opportunity blocks a new block into the Java stack. When this method runs, the Java virtual opportunity will bring the corresponding block and abandon.

The Java virtual machine does not use the register to save the intermediate result, but use the Java stack in the middle result. This is a more compact of Java virtual machines, making it easier to implement Java virtual machines on a device without registers.

In the Java stack in the figure, the thread three in the PC register is gray because it is performing the local method, and his next execution instruction is not saved in the PC register.

Fourth, Data Types (Data Types)

All data used in all Java virtual machines have certain data types, data types, and operations are strictly defined in the Java virtual machine specification. The data type in Java is divided into the original data type (Primitive Types) and the reference data type. The reference type relies on the actual object, but it is not an object itself. The original data type does not depend on anything, they are the data represented by itself.

The original data type in all Java program languages ​​is the original data type of the Java virtual machine, except for Boolean. When the compiler compiles the Java source code to your own code, use an integer (INT) or byte (byte) to represent the Boolean. Using an integer 0 in the Java virtual machine, the Boolean FALSE is used, and the use of non-zero integer represents the Boolean TRUE, the Boolean array is represented as an array of bytes, although they may be saved in byte arrays or blocks. In the heap.

In addition to the Boolean, the original type in other Java languages ​​is the data type in the Java virtual machine. Data types in Java are divided into: shaped Byte, short, int, long; char and floating-point Float, Double. The data type in the Java language has the same range on any host.

There is also a ReturnValue that cannot be used in a Java language in a Java virtual machine. This type is used to implement "Finally Clauses" in the Java program, and see "Finally Clauses" in 18 chapters.

The reference type may be created as: Class Type, Interface Type, Array Type. They all refer to objects that are dynamically created. When the reference type references NULL, no object is not referenced.

The Java virtual machine specification only defines the range of each data type representation, and is not defined in the storage of space occupied by each type. How do they store themselves by the implementation of the Java virtual machine. See 14 "Floating Point Arithmetic" on floating point. TypeRange

BYTE8-BIT SIGNED TWO's Complement Integer (-27 to 27 - 1, inclusive)

Short16-bit Signed Two's Complement Integer (-215 to 215 - 1, Inclusive)

INT32-BIT SIGNED TWO's Complement Integer (-231 to 231 - 1, Inclusive)

Long64-bit Signed Two's Complement Integer (-263 to 263 - 1, inclusive)

Char16-bit unsigned Unicode Character (0 to 216 - 1, inclusive)

Float32-Bit IEEE 754 Single-Precision Float

Double64-Bit IEEE 754 Double-Precision Float

ReturnValueAddress of an opcode within the Same Method

ReferenceReference to an Object on the heap, or null

Five, byte length

The Minimal Data Unit (Word) in the Java virtual machine is defined by the implementation of the Java virtual machine. But a word size must be enough to accommodate Byte, Short, Int, CHAR, FLOAT, RETURNVALUE, and REFERENCE; two words must be sufficient to accommodate lonble. Therefore, the value of the virtual machine provides at least the word that is less than 31bits, but it is best to choose the most efficient word length on a particular platform.

At runtime, the Java program cannot determine the word length of the running machine. The word length does not affect the behavior of the program, he is just a way in the Java virtual machine.

Six, class loader subsystem

The class loader in the Java virtual machine is divided into two types: Primordial Class Loader and Class Loader Objects. The original loader is part of the Java virtual machine implementation, and the class loader object is part of the running program. The class loaded by different types of loaders is split by different namespaces.

The class loader calls many other parts of the Java virtual machine and many classes in the java.lang package. For example, the class load object is an instance of the java.lang.classloader subclass. The method in the ClassLoader class can access the class load mechanism in the virtual machine; each class loaded by the Java virtual machine will be represented as a java.lang.class Examples of classes. Like other objects, the class loader objects and Class objects are saved in the heap, and the loaded information is saved in the method area.

1, loading, connection, initialization (Linking and Initialization)

The class plus subsystem is not only responsible for positioning and loading class files, and he made a lot of other things in accordance with the following strict steps: (Specific information, "Class's Life Cycle" in Chapter 7)

1) Load: Find and import binary information of the specified type (class and interface)

2), connection: verification, preparation, and analysis

1 Verification: Ensure the correctness of the import type

2 Preparation: For the type allocation memory and initialize the default value 3 parsing: Resolution character reference to direct drink

3), initialization: call Java code, initialize the class variable as the right value

2, the primordager class loader

Each Java virtual machine must implement an original grade loader that can load those classes that follow the class file format and trusted. However, the Java virtual machine specification does not define how to load classes, which is determined by the Java virtual machine implementation. For the type of a given type name, the original loose loader must find the type of ".class" file and load into the virtual machine.

3, class loader object

Although the class loader object is part of the Java program, three methods in the ClassLoader class can access class plus load subsystems in the Java virtual machine.

1), protected final class defineclass (...): Using this method, you can enter a byte array to define a new type.

2) Protected class findsystemClass (String Name): Load the specified class, if you have loaded, return it directly.

3), protected final void resolveclass (class c): defineClass () method is just loaded, which is responsible for subsequent dynamic connection and initialization.

For details, see Chapter VII "Connecting Model".

4, namespace

When multiple type loaders loaded with the same class, in order to ensure the uniqueness of their name, you need to add the identity of the class loader that is loaded before the class name. For details, see Chapter VII "Connecting Model".

7. The Method Area is saved in the method area in the Java virtual machine. This write information is defined by the virtual machine's implementation, for example, the virtual machine works on a "Little-endian" processor, and he can save the information as "Little-Endian" format, though In the Java class file they are saved in the "BIG-Endian" format. The designer can store data with the representation of the most suitable representation of the machine to ensure that the program can be executed at the fastest speed. However, on a device with only small memory, the implementation of the virtual machine will not take a lot of memory.

All threads in the program share a method area, so the way to access the method area information must be threads. If you have two threads to load a class named Lava, it can only be allowed by a thread to load this class, and the other must wait.

When the program is running, the size of the method area is variable, and the program can be expanded at runtime. Some Java virtual machines can also be customized by parameters, the initial size, minimum, and maximum value of the method area.

The method area can also be collected by garbage. Because the internal authenticated loaders in the program are dynamically loaded, all classes may become a state in which unreferenced is unreference. When the class becomes this state, he can be collected by garbage. Unloaded classes include two states, one is true unloaded, and the other is the state of "unreferenced". See Lifetime of A Class in Chapter VII (The Lifetime of A Class).

1, type information (Type Information)

Each loaded type, saving the following information in the method area in the Java virtual machine:

1), the full name of the full quaalified name of the type 2), the full name of the type of parent type (unless there is no parent type, or the full-form java.lang.Object) (The Fully Qualified Name of the Typeís Direct SuperClass

3) Give a type or an interface (CLASS or NOT The Type IS A Class)

4) Type modifiers (public, private, protected, static, final, volatile, transient, etc.) (The Typeís Modifiers) ("THEPEIS Modifiers)

5), all of the list of all parent interfaces (An Ordered List of the Fully Qualified Names of any Direct Superinterfaces)

The data structure saved by the type of type is defined by the virtual machine implementator. In addition, the Java virtual machine also saves the following information for each type:

1), the type of constant pool (The Constant Pool for the Type)

2), information on the type field (Field Information)

3), information about the type method (Method Information)

4) All static variables (very quantity) information (all class (static) Variables Declared in Type, Except Constants

5) A reference to class classloader, a reference to class loader (A Reference to Class ClassLoader)

6) A reference to the class class (a reason to clas clas)

1), the type of constant pool (The Constant Pool for the Type)

All types in the constant pool are used in the orderly set of constant sets, including direct constants such as strings, integers, floating point numbers, and symbolic references to the type, field, method. Each saved constant in a constant pool has an index, just like the fields in the array. Because all types of types, fields, methods used in the constant pool are stored, the character reference is used, so it is also the main object of dynamic connection. See Chapter 6, "The Java Class File" for more information.

2), information on the type field (Field Information)

Field name, field type, Field modifier (public, private, private, maincted, static, finAl, volatile, transient, etc.), the field defines in the class.

3), information about the type method (Method Information)

Method name, method return value type (or void), the number of method parameters, the type, and their order, the form of the field (public, private, protected, static, final, volatile, transient, etc.), method is class The order in which it is defined, if not abstract and local this law, it needs to be saved.

The bytecode of the method, the size of the operand stack and the size of the local variable area (some details), exception list (see Chapter 17 "Exceptions" in detail.)

4), class (static) variables (Class Variables)

Class variables are shared by instances of all classes, even if they are not passed through the instance of the class. These variables are bound to the class (instead of an instance), so they are part of the logical data of the class. Before the Java virtual machine uses this class, you need to assign memory for the class variable (Non-final).

The processing of constants is different from Non-final. Each type is replicated into your own constant pool when you use a constant. The constant is also saved in the method area like class variables, but he is saved in a constant pool. (Probably, class variables are shared by all instances, and the constant pool is unique to each instance). Non-final class variables are saved to define a part of the Data for the Type That Declares the THEM, while the Final constant is saved as part of the Data for Any Type That Uses the THEM. See Chapter 6, "The Java Class Filethe Java Class File"

5), point to the reference to the class loader (a Reference to classLoader)

Each type loaded by Java virtual machines must save this type by the original loader or class loader. Those types loaded by the type of loader must save a reference to a class loader. This information is used when the class loader dynamically connects. When a class references another class, the virtual machine must save the referenced type is loaded by the same class loader, which is also the process of maintaining different deadline spaces. See Chapter VII "The Linking Model" for details.

6) Point to the reference to the Class class (a Reference to class class)

The Java virtual machine creates an instance of a java.lang.class class for each load type. You can also pass the Class class:

Public Static Class Forname (String ClassName) to find or load a class and obtain an instance of the corresponding Class class. With this example of this Class class, we can access information in the Java virtual machine method area. Specifically refer to the Class class Javadoc.

2, method list (Method Tables)

In order to access all data stored in the method area more effectively, the storage structure of these data must be carefully designed. In all method areas, in addition to the original information saved on the top, there is a data structure designed to speed up the speed, such as a list of methods. Each loaded non-abstract class, the Java virtual machine will generate a list of methods for them. In this list, this list is saved to all instance methods of this class, and the method of incorrect the parent class is called. See Chapter VII "The Linking Model" for details.

8. Heap When the Java program creates a class instance or array, allocate memory for new objects in the heap. There is only one pile in the virtual machine, and all threads share him. 1. Garbage Collection

Garbage collection is the main method that releases the object that is not referenced. It may also move the object to reduce the fragments of the heap. There is no strictly defined garbage collection in the Java virtual machine, just define a Java virtual machine implementation must manage your own stack in some way. See Chapter 9 "Garbage Collection" for details.

2, object storage structure (Object Repesentation)

There is no object in the Java virtual machine specification how to store it in the stack. Each object is mainly stored in his class and the object variable defined in the parent class. For references for a given object, the virtual machine must be tender to locate the data of this object. Also, it is necessary to provide a method of reference method data of an object, such as a reference to an object in the method area, and the data stored in one object is often contained in a certain form pointing to the pointer to the method area.

A possible stack is designed to be divided into two parts: reference pool and object pool. A reference to an object is a local pointer to the reference pool. The entries in each reference pool include two parts: pointing to the pointer of the object class data in the object pool and the pointer in the method area. This design can facilitate the finishing of Java virtual machine stacking. When a virtual machine moves an object in the object pool, you only need to modify the pointer address in the corresponding reference pool. However, each access object is required to handle twice. The following figure demonstrates the design of this pile. This design is demonstrated in the Heapoffish Applet in "Garbage Collection" in Chapter 9.

Another stack is designed: an object's reference is a batch pointer pointing to a bunch of data and points to the corresponding object. This design makes it easy to access objects, but the movement of the object is abnormally complex. The figure below shows this design.

When the program tries to convert an object to another, the virtual machine needs to determine whether this conversion is the type of this object, or his parent type. Similar things will be made when the program applies to instanceof statements. When the program calls an object's method, the virtual machine needs to perform dynamic binding, and he must determine which type of method called call. This also needs to do the above judgment.

Regardless of the design of the virtual machine implementation, he may save a similar method list for each object. Because he can improve the speed of the object method, it is very important to improve the performance of the virtual machine, but a similar data structure must be implemented in the specification of the virtual machine. This figure is described below. The figure shows all of the data structures associated with an object reference, including:

1), a pointer to type data

2) A list of methods for an object. The method list is a pointer array pointing to all possible modes. The method data includes three parts: the size of the operating code stack and the local variable area of ​​the stack; the method of the bytecode; the abnormal list.

Objects in each Java virtual machine must be associated with a Lock (Mutex) for synchronous multi-threads. At the same time, there is only one object to have the lock of this object. When a lock with this object, he can apply for this lock multiple times, but it must also release the corresponding number of locks to truly release this object lock. Many objects will not be locked throughout the life cycle, so this information only needs to be added when needed. Many Java virtual machines are implemented in the data of the object contain "lock data", just generate corresponding data when needed. In addition to the lock of the object, each object is also logically related to a "WAIT SET" implementation. Locking the grouped thread independently handles shared data, does not need to hinder other threads. "WAIT SET" help group threaded consequences completed the same goal. "WAIT SET" is often implemented through the WAIT () and Notify () methods of the Object class.

Garbage collection also requires information about whether objects in the heap are associated. The Java virtual machine specification indicates that garbage collects a Finalizer method running an object once, but allows the Finalizer method to retrieve this object. When this object is not quoted again, it is not necessary to call the Finalize method again. Therefore, the virtual machine also needs to save the Finalize method to run information. See "Garbage Collection" 3, Array Repesentation

In Java, an array is a full-meaning object, and he and the object are saved in the heap, there is a reference to the Class class instance. All the same dimensions and types of arrays have the same Class, and the length of the array does not consider. The name of the corresponding Class is expressed as dimensions and types. For example, a class of integer data is "[i", byte three-dimensional array Class name "[[[[[[b", two-dimensional object data Class "[[ljava.lang.object".

The multi-dimensional array is expressed as an array of arrays, as shown below:

The array must save the length, array data of the array in the heap, and reference to some object array type data. Through an array reference, the virtual machine should be able to obtain a length of an array, and can access specific data by indexing, and can call the object definition of Object. Object is the direct parent class of all data classes. See Chapter 6, "Class Files" for more information.

Nine, PC Register (The Program Counter)

Each thread will be created when executed is executed. The program counter has only one word command, so it can save a local pointer and ReturnValue. When the thread is executed, the address is stored in the program counter, which allows a local pointer, or the offset pointer starting from the method byte code. If the local method is executed, the value of the program counter is not defined.

Ten, Java Stack (THE JAVA STACK)

When a thread is started, the Java virtual opportunity creates a Java stack for him. The Java stack uses some discrete Frame recording threads. Java Virtual Machine Heap Java Stack has only two: pressing and popping up FRAMES.

The method being executed in the thread is called the current method, and the FRAME corresponding to the current method is called the current frame. Defining the class of the current method is called the current class, the current class constant pool is called the current constant pool.). When thread is executed, the Java virtual opportunity tracks the current class and the current constant pool. However, when the thread operation is saved in the frame, he only operates the data of the current frame.

When a thread calls a method, the virtual opportunity generates a new frame and press the Java stack of the thread. This new frame becomes the current frame. When the method is executed, he uses the parameters of the current frame save method, local variables, intermediate structures, and other data. There are two ways to exit: normal exit and abnormal launch. Regardless of the method, the Java virtual machine pops up and discards the frame of the method, and the frame of the previous method is changed to the current frame.

All data saved in the frame can only be included with its thread access, and threads cannot access data in the stack of other threads. Therefore, when accessing the local variable of the method, you don't need to consider multithreading synchronization.

In line with the method area, like a heap, the Java stack does not require a continuous memory space, which can be saved on a dispersed memory space or pile. The specific data and length of the stack have the implementation of the Java virtual machine to define itself. Some implementations may provide a method of performing a stack maximum and minimum value.

XI, the Stack Frame Stack Frame contains three parts: local variables, operands stack, and frame data. The size of the local variable and operand stack is a word (Word), and they have been determined in compilation. The size of frame data depends on different implementations. When a program calls a method, the virtual machine acquires the size of the local variable and the operand stack from the class data, creates a suitable size and frame, and then press in the Java stack.

1, local variables (Local variables)

Local variables are organized into an array from 0 count in the Java stack frame, and instructions take the corresponding value from the local variable zone by providing their index. INT, FLOAT, REFERENCE, RETurnValue accounts for one word, byte, short, char is converted into int, then stores, long and doubel two words.

The instruction acquires the value of long, doubel by providing the previous one in the two word index. For example, a value of a long is stored on index 3, 4, and the instruction can be obtained by 3 to obtain the value of this long type.

The local variable zone contains the parameters and local variables. The compiler puts the parameters of the method in front of the array in the order they declared. However, the compiler can arbitrarily arrange the local variables in the local variable array, or even two local variables can use an address, for example, when two local variables are in two unlatched areas, like circulating variables I, J .

Implementors of the virtual machine can use any structure to describe data in the local variable area, and do not define how LONG and Doubel are stored in the virtual machine specification.

2, operand stack (OPERAND STACK)

Like local variables, operand stacks are also organized as an array of words. However, it is not accessed by indexing like local variables, but through the PUSH and POP values. If a directive Push is a value to the stack, the next instruction can pop and use this value.

The operand stack is not directly accessed directly like the program counter, and the instruction can directly access the operand stack. The Java virtual machine is a stack based, not based on registers, because its instruction acquires operands from the stack, not in the registers. Of course, the instructions can also be removed from other places, such as operational code behind the instruction, or constant pool. However, Java virtual machine instructions are mainly from the operand that they need from the operand stack.

The Java virtual machine treats the operand stack as a work area, and many instructions will first post from the operand stack, and then the result push returns the operand stack. The instruction execution process of an Add is shown in the following figure: First execute iLoad_0 and iLoad_1 instructions will need to add two numbers, remove from the local method area, and push to the operand stack; then perform IADD instructions, now POP There are two values, add, and put the result PUSP into the operast stack; finally execute the iStore_2 instruction, POP results, assign a value to the local method area.

3, Frame Data)

Handling local variables and operating stacks, Java stack frames also include data required to support constant pools, methods return values ​​and exception distribution, they are saved in the frame data.

When the virtual opportunity uses instructions that point to the constant pool, the required information is accessed through the pointer to the constant zone in the frame data. As mentioned earlier, references in the constant zone are symbolic references at the beginning. Even when the virtual machine checks these references, they are also character references. So virtual machines need to convert this reference at this time.

When a method is returned normally, the virtual machine needs to rebuild the stack frame that calls this method. If the method is performed, there is a return value, the virtual machine needs to put this value of the PUSH invoice method in which an operand stack is used.

The virtual machine is also included in the frame data to deal with exception tables. The exception table defines a paragraph code that is protected by the CATCH statement. The individuals in each of the abnormal tables also contain the range of bytema that require protection, and the location of the bytecode that needs to be executed when the exception is captured. When a method throws an exception, the Java virtual machine is to use an exception table to determine how this exception is handled. If the virtual machine finds a matching catch, he will hand over the control to the CATCH statement. If you do not find a matching catch, the method will return to the process, then continue this process in the method. In addition to the above three applications, the frame data may also contain some information dependent on implementation, such as debugging information.

Twelve, local method stack

The local method area depends on the different implementation of the virtual machine. Implementors of the virtual machine can decide which mechanism to use to perform the local method.

Native Method Interface uses some form of local method stack.

Thirteen, executive engine

A Java virtual machine implementation is the execution engine. In the Java virtual machine specification, the execution engine is described as a series of instructions. For each directive, the specification describes what they should do, but not to say how to do it.

1, instruction set

The byte stream of one method in the Java virtual machine is a sequence of instructions. Each command is operated by one byte and an OPCode that may exist (Operands). Operation code indicates what is going to do, and the operand provides some additional information that can be required to execute this opcode. An abstract execution engine performs an instruction each time. This process occurs in each of the threads performed.

Sometimes the execution engine may encounter a command that needs to call the local method. In this case, the execution engine will try to call the local method, but when the local method returns, the execution engine will continue to perform the next one in the byte stream. instruction. The local method can also be seen as an expansion of the instruction set in the Java virtual machine.

Deciding that the next step is also part of the execution engine work. There are three ways to perform the engine to get the next instruction. Most instructions will perform instructions that follow him; some instructions like goto, return will determine their next instructions when they execute; when an instruction throws an exception, the execution engine determines the next one by matching the catch statement. The instructions that should be performed.

The platform independence, network mobility, and the design of the Java virtual machine instruction set. Platform independence is one of the main factors in the design of the instruction set. The stack-based structure allows the Java virtual machine to be implemented on more platforms. The smaller opcode, the compact structure makes the bytecode more efficiently using the network bandwidth. One-time byte code verification makes the NPC more secure without affecting too much performance.

2. Executive Technology

Many execution techniques can be used in the implementation of Java virtual machines: interpretation, timely compile (Just-in-Time Compiling), Hot-Spot Compiling, Native Execution In Silicon.

3, thread

The Java virtual machine specification defines a thread model for implementing on more platforms. A local thread can be utilized when a goal of the Java thread model. Using local threads allows threads in the Java program to be implemented simultaneously on multiprocessor machines.

One price of the Java thread model is thread priority, and a Java thread can run on 1-10 priority. 1 minimum, 10 highest. If the designer uses local threads, they may map these 10 priorities to local priorities. The Java virtual machine specification is only defined. The high-point priority thread can be some CPU time, and the low priority thread is clogged in all high priority threads, but it can also obtain some CPU time, but this is not guaranteed: low priority The thread can not obtain a certain CPU time when there is no clogging of the high priority thread. Therefore, if you need to cooperate between different threads, you must use "Synchronizatoin". Synchronization means two parts: Object Locking and thread wait, activation (Thread Wait and Notify). Object lock Help threads can not be disturbed by other threads. Thread waiting, activation can make different threads collaborate.

In the Java virtual machine specification, the Java thread is described as variables, main memory, and work memory. Each Java virtual machine has a master memory, and he contains variables for all programs: objects, and array class variables. Each thread has its own work memory, and he saves the copy of what he may use. rule:

1), from the value of the main memory copy variable to work memory

2) Write the value of the value in the work memory

If a variable is not synchronized, the thread may update the variables in the main memory in any order. In order to ensure the correct execution of multi-threaded programs, synchronization mechanisms must be used.

Fourteen, local method interface (Native Method Interface)

The implementation of the Java virtual machine is not necessary to implement the local method interface. Some implementations may not support local approaches at all. Sun's local method interface is JNI (Java Native Interface).

Fifteen, the real machine 16, mathematical method: Simulation (ETERNAL MATH: A Simulation)

转载请注明原文地址:https://www.9cbs.com/read-132866.html

New Post(0)