Virtual memory area jvm -1

A data area .java

               Program counter, java virtual machine stack, native method stacks, java heap, method area, constant pool operation (part of the zone method), direct memory (part of the data area of ​​a non-virtual machine is running)

               Thread sharing, thread-private

                                                     

 

     1.1 Program Counter

                 It is a small memory space, its role can be seen as a thread at the head byte code executed by signal indicator.

                 Bytecode interpreter of this work is that by changing the value of the counter to select one of the instructions to be executed bytecode instructions, branching, looping, branching, exception handling, and other basic functions thread recovery relies counter complete

           This memory area is the only one not provide for any situation in the region OutOfMemoryError Java Virtual Machine Specification.

     1.2 java virtual machine stack

                 Life cycle and thread consistency. Java memory model is a description of the method performed: each method to create a stack frame (Stack Frame) will be executed when the bed local variable table for storing information, the operand stack, a dynamic link, the method exports. Each method invocation until the end of execution, a corresponding stack frame on the stack from the stack to the virtual machine process stack.

                 Note: java two ways to return ways: return statement, an exception is thrown, the two will result in the stack frame is popped.

                 Stack frame: table holds local variables, an operand stack, the method entrance and exit

                 Local variable table: storing the compilation of the basic types of known (boolean, byte, char, short, int, float, long, double), object reference (reference type, reference may point object address pointer may point to the representative handle objects), returnAddress type.

                Variable stack reference, and are stored locally (i.e.: variables defined in the body of the method or reference), and references in the local variable stack (local variables including the final)

               The stack is also stored a reference to a local object (the definition of variables in the process of reference type body), a reference object is not the object itself, but in the object heap address, in other words, the local object references referred objects on the heap address stored in the stack

     1.3 native method stacks

                 And virtual machine stack to play a similar role for a java service, a service for the local method, when the native method is performed in native method stacks will create a stack frame, for local variable to store the table method of operation the number of stacks, dynamic linking, export information.

                 Local method refers to native way, it is a non-call interface java java code. Implementation of the method implemented by the non java, such as c

     1.4 java heap

                The meaning of existence is to store the object instance, almost all object instances and to allocate memory array to be here. This is inside the object is automatically managed, also known as GC (Garbage Collector) under management.

                Instance variable (non-modified static member variables) and object association together, so instance variables are heap 

                also open up an array of java heap memory space

     1.5 Method zone

                Shared memory region, class information storage has been loaded in the virtual machine, constants, static variables, the time compiler to compile the code and other data. Where the runtime constant pool is on the method area

                java.lang.class Object (Class object) generated during the class loader is stored in the method area, rather than heap (new instance object).

                Note: by loading a virtual machine, and initialize a Java type connector, so that the type can be used by a Java program running in order to use a class that is bound to the above three processes experienced

          Garbage collection is mainly directed against the constant pool recovery and type of unloading.

                Class information: for each type of load (Class class, the interface interface, enum enum, annotation annotation), JVM must be stored in the process, the following types of information area.

                     Fully qualified name of this type of (full name = package name. Class name)

                     The fully qualified name of the type of the direct parent (java.lang.Object except if there is no other type of parent class declaration, the default is the parent class Object)

                     This type of modifiers (public, abstract, a subset of the final)

                     This type of interface to direct an ordered list
                     addition method further region (Method Area) and the types of information storage class constant pool (constant pool), field (Field) information, a method (Method) information

                     In addition to all the static constant (static) variable               

               Constants: static final modification of member variables (constants) are stored in the method area (Method Area) in

               Static variables: the modified static member variables

                     Static variables, also known as class variables, because the static variables and class associated together, with loading the class exists in the process zone (rather than heap)

                    Eight basic data type (byte, short, int, long, float, double, char, boolean) static variables in the process open space areas, and the value stored in the corresponding area methods, static type if a reference variable No assignment (eg: static object obj;) is a static variable using new reference type then the object obj stored in the reference area method, and assign a default null value; if a reference to a type of static variables if new keyword assignment of a static variable reference type (eg: static Person person = new Person ();), then the person is stored in the reference area method, and the object address is also stored in the stack object in the process area (note only this time a static variable to store the heap address of the object, but the object itself is still in the heap memory)               

               After time compiler to compile the code:

                  Loaded classes compiled bytecode program is running, the process static variables (class variables) and the static method and the conventional method corresponding to the method of loading the bytecode region.

                 No instance variable area method, because, prior to loading the class generates a corresponding object class, instance variables are associated together and objects, instance variables no object does not exist, there is no object class loading, the methods zone no instance variables

            Static variables (class variables) and the static method and the conventional method in a storage area of ​​a method (Method Area) are distinguished

      1.6 running constant pool

                Constants: final modified member variable represents the constant value once given can not be changed

                 final modification of variables in three ways: static variables, instance variables and local variables

                Static constant pool that * .class file constant pool, class file constant pool not only contains the string (digital) literal, also contains the class, method of information, most of the space occupied by the file class.

               Runtime constant pool is jvm virtual machine loading operation after completion of the class, the class file constant pool is loaded into memory and stored in the method area, we often say that the constant pool, refers to the method area runtime constant pool for storing a variety of compiler generated literal (string, final constant value) and a reference symbol (fully qualified name of the class and interface; and a descriptor field names; the method name and descriptor)

                 Most of the eight basic types of Java wrapper class implements the constant pool technology, they are Byte, Short, Integer, Long, Character, Boolean, the other two floating-point types of packaging (Float, Double) is not implemented . Further Byte, Short, Integer, Long, Character these five packaging only integer values ​​corresponding to the constant pool when -128127.

      1.7 Direct Memory

               Part of the runtime data area of ​​direct memory is not a virtual machine

Code to know:

        // local variable stack frame p are the main method
         // new new the Person () object is allocated on the heap space 
        the Person p = new new the Person ();
         // SUM in the stack, new int [10] in the heap space 
        int [] = SUM new new  int [ 10 ];
 class the Person 
{    // instance variable name and age in the heap (heap) allocate space 
    Private String name;
     Private  int age;
     // class variable (reference types) and NAME1 "cn" in method area (area method,) 
    Private  static String NAME1 = " CN " ;
     // class variable (reference type) in the process area NAME2 (method, area)
     //new String ( "cn") allocated in the object heap (Heap) space 
    Private  static String = NAME2 new new String ( " CN " );
     // NUM heap, new int [10] Also stack 
    Private  int [] NUM = new new  int [ 10 ]; 
    the Person (String name, int Age) 
    {    
        // the this parameter and the name, age when the constructor is called
         // will open space in the stack frame construction method of 
        the this .name = name;
         the this = .age Age; 
    } 

    // the setName () method in the process zone 
    public  void the this the setName (String name)
    {
        = .name name; 
    } 

    // Speak () method in the process zone 
    public  void Speak () 
    { 
        the System. OUT .println ( the this .name + " ... " + the this .age); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/tansuiqing/p/11197513.html