jvm study notes (a) - java memory area

Runtime data area

Run-time data area

A program counter (recording program running position)

  • The program counter is a smaller memory space can be seen as an indicator byte-code line number of the currently executing thread
  • Bytecode interpreter chamber by changing the value of the counter is selected bytecode instruction to be executed next, a branch, looping, branching, exception handling, and other basic functions thread recovery relies counter complete
  • java multithreaded time slice is allocated by a thread of execution, when a thread's time slice is exhausted, there is a need to record a record thread to run, conveniently once this rotation can be performed when a thread suspended from the upper position continue, therefore, each thread needs to have a counter, and the counter thread is the thread isolated, independently of each other, as thread-private
  • Java method is executed, the address counter records bytecode instructions are being executed, native method execution, the counter is empty.

Two, java virtual machine stack

VM stack

  1. Java Virtual Machine stack
    • It is the thread private life cycle in the same thread. Memory Model for java virtual machine stack method described execution, while each method creates a stack frame are performed simultaneously (Stack Frame) table used to store information local variables, an operand stack, dynamic link, the method exports. Each method call to the completion of a stack frame corresponds to push the stack in a virtual machine to process
  2. Local variable table
    • All the basic data types where the compiler of the known object reference (pointer or object reference object handle), returnAddress type (pointer to address a byte code instruction)
    • long and double take up two local data variable space (Slot), the rest of the data type occupies only a local variable table to see Nether End assigned during compilation, when entering a method, this method requires a frame local variable space allocation is determined, the method does not change during operation
  3. Will throw an exception: StackOverflowError and OutOfMemoryError

Third, native method stacks (Native Method Stack)

  1. To use for the virtual machine Native method services, virtual machine specification language used in the native method stack method, use, and the data structure is not mandatory.
  2. Some virtual machines (such as hotspot) directly to the native method stacks into one stack in a virtual machine
  3. Will throw an exception: StackOverflowError and OutOfMemoryError

Four, java heap (Java Heap)

  1. java heap is the largest piece of memory java virtual machine management, and shared by all threads, created when the virtual machine starts
  2. The only role of java heap object instance is stored
  3. java heap is the main area managed by the garbage collector

V. Method region (Non-Heap)

  1. Region shared by the threads, storage virtual machine has been loaded class information {fully qualified class (package name. Class name), the direct parent. An ordered list of fully qualified class name, a direct interface modifier], constants, static variables, the time compiler to compile the code and other data , etc.
  2. Runtime constant pool
    • Generated by the compiler to store various literal and symbolic references into the method area after loading class runtime constant pool to store

Sixth, direct memory

Objects

A memory allocation when creating objects

Memory Allocation
  1. Pointer collision

    Absolute regular heap memory, the memory and the memory used by a pointer spaced unused two do not cross memory allocated only move the pointer to the object distance is equal to the size of the

Here Insert Picture Description

  1. Free list

    Memory irregular, have been used with interdigitated unused memory, the memory space using a linked list of records is not used, the time allocated objects to find a large enough memory is divided from the list

Memory Allocation - free list

Second, the memory layout object (the HotSpot)

1. Object head
  1. Storing runtime data object itself (Mark Word), such as a hash code, the GC generational age lock state flag thread holds the lock, the thread ID bias, bias timestamp
  2. Type pointer, i.e. a pointer to its class object is metadata, whereby the virtual machine determines that the object belongs to which class
2. Examples of data
  • Effective information object is actually stored
3. Align the filling
  • Object of memory occupied by the whole integer multiple of 8 bytes, when placeholders

Third, access the location

1. Handle Access (stable)

java stack dividing a memory cell as a handle, store object reference object handle address contained in the handle of each specific object instance data and the address information of the data type

Handle visit

2. Direct Access Pointer (Hotspot using fast location)

Reference types store the Java heap object addresses, heap objects to consider how to place the object type data

Here Insert Picture Description

Published 17 original articles · won praise 1 · views 652

Guess you like

Origin blog.csdn.net/c_c_y_CC/article/details/93229033