Actual java virtual machine (a) - the basic structure of the virtual machine and Basic Operation

Foreword


There has been no complete reading a book on java virtual machine, recently a number of slightly smaller workload, intend to learn from start to finish a book on java virtual machine. The thinking of watching "in-depth understanding of java virtual machine", think twice, because the book is based on jdk1.7, he gave up this one, and finally chose the "real java virtual machine --JVM troubleshooting and performance optimization."

 

The basic structure of a diagram, Java Virtual Machine


 

 

 The basic structure shown above in FIG Java Virtual Machine

1. class loader subsystem: responsible for loading Class information from the file system or network

2. Method Area: storing class information loaded before jdk1.7 called permanent Generation (Perm), after 1.8 metadata area (Metaspace)

3.Java heap: the establishment when the virtual machine is started, nearly all of Java object instances exist heap, all threads share

4. Direct Memory: Direct Memory area of ​​the system, access is faster than the portion of the Java heap, is widely used in the NIO, direct memory usage is also very common, such Java program can direct memory skip directly access the native Java heap pile space

The garbage collection system: the procedure zone, Java heap garbage objects and direct memory recovery

6.Java stack: Each thread has a private stack, the stack frame information is preserved, local variables, method parameters, and method call and return are closely related

7. native method stacks: the Java stack is similar to the method used to call the local

8.PC register: private to each thread, any time Java thread always perform a method, if it is a local method, the value of PC register is undefined, if not native, PC register will point to the currently executing instruction

9. execution engine: performing a virtual machine bytecode

Common operating parameters Second, the virtual machine


1. Virtual Machine Parameters

  -XX: + PrintGC (recommended in jdk9.jdk10 use -Xlog: gc), use this parameter to start java virtual machine, it will print the corresponding log in the GC

  -XX: + PrintGCDetails, the print parameter stack details, describing the use of each section (jdk9, jdk10 use -Xlog: gc *)

  -XX: + PrintGCApplicationStoppedTime, you can print the application due to the GC pause time generated

  -Xloggc: log / gc.log, the command log records all GC log files in the current directory file folder gc.log

2. class loading / unloading track

  -verbose: class can trace class loading, unloading

  -XX: + TraceClassLoading (jdk9, jdk10 use -Xlog: class + load = info) to load the class tracking

  -XX: + TraceClassUnloading (jdk9, jdk10 use -Xlog: class + unload = info) unloaded class tracking

3. Review the virtual machine parameters

  -XX: + PrintCommandLineFlags, can be transferred to the print implicit and explicit parameters of the virtual machine itself may be a hidden parameter setting virtual machine starts

3. heap configuration parameters

  -Xms specify the initial stack, -Xmx specified maximum heap (Example: -Xmx20m -Xms5m, representative of heap initialization 5M, 20M available maximum stack)

  -Xmn specify the size of the new generation is generally recommended settings for the entire heap of 1/3 to 1/4

  -XX: SurvivorRatio, (example: -XX: SurvivorRatio = 2, the representative eden: from = 2: 1) to specify the new generation ratio eden region and from / to the area. The new generation area, the new generation of total available size (eden + from) or (eden + to), normally of the same size and from the area to

  -XX: proportion NewRatio, years old / new generation

4. The stack overflow handling

  The program is running, if insufficient heap space, it will throw an exception OOM (Out Of Memory), Java virtual machine provides two parameters

  -XX: + HeapDumpOnOutOfMemoryError can export the entire information in the memory heap overflow

  -XX: HeapDumpPath, you can specify the export heap storage path (absolute path)

5. The method of zone configuration

  jdk1.6 and jdk1.7 use -XX: PermSize and -XX: MaxPermSize permanent configuration area and maximum size of the permanent area

  Also mentioned above, jdk8 start, permanent area has been completely removed, using the metadata stored in the metadata area type, default system metadata area only by available memory, but can still use -XX: MaxMetaspaceSize specified the maximum available

6. Stack Configuration

  -Xss: Specifies the thread stack size

7. The mode of operation of the virtual machine

  (1) Client mode

    After using -client can specify Client mode, faster start this mode, the system maximum heap MaxHeapSize about 256MB, CompliThreshold default is 1500, that function is called 1500, will be JIT compiler

  (2) Server mode

    Use -server can specify server mode, which is slow to start, will try to gather more information on system performance, the use of more sophisticated optimization algorithm to optimize the program, so the system is fully booted, Server mode is much faster than Client mode .

    In this model system the maximum stack MaxHeapSize about 1GB, CompliThreshold default 10000

Guess you like

Origin www.cnblogs.com/gtblog/p/11453304.html