Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to explain the JVM memory model in the most popular way

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to use the most popular way to explain the JVM memory model, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

What is JVM? What is the JVM memory model?

Note: this article is based on JDK1.8, and there is a slight gap between before and after 1.8. this article will only introduce the versions before 1.8.

To put it bluntly, JVM is a program, and after this program is run, it is a computer, and it is very similar to the computer we usually use, it is a virtual computer. So what is the JVM memory model? It was several great gods who wrote a memory model of a virtual computer running on a computer. What is the memory model of the computer?

For all the functions, I believe that a considerable number of people who are not engaged in the industry know its general function, but let's roughly explain the name | Speed | introduction-register | very fast | short and lean data such as temporary instructions. Stack | Speed block | Spatial continuity. Heap | slow speed | discontiguous space, but much faster than hard disk. Hard disk | slowest | it is a warehouse.

that! This article will explain the following pictures carefully in this picture!

Add a virtual machine

Next, we add a virtual machine to this computer. Since we say that a virtual machine is the same as a computer, let's put all the above stack and other things into the computer. So where should I put it?

The register won't work.

The stack is too small.

The heap is OK, but the space is not continuous. We can do it ourselves.

The hard disk is a physical storage, and it doesn't work either.

From the top, put it in the heap, so it looks like the following.

This diagram is also easy to understand, that is, registers, stacks, stacks and hard drives are all placed in the operating system stack. OK, we put the virtual machine in, so what's next? I don't seem to have a clue. Now that we have a virtual machine, let's run it. Now there are two questions.

How does it work? JVM is a C language program.

What is the function of this program? You are running a .class file.

To put it simply, when the program is running, it will start a function called the classloader. After loading the .class file, the classloader will put the different contents of the file into these different areas of the stack. So what is written in each of these areas? | region name | Storage content | Features:-|:-|:-register | Line to which the code is running (jargon: line number indicator of the bytecode being executed by the current thread) | Space is small and will not overflow. Local method stack is generated or killed with thread | native method executed by JVM | HotSpot virtual machine does not distinguish between virtual machine stack and local method stack. Both are one stack. | 1. Local variable 2. Operation stack 3, dynamic link 4. Return address | first-in, last-out, bucket structure heap | 1. Instance object 2. Array 3. String constant pool 4. Static constant | the garbage collector will collect unreferenced objects and array metadata areas (called method areas before 1.8) | 1. Class information 2. Compiled code 3. Run-time pool | method area before 1.7, non-heap in heap, local memory after 1.7, metadata area. I'll explain it in detail one by one.

1. Local method stack (thread private)

This knowledge point is relatively simple, = = the object of the local method stack service is the native method executed by JVM. In short, when the thread starts to call the local method, it is not constrained by JVM. Too many nativa methods will affect the portability of virtual machines.

two。 Heap (shared by threads)

Why put the stack in front of the stack, because this part is more important, and it is the basic part.

The content in the heap is common to threads, and all threads access the heap in the same area.

2.1 storing content

The data stored in the heap are object instances and arrays such as:

User user = new User (); / / User is a common Model class in the system, ↑ └─ new comes out of this thing, just in the heap, controller synonymous ↓ UserController uc = new UserController (); / / common classes in mvc mode

The heap is the largest and contains the most things. There are more and more things in it, but the memory is so large that one day it will be full, so the useless things in the heap will be recycled. So the great gods divided the heap into several areas, which are:

String constant pool: it is actually a hash table written by C++. All strings are stored in the constant pool. In the http://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/9732f3600a48/src/share/vm/classfile/symbolTable.hpp definition of the old age: the proportion is about 2 Cenozoic: the ratio is about 1, of which the Cenozoic is divided into: Eden area: accounting for 8 Suivivor 10 Suivivor 0 of the Cenozoic era; accounting for 1 Suivivor 1 area of the Cenozoic era Of course, the size and scale can be modified by command.

As shown in the figure:

Change to an official picture.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report