mention Java virtual machine （JVM）, Probably most people's first impression “ difficult ”, But let's really walk in “JVM The world ” When , We will find that the problem is not as complicated as we thought . The only thing that really scares us , It's the fear itself . But as a whole JVM The first in a series , This article will take you through the beginning of learning JVM When a variety of doubts . such as ： What is? JVM？ Why study JVM？ How to study effectively JVM？ Take these questions with you , Let's walk in together JVM In the world! .
One 、 Why study JVM？
Study JVM There are several reasons ：
1、 Application tuning
Different procedures （ Business scenario ） Need different Jvm To configure , For example, set different garbage collectors 、 Set the memory configuration and proportion of the new generation and old generation , Different configurations have very different effects on the execution of a program . and Jvm The default configuration only guarantees that the program can “ function ”, And want to “ It works fine ” Even “ Better run ”, Is learning Jvm One of the most important factors .
2、 Troubleshoot program running problems
Some programs may encounter all kinds of problems when they are used online , And these problems are often fatal , Like a memory leak , Deadlock causes the program to run slowly, etc , These problems are easily overlooked during the development and small concurrent testing phases , So study Jvm At a critical time , Help you clean up the system when you're in danger “ ills ”.
3、 Master the fundamental and principle of program execution
That's what a lot of people say ： Not only should “ Know what it is ”, still more “ Know why ”.
4、 To avoid errors in writing code
For example, avoid overloading calls to variable-length parameters （ Specific cases will be given in the following articles ）.
5、 To cope with the interview
I have to say that's one of the things that a lot of people study for , It is also a positive force , If you understand “ Catfish effect ” Words .
6、 Master the general mechanics of other languages
JVM There is also a strong point , It doesn't just work Java Program , It also works Scala、Clojure、Groovy, And what's hot right now Kotlin, Study JVM You can then understand the general mechanics of these languages , Even allowing these languages to share ecosystems .
Two 、 What is? JVM？
JVM brief introduction ：
JVM yes Java Virtual Machine Abbreviation , Chinese translation for Java virtual machine , Is a specification for computing equipment , It's an imaginary computer , It is realized by simulating various computer functions on a real computer . Simply speaking JVM It's for parsing and running Java programmatic .
Java There is a very important feature “ Platform independence ”, Is the use of JVM Realized .Java The language just needs to be generated Jvm Object code running on （ Bytecode ）, It can run unmodified on multiple platforms , because JVM It blocks platform-specific information , bring Java can “ A compilation , Run anywhere ”.
3、 ... and 、 How to study effectively JVM？
So that's learning JVM Benefits of , But how to learn effectively JVM Well ？ Someone might see it “JVM” perhaps “Java virtual machine ” These few words are muddled , I don't know what it is , Not to mention how . And this section is going to teach you how to learn effectively. Right JVM, hold JVM Make a division of knowledge points . so to speak , Master the following listed knowledge points , You have the whole thing JVM.
JVM Knowledge points of , Divided into the following ：
1、 JVM The composition of
Only to understand JVM Component part , To calculate the real understanding JVM,JVM The composition of 5 Parts of ： Pile up 、 Virtual machine stack 、 Native Method Stack 、 Program counter 、 Method area , This will be covered in the following articles 5 The specific purpose of each part .
2、 Multiple garbage collection algorithms
Jvm There are a lot of garbage collection algorithms , Different algorithms have different advantages and disadvantages , such as ： Tag clearing algorithm and replication algorithm 、 A clearly marked algorithm produces a variety of space debris 、 The replication algorithm divides the memory into two pieces , Although the performance is very good but can only use one at a time , Wasted memory space , There's no perfect algorithm ？ The answer is yes , Because of the space , More on that later in the article .
3、 Multiple garbage collectors
Jvm There are many garbage collectors , For example, the earliest version of the serial collector Serial, Development of the oldest collector , It is a new generation collector using replication algorithm , It is a single-threaded collector , It's doing garbage collection , All other worker threads must be suspended , until Serial Collector collection ends （“Stop The World”）. also CMS（Concurrent Mark Sweep） A collector is one that aims to obtain the shortest recovery pause time ; There are more advanced ones G1（Garbage-First） The collector etc. .
Learn about these collectors , One is to configure the appropriate collector for your program , On the other hand, each collector has different Settings , After learning the configuration of these collectors , You can set optimal run matching parameters for your program .
4、 JVM Analysis tools
Jvm Analysis tools are used to troubleshoot bugs in a running program , Find out what's wrong with the program , In order to ensure the stable operation of the program ,Jvm Analyzers are divided into ： Command line tools （ Officially, it's an experimental tool , But stability is not in doubt ）, There are also view analysis tools , The former is certainly superior to the latter , But the latter is based on the former , Each of these tools will be explained in more detail later in this series .
5、 Java Class loading mechanism
Java Class loading mechanism , It's about Java The class in Jvm Load and run mechanism in , To understanding Java How does it work that helps a lot , This is also learning Java Very interesting point , You can see Java The whole process of running , It's completely transparent , Give a person a kind of “ Sense of control ”, This is a Java Language is inherently supportive , So it feels like Java This language is very interesting .
6、JVM Commonly used optimized configuration
Study Jvm The biggest benefit is actually , Use Jvm These common configurations , Make your program run more efficiently , So it is essential for this aspect of learning .
This article leads you to the right Jvm The overall impression has the preliminary understanding , got it Jvm Learning can bring us benefits , as well as Jvm How to learn , And these questions are just beginning to be learned Jvm Is the biggest obstacle . Everything is difficult at the beginning , Well begun is half done , Congratulations on your study Java An indispensable skill in your field .
If you want to learn for free （Java engineering 、 High performance and distributed 、 Microservices 、Spring,MyBatis,Netty Source code analysis ） Can add programmers Java Advanced group ：875511259, In the group, Ali Daniu explained the sharing technology , And large Internet technology videos , We all share it for free .