1. Compilation order: Compiler virtual machine virtual machine JAVA source file * .java ------> byte code * .class ------> Type loader ---> Execute Engine
A .class 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 you want to load one
At a class, the loader at the bottom attempts to hand over the class to the parent carrier, and the parent class is trying to handle the parent class loading, always until the class loader. If the parent class loader cannot be
Loading, then give the subclass loader load, sub-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.
The remainder is given to E, and then it will go on this way.
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 constant pool: Store all constants used in this type (direct constant and symbolic reference to other types, fields, methods), which are accessed by indexing in an array, is external call
Bridges associated with class contacts and type objects. 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 the method is called, it will be pressed against the method of the method.
Java stack becomes the current method frame. This frame is popped when the end (returns) is called. When the compiler compiles the original code into a zona code (.class), the partial changes of various types of methods have been
Quantity, the operating number stack size is determined and placed in the bytecode, and loaded into the method area as the class. When the method is called, the local variable and operand are obtained by accessing the information in the method area.
The size of the stack.
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 partial variable of the method constitutes an array and accesses it through 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 call 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, you will be operated.
Number stack, such as putting B and C stack, then popping them by operation instructions, and performing operation, here, B and C pop up B and C, then pressing the operator stack (a series of IADD Execute
Row) Then pop up the result from the i_storex command, save the partial variable region array pointed to index X (index X point to local variable 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 (ie, can be loaded by different loaders), therefore the loader loaded with the loader is added
On to uniquely 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 create the object by reference to the reference
The data of the class. 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 time,
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. Two
Dimensional group, which is a one-dimensional array, 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 in the Try clause.
Bytecode). 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, then 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 order of locks through the instruction set, with the same inheritance
Wait (), Notify (), NotifyAll () method of the Object class come to wait and notify. When a thread calls a WAIT () method of an object, the thread is blocked and joined to the line of the object.
In the process of blocking queues, the thread in the blocking queue can be awakened until the other thread calls the notification method of the same object.
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 corresponding table can be judged from the flag of the entrance of the constant pool.
The constant type stored in the store. 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). When running, the virtual machine's constant pool's list of constant names and methods, the descriptor of the fields creates a relationship between classes and classes.
The constant pool is just a collection of references and descriptors and does not accept any assignment operation.
All objects creation, methods, and class variables are invoked from the constant pool, but the call of the instance variable is obtained from the heap. (guess)
The symbol reference is used by the virtual machine to obtain a specific address.
A constant pool parsing is to replace the symbol reference in the constant pool to direct reference.
When you use a class method or field, first find the symbol reference of the method or field from the constant pool, then analyze, find its physical address.
Convey the various symbols, classes and classes of the code, and perform a constant pool resolution called dynamic connection.
16. The constant pool structure constant pool consists of a lot of units, each unit is shaped (inlet | content), and the entry is found by the index when accessing a constant pool unit, and then accesses its content. But sometimes the content of the unit is also
It may be a constant pool entry (such as a constant pool unit of class or interface, the entrance contains the symbol reference of the class is constant_class_info, and the content points to one
Constant_utf8_info's constant pool unit, which stores the full-qualified name of this class). Direct constants such as int, float, etc., the content is the value of constant.
17. The structural method area of the method area stores all information about type, interface. The method area contains:
Confarus Pool: Storage Type Direct Constants and All Fields, Methods, Other Type Symbolic references (just references, do not store specific information).
Field information: All declarations of fields (including field name, type, modifier).
Method Information: All defined methods (including method names, return types, modifiers, method of bytecodes, method stack frames, and abnormal methods).
Class variable information: The virtual machine is allocated in the method area for all class variables, and later initialization, assignment, etc. are also performed in the method area to share all kinds of instances.
In order to improve access speed, the virtual machine sets a method table for each non-abstract class in the method area, which is an array, and each element is a method of direct reference. Take the class object call
When the method is searched in the method table (the abstract class has no instance, so there is no way to call the method, so there is no method table).
18. The instances and arrays of the stack storage (including instance variables, pointing to references to class data in the corresponding method area).
19. An example class test {public static void main (string args []) {string a = new string ("hello"); string b = new string ("Hello"); string c = "hello"; string d = "Hello";}}, a == b returns false, c == D returns Ture. Because: == Compare whether the two parties are the same object.
First: String a = new string ("Hello") String B = New String ("Hello") A and B respectively create a new Hello object and reference variable, that is, two Hello in the heap, their respective references are A and B. And: string c = "hello" string d = "hello" first creates a string-class instance hello, then establish two string reference variables C and D, then let C and D point to the Hello instance that starts establishing. Therefore, C and D point to the same object.