On the JVM

Program counter (register)

The program counter is private to thread
bytecode line number (offset address byte code execution) recording the currently executing thread, for obtaining a next bytecode execution.
Why do you need a program counter I think one of the reasons is
because running multiple threads, each thread after the switch needs to know the status of the last run, location. So this you can see the program counter for each thread is private.

VM stack

Java Virtual Machine stack Java memory model is described a method of performing
a storage stack frame
for each method call from the completion of the execution procedure, it corresponds to the stack (push) a stack frame of the stack in a virtual machine to pop (popped) process.
Also belonging to the private thread

  • Local variable table
    of local variables defined within the local variable table for storing method parameters and method

  • Operand stack

  • Dynamic Link

  • Methods exports

If the stack is too deep can cause stack memory overflow error StackOverflowError recursive functions such as no exit
can set the stack size by -Xss
likely cause OutOfMemoryError caused a virtual machine stack is also possible to run out of the current thread of memory and can not allocate memory

Native method stacks

Navtive method is to call native Java C / C ++ libraries directly through the JNI, the method can be considered equivalent to Native C / C ++ to Java expose an interface, Java by calling this interface to invoke the C / C ++ method. When a thread calls a Java method, the opportunity to create a virtual stack frame and pressed into the Java Virtual Machine stack. However, when it is the native method call, the opportunity to maintain a virtual Java virtual machine stack unchanged, nor is pressed into a new stack frame stack to the Java virtual machine, the virtual machine simply and directly invoke dynamic connection method specified native

Java heap

Java heap is the main area managed by the garbage collector heap memory is divided into the old and the new generation's new generation
has been divided into three regions Eden from Survivor To Survivor

Cenozoic 1/3 2/3 year old heap heap space

If the object is a priority under the age of Eden in Eden created in
if Eden is full of trigger Minor GC (Eden and Survior will recover in one) will also
copy the active object into another piece of Survivor in
if Survior in memory was full or does not fit directly into Survior years old

大对象直接进入老年代
This is because
a large number of very large objects appear affect the performance of the system, this will cause there to trigger garbage collection in advance when a lot of space to place these objects.

Trigger code when the GC
[Full the GC (Ergonomics) [PSYoungGen: 752K-> 0K (9216K)] [ParOldGen: 6152K-> 6775K (10240K)] 6904K-> 6775K (19456K), [Metaspace: 2574K-> 2574K (1056768K )], 0.0068214 secs] [Times : user = 0.01 sys = 0.00, real = 0.01 secs]

After 752K buffer deleted successfully 6152K 6775K ok goes mobile

Young to old-generation mobile's 6904-> 6775K ok

public class EdenTest {
    private static final int _1MB = 1024*1024;

    /**
     * 虚拟机参数设置:-XX:+UseParallelGC -XX:+PrintGCDetails -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8
     * @param args
     */
    public static void main(String[] args) {
        byte[] a = new byte[2*_1MB];
        byte[] b = new byte[2*_1MB];
        byte[] c = new byte[2*_1MB];
        byte[] d = new byte[3*_1MB];
    }
}



java -XX:+UseParallelGC -XX:+PrintGCDetails -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8 EdenNOTGCTest

  • Set the initial heap size represents -Xms20M,
  • -Xmx20M represents the maximum heap size 20M
  • -Xmn size of the actual space available for the new generation of Eden + 1 th Survivor i.e. 90%
  • -Xss stack size of each thread in general if the stack is not very deep, then 1M definitely enough
    [PSYoungGen: 752K-> 0K (9216K )]
    is Eden + a Surivor space 9216K representation

Collection (part)

PSYoungGen means using Parallel Scavenge collector
after the trigger again when the Minor GC, S0, and Eden surviving object is moved to S1, (From s0To s1), S0 i.e. empty. At the same time, only a Survivor Space and Eden are operated simultaneously

Virtual machine for each object defines an age counter (Age), if the object is created in the new generation of Eden, and after undergoing a Minor GC still alive and can be accommodated Survivor words, the virtual object is moved to the Survivor region, and the age of the subject Age + 1.

Each new generation of the object survived a Minor GC, age, increased 1, when its age increases to a certain threshold (default is 15 years old), will be promoted to the old era.

By -XX: MaxTenuringThreshold
set the threshold

When storing GC does not occur when the size of 7456-6144
during storage size occurs GC

JVM-dimensional space

JVM heap memory is divided into regions and non-stack
non-heap region including native code for compiling and save the
metadata JVM classes and methods used to describe the application used in generation is also stored in the persistent
metadata Java the mean notes

Memory layout objects

In HotSpot VM objects stored in memory layout can be divided into
biased instance data thread ID (valid information object) alignment padding object header (the object itself runtime data such as the hash code) locks thread holds the lock status flag

When you create an object roughly divided into

  1. Check the load class
  2. Allocate memory for the object
  3. Memory initialization
  4. Object to the other object header alignment padding
  5. init

Reference links

https://www.jianshu.com/p/ac162726d7de

Published 17 original articles · won praise 3 · Views 358

Guess you like

Origin blog.csdn.net/qq_40184765/article/details/104819269
JVM
JVM