Java 5 Large Memory Area

Source: Internet
Author: User

1.Java run-time data area

    1. Method area, heap thread sharing. The virtual machine stack, the local method stack, and the program counter thread are private.
2. Program counter (PC counter)
    • Takes up a small chunk of memory space and logs the virtual machine bytecode instruction address that is executing when the Java method is executed, and if the native method is executed, the timer value is empty.
3.Java Virtual Machine Stack
    • Memory model for Java method execution
    • View Java Virtual machine stack details
3.1 Stack Frame
    • Each method creates a corresponding stack frame in the virtual machine stack for storing local variable tables , operand stacks, dynamic links, method exits and other information.
    • A method call to the end corresponds to this stack frame from the virtual machine stack into the stack to the stack.
4. Stack memory and heap memory
    • In general, stack memory and heap memory stack refers to the virtual machine stack memory or refers to the local variable table, heap is the heap memory. These two pieces are of the greatest concern.
5. Local Method Stack
    • The local method stack acts similarly to the virtual machine stack, where the virtual machine executes the Java Method (bytecode) service for the virtual machine, and the local method stack uses the native method service for the JVM.
    1. Local method keyword native, which are typically used to invoke methods in the Local method library, which are mostly implemented with C.
    2. Some virtual machines combine a local method stack with a virtual machine stack, such as a hotspot.
6.java Heap
    • The largest piece of memory, where the object instance is stored.
    1. The Java heap is the primary area of garbage collector management, also known as the GC heap.
    2. The Java heap is physically discontinuous and logically contiguous.
    3. The instance assignment is not completed in the heap and the OutOfMemoryError exception cannot be thrown on the extension
7. Method area
    • Store the class information (class object), constants, static variables, and JIT-compiled code data that have been loaded by the virtual machine.
    • JDK 1.7, 1.8 has made modifications to the method area, and 1.8 has canceled the method area.
    1. The method area is described by the Java Virtual Machine specification as a logical part of the heap, but it is not a heap and has an alias called non-heap Non-heap
    2. jdk1.6 and Previous method location Yuyongjude (PermGen), permanent generation and heap isolation from each other.
    3. The method area may not require contiguous memory space, can also be fixed size, can be extended, or garbage collection can not be implemented, if the implementation is mainly for the collection of constant pool and type of unloading.
7.4 Running a constant-rate pool
    • In the method area, it is used to hold various symbol references and literals generated during the compilation period .
    • The compilation period places a variety of symbol references and literals in a constant pool of class files, after parsing in the run-time pool , where strings are in the string constant pool of the method area (before 1.7), and method runs are copied to the local variable table the.
    • Symbol Reference: String SS = "ASDSFG" ss this symbol is the symbol reference. parse phase resolves to direct reference
    • Literal: value itself such as ASDFG
8. Direct Memory
    • is not the memory of the virtual runtime and is no longer defined in the JVM specification.
    • The new Input/output class was added to JDK 1.4, introducing an I/O approach based on channel and buffer, which can be used to directly allocate out-of-heap memory using the native function library. It then operates as a reference to this memory through a Directbytebuffer object stored in the Java heap. This can significantly improve performance in some scenarios because it avoids copying data back and forth in the Java heap and native heap.
9. Creation of objects
    • Ordinary Java object creation, not including arrays and class objects.
    • View specific object creation procedures and memory allocations
    1. Class load connection class load check
    2. After the check passes to allocate memory for the object, the object memory size is determined when the class is loaded.
    3. Initializes the allocated memory to a value of 0, which guarantees that the instance field can be used even if the initial value is not assigned.
    4. Sets the object's hash code, which is the instance of the class, and the GC generational age.
    5. <init> method execution, object execution initialization .
10. Object Memory Distribution
    • Objects are divided into 3 areas in memory, object header (header), instance (Instance data), and aligned padding (Padding).
    1. Instance data: Includes fields that inherit from the parent class, and assigns fields of the same width to each other.
    2. Align fills: the Memory auto-management system of a HotSpot VM requires that the object start address must be an integer multiple of 8 bytes, which means that the object size must be a 8-byte integer multiple, and the object header is exactly a multiple of 8 bytes, so that the instance data is not enough for a 8-byte integer multiple when the fill is padded.
10.1 Object Header
    • The object header is divided into 2 parts, the first part stores the object's own run-time data, and the second stores the type pointers.
    • Object Head Action
    1. Its own runtime data (Mark Word): such as hash code, GC generational age, lock-to-state flag, thread-held lock, bias thread ID, bias timestamp. Mark Word is a non-fixed data structure so that more information can be stored, depending on the state of the object, the number of placeholders for each information varies, but the total is definitely a 8-byte multiple.
    2. Type pointers: Pointers to metadata (class data)
    3. If the object is an array then the object header has an area for recording the length of the array, because ordinary Java objects can determine the size by metadata, and the array's metadata cannot determine the size of the array.
11. Object Positioning
    • There are two ways to access objects in the mainstream, through handle access and direct access, with direct access to the HotSpot.
    1. Access through the handle is just a handle pool in the heap holds the object instance data and the type data each individual address, the reference in the stack holds the address of the handle, the advantage is that the reference saved address is not stable, and the object change only changes the address in the handle pool.
    2. Direct access refers directly to the object, and the advantage is that it is fast.
12.OOM
    • See more content

Java 5 Large Memory Area

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.