Java virtual machine learning notes

xiaoxiao2021-03-06  19

1. Compilation order: Compiler virtual machine virtual machine Java source file * .java ------> byte code * .class ------> Type loader ---> Execute Engine one .class The file can only contain one class or interface. Therefore, how many classes are defined in .java files, how much .class files (internal classes are not counted) when compiling. 2. Java program can choose to access the underlying system in two ways, select: (1). Call the JavaAPI through the Java program to call the local method, access the underlying system, and the platform is independent. (2). Directly call the local method through the Java program, access the underlying system and the platform. The method of the operating system is provided by the local method. 3. Classically loader: Loading a Java compiler compiled bytecode * .Class and Java API bytecode to method area. Java has two types of loaders: (1). Startup type loader: The system is unique, part of the virtual machine, written in a specific language (communication with the virtual body layer language), mainly to load the core class library . (2). User-defined class loader: There can be any plurality, write with Java, part of the Java application, can be compiled into a zona code and is loaded by the virtual machine. A loader loads a class and its class call, allowing them to interconnect and form a name space (Name Space), each of which corresponds to a namespace. That is, the principle of name space in Java. The type-loaded carrier is linearly arranged, bottomed up, and the top is a start-up loader. In addition to the start-up type loader, other class loaders are instantiated by the user to load different classes. When a class is to be loaded, the bottom loader attempts to hand over the class to the parent loader, and the parent class is trying to handle the parent class load, always until the class loader. If the parent class loader cannot be loaded, the subclass loader is loaded, the subclass load can be loaded, and the remainder is given to his subclass until the bottom. Such as: loader A, B, C, D, E, F, start a ---> b ---> c ---> d ---> e ---> f ---> startup When a class FUN needs to be loaded, he will go back to the top, which is started to start the class loader. If the start-up type loader cannot load FUN, it will be given to the F load, F load can be loaded, and then the rest is given to E, and then it will go so. As mentioned above, the class loaded by each class loader during the run forms a runtime package, the class in the same runtime package can be accessed to each other, but cannot access the outer class. 4. Virtual machine lifecycle: Each Java program has its own virtual machine instance, producing and demise with the production and demise of the program. 5. The memory structure of the Java program: The program space is divided into method area, pile, java stack, and local square stack. (1) Method area storage loaded class data information includes: Basic information: The full qualification of each class. The direct superclass of each class (constrained type conversion). This class is a class or an interface. This type of access modifier. A list of complete list of direct super interfaces. Details of each loading: Running Time Pool: Store all constants used in this type (direct constant and symbolic reference to other types, fields, methods), which are accessed by an index in an array, and is external calls and Class contacts and type objective bridges. It is the runtime representation of a class file (byte code) constant pool. (There is also a static constant tank, in the bytecode file). Field information: Information of each field declared in the class (name, type, modifier).

Method information: Information of each method declared in the class (name, back-back type, parameter type, modifier, method code code and exception table). Static variables to ClassLoader reference: ie reference to the class loader of this class. Reference to class Class: The virtual machine creates a Class instance for each loaded type to represent this loaded class. (2) Stack all instance variables of all generated objects and objects. (3) The Java Stack is stored in the form of a local method (including the parameters, local variables, intermediate results, etc.). Each time to call a method to press the method frame of the method to enter the Java stack, becoming the current method frame. This frame is popped when the end (returns) is called. When the compiler compiles the original code into a zip code (.class), the partial variable of various types of methods has been determined and placed in the bytecode, and the method is loaded with the class. Area. When the method is called, the local variable and the size of the operator stack are obtained by accessing the information in the method area. Java stack frame (ie method frame) consists of a local variable area, an operator counting, and a frame data area. The local variable zone is a value of a word-oriented unit, each array element, corresponding to a local variable value. When the method is called, the local variables of the method constitute a number of arrays and access them by an index. If a non-static method is added, an implicit reference parameter THIS is added, which points to the object that calls this method. The static method does not have this parameter. Therefore, the object cannot invoke a static method. Operator stack is also an array, but it is accessed by stack operation. The so-called operands are those that are instructive. When you need to operate as a = b c, the parameter stack will be operated, such as the B and C stack, then pop up by the operation instruction, and perform the operation, this is made by the IADD instruction B And c and add, then press the operator stack (a series of IADDs) and then pop up by the i_storex instruction, save the result to the partial variable zone array pointed to index X (here index x point to local variables a) . The virtual machine will operate the operator as a work area. Frame data area processing constant pool resolution, exception handling, etc. (4) Local square stack: related to the language of the local approach, if the call is a C language method, a C stack. The local method can call up the Java method. If there is a Java method to call local methods, the virtual machine runs this local method. In the virtual machine, running this local method is to perform this Java method. If the local method throws an exception, the virtual machine thinks that this Java method throws an exception. (5) When executing a program, find the loaded class through the reference to the method area. If there is not yet loaded, look up the bytecode (class name .class), and load it into the method area. During the execution, the virtual opportunity replaces the object's symbol reference (ie, the object name) with a direct pointer to improve access speed. (6) Therefore, it is generally shown as: method area: storage classes include various information, and bytecodes are loaded here. Java Stack: Store various information of the called method, only when the method is called, the method frame is pressed into the Java stack. Heap: Store information of the object, including the instance variable of the object, but does not include the method of the object. Only when the object is called, the method frame is pressed into the Java Stack. 6.Java Data Type: Value Type: Floating Point Type: Float Double Integer Type: Byte, Short, Int, Long, Char (INT and CHAR). Quote Type: Class Type, Interface Type, Arch Type. 7. Java's reference type: reference and pointer. Quote represents the object being referenced, it is just a representative of the object, does not occupy the memory, and cannot be modified.

If the reference variable is not referenced, the reference variable = NULL. The address of the pointer stores the address of the object, it is a variable, which can be modified, like other variables, occupying memory. 8. Method area All thread sharing method area, but in order to meet the thread security, each class in the method area must be set as a critical resource, that is, a certain class can only be accessed by one thread. 9. Class ID: Since a program can load the same class multiple times and the class can exist in different namespaces (that is, loaded by different loaders), the identity of the loader loaded, Can only identify a class. 10. The object object instance variable is stored in the heap, and the object symbol reference is where the constant pool, method properties, and so on. Access to the object's instance data and data of the class of the object can be accessed by reference to the object. The reference to the object points to the object in the stack. There are two examples in the instance, see book 98. Dynamic binding is required when the method of calling the object is called. That is, it is not possible to determine the method you need to call according to the object, but to determine the method that needs to be called according to the class data of the object. At this point, you also need to access class data by reference to the object. Dynamic binding is binding at runtime instead of binding upon compiling. 11. A array array is also an object of a class. An array with the same type and dimension belongs to the same class (regardless of the length of only the dimension). The length of the array belongs to an object instance. The multidimensional array is also a one-dimensional array. Such as a two-dimensional array, which is a one-dimensional array, and each element of the one-dimensional array is a reference to an array. The array is also stored in a heap as a common object. The array name is a reference to the array, and the array content is accessed by the index, ie the array label. 12. An exception is saved in the frame data area of ​​the Java stack frame to be referenced for the exception table for this method. The abnormal table describes the bytecode (* .class) of the method (* .class) is protected by the Catch clause (ie the byte code in the TRY clause). When a method throws an exception, the virtual machine looks for matching catch clauses in the corresponding exception table and handles control to the code in the CATCH clause. 13. Java Execute Engine Implementation Platform Unrelated, in the center of Java method frame, the local variable array as a register of the CPU. Each operation must operate the operator's operator and return to the local variable area. Java virtual machine specifies strong type conversion, that is, low precision can be implicitly converted to high precision, high precision must be forced to transform to low precision. 14. The thread thread is present in a certain actuator in the process. Each thread must comply with object lock, thread wait, and notifications. Object locks the access object resource for thread mutual exclusion. Waiting and notice is to comply with the thread syndrome to achieve the same purpose. The Java object reaches the locking purpose through the instruction set, and the Wait (), Notify (), Notify () method of the Object class are waiting and notify. When a thread calls a WAIT () method of an object, the thread is blocked and adds to the thread block queue of the object until another thread calls the notification method of the same object to wake up the thread in the block queue. 15. Constant pool constant tanks are used to store various information of the type, including various direct constants of the type, and symbolic reference to other types, fields, methods. The constant pool is divided into two, the constant pool stored in the .CLASS bytecode and the runtime constant pool stored in the method area. The constant pool appears in an inlet form (similar to the interrupt vector table), each entry points to a table, and stores the constant information. However, the flag bits of the entrance of the constant pool can determine the constant type stored in the corresponding table. The constant pool entry begins with a flag bit, which indicates the type of constant. Each entry corresponds to a table, which is the end of the symbol _info, and the constant form of constant is stored in the table. The constant pool is accommodated in addition to the storage of direct constants, and the following symbols are accommodated: the list of classes and interfaces. Field names and descriptors (this descriptor is a string indicating the field type. Field is a class or interface class variable or instance variable). Method Name and Descriptor (This descriptor indicates method returns type, parameter type, quantity, order).

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

New Post(0)