JVM system learning path series demo code address: github.com/mtcarpenter…
preface
Hello, I’m doing, I spent more than 10 chapters in front of the carding JUC concurrent programming knowledge, if don’t know the classmates to JUC knowledge, pay attention to my public number can be directly accessed from the menu at the bottom of the mountain the carpenter 】 【, starting from this article to update the JVM related knowledge, every JAVA developer should be able to deeply understand, Multithreading, concurrency, and JVM are difficult and painful points.
Domestic JVM virtual machine learning is almost everyone, Zhou Zhiming god’s “in-depth understanding of Java virtual machine” books. The first time I read Deep Understanding the Java Virtual Machine: Advanced JVM Features and Best Practices (3rd edition), I forgot about it and remained largely at sea. Behind me in the young people love learning platform B station found a good video, is still silicon Valley 2020 the latest version of Song Hongkang JVM tutorial, is also updated more than 300 sets, for small white entry learning JVM is very helpful. [JVM system learning path] will be based on the latest version of Silicon Valley 2020 Song Hongkang JVM tutorial chapter to write a blog.
Recommended books and video video: silicon valley is the latest version of the tutorial Song Hongkang JVM 2020 B station address: www.bilibili.com/video/BV1PJ… Books: In Depth Understanding the Java Virtual Machine: Advanced JVM Features and Best Practices (3rd edition) Algorithms and Implementations for Garbage Collection The Java Virtual Machine Specification (Java SE 8th Edition)
Why do you need a JVM for learning
Running online system suddenly stuck, the system can not access, or even directly OOM!
- Wanted to solve the online JVM GC problem, but didn’t know where to start
- New project online, all kinds of JVM parameters set a blank face, directly default, run for a period of time to hang
- You have to recap the principles and concepts of the JVM before every interview, but the interviewer often asks you how to tune VM parameters in a real project, how to solve GC, OOM, etc
- Essential skills for intermediate and senior programmers
- Project management, tuning requirements
- Pursue the spirit of the geek
- For example: garbage collection algorithm, JIT (just-in-time compiler), underlying principles
How does a calculator recognize high-level languages
What do architects think about every day?
- How can I make my system faster?
- How to avoid system bottlenecks?
- Participate in performance optimization and reconstruction of existing systems to ensure platform performance and stability
- According to the business scenario and requirements, decide the technical direction and make the technical selection
- Able to independently construct and design high-concurrency distributed solutions for massive data, meeting functional and non-functional requirements
- Solve all kinds of potential system risks, core function architecture and coding
- Analyze the bottleneck of the system, solve all kinds of problems, performance tuning, etc
The JVM ecosystem
Java is one of the most widely used software development platforms. With the growth of Java and the Java community, Java is no longer simply a computer language, but a platform, a culture and a community.
- As a platform,
Java
Virtual machines play an important roleGroovy
、Scala
、JRuby
、Kotlin
Are allJava
Part of the platform
Java
It has become almost synonymous with “open source”.- Third-party open source software and frameworks. Such as
Tomcat
、Struts
,MyBatis
,Spring
And so on. - Even the JDK and JVM themselves have many open source implementations, such as
openJDK
、Harmony
。
- Third-party open source software and frameworks. Such as
- As a community,
Java
It has the largest number of technical advocates and open source community support in the world, with countless forums and materials. From desktop application software, embedded development to enterprise applications, background servers, middleware, can be seenJava
In the figure. The complexity of its application forms and the number of participants are also surprising.
Java development
A quarter of a century has passed since the first version of Java was created. In the timeline shown in Figure 1-3, we see the JDK version evolving to JDK 13. Countless Java-related products, technologies, and standards have emerged over the past two decades. Let’s step back in time and take a look at the history and evolution of Java from the time when the language was conceived.
- In 1990, the Green Team, a Sun computer group led by Patrick Naughton, MikeSheridan, and James Gosling, developed a new programming language, oak, and later Java
- In 1995, the Oak language changed its name to Java, and Java version 1.0 was officially released at SunWorld. The slogan “Write Once, Run Anywhere” was first coined in the Java language.
- .
- On January 23, 1996, JDK 1.0 was released, giving the Java language its first official runtime environment.
- On February 19, 1997, Sun released JDK 1.1. JDK 1.1 technical representatives include: JAR file format, JDBC, JavaBeans, RMI and so on.
- In 1998, the JDK reached a major milestone with the release of JDK1.2. At the same time, Sun published JSP/Servlet, EJB specifications, and the division of Java into J2EE, J2SE, and J2ME. This represents the beginning of Java’s march into enterprise, desktop, and mobile applications.
- In 2000, JDK1.3 was released and Java HotSpot Virtual Machine was officially released as the default Virtual Machine for Java.
- In 2002, JDK1.4 was released, and the old Classic virtual machine disappeared.
- Scala for the Java platform was released in late 2003, the same year Groovy joined the Java camp.
- In 2004, JDK1.5 was released. At the same time, JDK1.5 is renamed to JavaSE5.0.
- In 2006, JDK6 was released. That same year, Java was open-source and openJDK was created. Not surprisingly, the Hotspot VIRTUAL machine has also become the default virtual machine in openJDK.
- In 2007, the Java platform received a new partner, Clojure.
- In 2008, Oracle acquired BEA and acquired the JRockit virtual machine.
- In 2009, Twitter announced the migration of most of its backend applications from Ruby to Scala, another large-scale adoption of the Java platform.
- In 2010, Oracle acquired Sun, acquired the Java trademark and the most valuable HotSpot VIRTUAL machine. At this point, Oracle has HotSpot and JRockit, the two most popular virtual machines in the market, and plans to integrate them in the future: HotRockit
- In 2011, JDK7 was released. In JDk1.7U4, the new garbage collector G1 is officially enabled.
- In 2017, JDK9 was released. Make G1 the default Gc instead of CMS
- That same year, IBM made J9 open source, forming what is now the Open J9 community
- In 2018, Google awarded Oracle $8.8 billion in damages for Android’s Java infringement
- That same year, Oracle made JavagE history by donating JDBC, JMS, and Servlet to the Eclipse Foundation
- In the same year, JDK11 was released, the LTS version of the JDK, with revolutionary zGc and tweaking JDK licensing
- In 2019, JDK12 was released, joining The Shenandoah GC led by RedHat
The difference between OpenJDK and Oracle JDK
Prior to JDK11, there were some closed-source features in the oracleJDK that were not in the openJDK. But in JDK11, we can assume that the openJDK and oracleJDK code are virtually identical.
VMS and Java VMS
The virtual machine
A Virtual Machine is a Virtual computer. It is a piece of software that executes a series of virtual computer commands. In general, virtual machines can be divided into system virtual machines and program virtual machines.
- big-name
Visual Box
,Mware
Are system virtual machines, which are complete simulations of physical computers and provide a software platform that can run a complete operating system. - The typical representative of program virtual machine is the Java Virtual machine, which is specially designed to execute a single computer program. The instructions executed in the Java virtual machine are called Java bytecode instructions.
Whether it is a system virtual machine or a program virtual machine, the software running on it is limited to the resources provided by the virtual machine.
The Java virtual machine
A Java virtual machine is a virtual computer that executes Java bytecodes. It has an independent running mechanism, and the Java bytecodes it runs may not be compiled from the Java language. The languages of the JVM platform share the cross-platform features of the Java Virtual Machine, excellent garbage callback, and reliable just-in-time compilers. The core of Java technology is the Java Virtual Machine (JVM), because all Java programs run inside the Java Virtual Machine. The Java virtual machine is the runtime environment for binary bytecode, which is responsible for loading the bytecode into its interior and interpreting/compiling it into machine instructions for execution on the corresponding platform. Each Java instruction is defined in the Java Virtual Machine specification in detail, such as how to fetch operands, how to process operands, and where to put the results of processing. Features:
- Compile once, run everywhere
- Automatic memory management
- Automatic garbage collection
The location of the JVM
The JVM runs on top of the operating system and has no direct interaction with the hardware
Java architecture
JVM architecture
- HotSpot VM is one of the representative high performance virtual machines in the market.
- It uses an interpreter and just-in-time compiler architecture.
- Today, The performance of Java programs has changed so much that it can compete with C/C++ programs.
The execution engine consists of three parts: an interpreter, a just-in-time compiler, and a garbage collector
Java code executes the process
The architectural model of the JVM
The instruction stream that the Java compiler inputs is basically a stack based instruction set architecture, and another instruction set architecture is a register based instruction set architecture. Specifically: the difference between the two architectures: based on the characteristics of the stack architecture
- Simpler design and implementation, suitable for resource-constrained systems;
- Avoid the register allocation problem: use zero address instruction mode allocation.
- Most of the instructions in the instruction stream are zero-address instructions, whose execution depends on the operation stack. The instruction set is smaller and the compiler is easier to implement.
- No need for hardware support, better portability, better cross-platform implementation
Register-based architecture features
- Typical applications are x86 binary instruction sets: traditional PCS and the Android Davlik virtual machine.
- Instruction set architecture is completely dependent on hardware and has poor portability
- Excellent performance and more efficient execution
- It takes less instruction to complete an operation.
- In most cases, the instruction set based on register architecture is usually dominated by one address instruction, two address instruction and three address instruction, while the instruction set based on stack architecture is dominated by zero address instruction.
Welcome to pay attention to the public number Shanma carpenter, I am Xiao Chun brother, engaged in Java back-end development, will be a little front-end, through the continuous output of a series of technical articles to literary friends, if this article can help you, welcome everyone to pay attention to, like, share support, we see you next period!