In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what are the JVM architecture and GC commands, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
JVM Runtime data area
Overview
Java virtual machine Java virtual machine (JVM) is the software implementation of physical machines. The java compiler javac compiles the source file .java into a bytecode file .class, then the bytecode file .class is put into JVM, and the bytecode file .class is loaded and executed. The JVM architecture is shown below.
JVM Architecture
JVM architecture
Garbage collection (garbage collection): responsible for collecting unused objects in the heap memory heap
Judge whether the object is alive or not, and test the accessibility.
Reference counting algorithm: add a reference counter to the object. Whenever there is a reference to it, the counter value is increased by 1, and when the reference expires, the counter value is subtracted by 1. An object whose counter is 0 at any time can no longer be used.
Root search algorithm: through a series of objects named "GC Roots" as the starting point, the search starts from these nodes, and the search path is called reference chain. When an object is not connected to GC Roots with any reference chain, it is proved that the object is unavailable.
Garbage collection algorithm
Mark-clear algorithm Mark-Sweep: first mark out all the objects that need to be reclaimed, and then uniformly reclaim all the marked objects after the marking is completed.
Efficiency issues: marking and clearing actions are not efficient actions
Space problem: a large number of discontiguous memory fragments are generated after the tag is cleared, and too many fragments make it impossible to find enough contiguous memory when allocating larger objects and have to trigger another gc in advance.
Replication algorithm Copying: it divides available memory into two equal chunks according to capacity, using only one of them at a time. When this piece of memory is used up, copy the surviving objects to another piece, and then clean up the used memory space at once.
The available memory has been reduced to half its original size.
During each collection, all marked objects are copied, causing some objects with a long life cycle to be copied back and forth many times, consuming a lot of time-> generational recycling to solve this problem.
Generation recovery algorithm Generational Collecting: according to the different survival period of the object, the memory is divided into several new generations: the memory is divided into a larger Eden space and two smaller Survivor space. When the new object is full, it triggers that the surviving objects in the YGC,Eden are moved to S0, and the surviving objects in Eden such as Eden; are emptied, and then the surviving objects in YGC,Eden and S0 are copied to S1. (the replication algorithm ensures that the surviving objects from Eden and S0 in S1 occupy continuous memory space and avoids fragmentation); empty Eden and S0. In the next round, S0 and S1 switch roles, and so on. If the object is copied 15 times, the object will be sent to the old age. Old age: high survival rate of objects
Garbage collector (concrete implementation of garbage collection algorithm)
Parallelism and concurrency
Parallel Parallel: refers to multiple garbage collection threads working in parallel, but the user thread is still waiting
Concurrent Concurrent: the user thread executes simultaneously with the garbage collection thread, the user program continues to run, and the garbage collector runs on another CPU
New generation minor gc: the new generation memory is not very large, and the recovery speed of miinor gc is generally fast.
Old major gc/ full gc: in the old days, the memory is generally large, which is used to cache large objects, so the recycling speed is more than 10 times that of minor gc.
Throughput throughput:JVM runs for a total of 100 minutes, of which garbage collection takes 1 minute, so the throughput is 99%, i.e. (all-gc) / all (for batch pipeline)
Pause time: the pause time (for streaming pipeline) of the application while the garbage collector is running
Collector type
NEW
Serial, single thread
ParNew,serial multithreaded version
Parallel Scavenge, replication algorithm, parallel, priority to ensure throughput, regardless of user STW perception, throughput optimization of the system, long pause time can be accepted.
OLD/tenured
Older version of the Serial Old,Serial recycler, single-threaded, tag-collation algorithm
Older version of the Parallel Old,Parallel Scavenge recycler, multithreaded, tag-collation algorithm
Concurrent Mark Sweep, CMS: priority and shortest recovery pause time, good user experience, mark-clear algorithm
NEW and OLD
Key points: region memory partition, priority area recovery. Give priority to the region with the greatest recycling value
Garbage first, G1: it divides the entire Java heap into several equal-sized independent regions (Region). Although it still retains the concept of the new generation and the old age, the new generation and the old age are no longer physically isolated, they are both part of the collection of Region (not need to be contiguous).
Class loading subsystem (classloader sub-system): locate and import binary class files, verify the correctness of imported classes, allocate and initialize memory for class variables, and parse symbolic references
Start the class loader bootstrap classloader, which is responsible for loading legal class files under JAVA_HOME/lib
Extension class loader extension classloader, which is responsible for loading legal class files under JAVA_HOME/lib/ext
Application class loader application classloader, which is responsible for loading legal class files under the user path classpath
Custom class loader user defined classloader,class MyClassLoader extends ClassLoader
JVM loads the class through the parent delegation model, first giving it to its lowest-level parent class to load, and then trying to load it itself when the parent class cannot load. If (parent! = null) parent.loadclass (name) Recursive recursion,application classloader-> extension classloader-> bootstrap classloader
First see whether the user defined classloader is cached. If it is cached, return it directly. If not, delegate the parent classloader to load, if the parent cache is cached, return directly, otherwise delegate to the parent classloader; until the last bootstrap classloader, if the cache cannot be found, find it under its path, and return to the second level if it is found, otherwise return to its subclass and let its subclass find it under its path. Finally, go back to the custom classloader and throw an exception if it cannot be found.
Execution engine (execution engine): executes method instructions in classloader
Interpreter Interpreter: reads the source code or bytecode and executes it one by one directly (javac is outside JVM)
Just-in-time compiler Just-In-Time compiler/JIT: read the source code, more often bytecode, and then instantly compile to machine code and execute
The Java virtual machine is an imaginary computer that can run Java code. The java source file (.java) generates bytecode files (.class) through the java compiler javac, and the bytecode files (.class) are translated into machine code on specific machines through the interpreter in JVM.
That is, source code / source code / Source code/.java-> bytecode / Bytecode/.class-> machine code / Machine code/ source code / Native Code
Runtime data area (runtime data areas): when JVM runs, it needs to set aside a memory area from the entire computer memory to store what jvm needs.
Sharing within heap Heap:JVM / sharing between threads, saving all class instances / objects themselves instance, not storing basic data type objects and custom object references (these exist in the JVM Stack of each thread), is the main recycling area of gc
The method area Method Area/ is permanently shared within the Permanent Generation:JVM / between threads, saving the information of each class (class name, field information, method information) class, static variable static, etc.
Program counter Program Counter Register/PC register: shared within threads to hold the address of virtual machine bytecode instructions being executed by each thread; if the method is Native, the counter sets Undefined
Virtual machine stack JVM Stack/ thread stack: sharing within threads, references to objects of basic data types and custom objects, context of the execution environment
Local method stack Native Method Stacks: shared within threads, which is very similar to JVM Stack, except that the virtual machine stack executes Java methods (that is, bytecode) services for the virtual machine, while the local method stack serves the Native methods executed by the virtual machine.
Garbage collector open command
Command line New Generation gc Mode Old gc Mode-XX:+UseSerialGCserial Serial Collector serialOld Serial Collector-XX:+UseParNewGCparNew parallel Collector default-XX:+UseParallelGCparallel parallel Collector default-XX:+UseParallelOldGCdefaultparallel parallel Collector XX:+UseConcMarkSweepGCdefaultCMS parallel Collector-XX:+UseG1GCG1 Collector G1 Collector
According to the above table, the new generation and the old gc mode match each other to serve the garbage collector.
On the JVM architecture and GC commands are shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.