In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what is the difference between Jvm memory structure, Java memory model and Java object model in Java common knowledge points. The content of the article is of high quality, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of related knowledge after reading this article.
As we all know, Java code is intended to run on a virtual machine, and the virtual machine divides the memory it manages into several different data regions during execution of Java programs, each with its own purpose. Some of these zones exist as virtual machine processes start, while others are created and destroyed depending on the start and end of user threads.
The function of each region is not the focus of this article, so it is not described in detail here. Here are a few points that need special attention:
The above is the Java Virtual Machine specification, different virtual machine implementations will vary, but generally adhere to the specification.
The method area defined in the specification is only a conceptual area and describes what it should do. But there's no definition of where that zone should be. Therefore, for different virtual machine implementations, there are certain degrees of freedom.
Different versions of the method area are located in different locations. The division in the above figure is a logical area, not an absolute physical area. Because some versions of JDK have method areas implemented in the heap.
The runtime constant pool is used to store various literals and symbolic applications generated at compile time. However, the Java language does not require constants to be generated only at compile time. String.intern also puts new constants into the pool during runtime, for example.
In addition to the JVM runtime memory described above, there is another memory area available, which is direct memory. The Java Virtual Machine specification does not define this memory area, so it is not managed by the JVM, but is a memory area that is directly applied outside the heap using the local method library.
Heap and stack data partition is not absolute, such as HotSpot's JIT will be optimized for object allocation.
To summarize, JVM memory structures are defined by the Java Virtual Machine specification. Describes the different data regions managed by the JVM during Java program execution. Each area has its own specific function.
II. Java memory model
JMM describes a set of rules that control how variables in a program access shared data areas and private data areas. JMM revolves around atomicity, orderliness, and visibility.
Java memory model looks similar to Java memory structure (JVM memory structure), many people mistakenly think that the two are the same thing, which also leads to interview process often do not answer.
In the previous diagram of the JVM's memory structure, we can see that the areas where Java heap and methods are shared by multiple threads are data areas. That is, multiple threads may be able to manipulate the same data stored in the heap or method area. This is what we often call "Java threads communicate through shared memory."
JMM (Java Memory Model) is not as real as JVM memory structure. He is just an abstract concept. JMM is related to multithreading and describes a set of rules or specifications that define how one thread's writes to shared variables are visible to another thread.
Then, in a simple summary, Java multithreads communicate through shared memory, and because shared memory is used for communication, there will be a series of problems such as visibility, atomicity, sequencing, etc. in the communication process, and JMM is built around multithread communication and a series of characteristics related to it. JMM defines some syntax sets that map to Java language keywords such as volatile and synchronized.
In Java, JMM is a very important concept, it is because of JMM, Java concurrent programming can avoid many problems.
III. Java object model
Java is an object-oriented language, and Java objects are stored in the JVM with a certain structure. This storage model for Java objects themselves is called the Java Object Model.
In HotSpot virtual machine, an OOP-Klass Model is designed. OOP (Ordinary Object Pointer) refers to an ordinary object pointer, while Klass is used to describe the specific type of object instance.
For each Java class, when loaded by the JVM, the JVM creates an instanceKlass for that class, which is stored in the methods area and used to represent the Java class at the JVM level. When we create an object using new in Java code, the JVM creates an instanceOopDesc object that contains the object header and instance data.
This is a simple OOP-Klass model of Java objects, the Java object model.
IV. summary
Let's distinguish between JVM memory structure, Java memory model and Java object model.
JVM memory structure, and Java virtual machine runtime area related.
Java memory model, and Java concurrent programming related.
Java object model, and Java objects in the virtual machine in the form of representation.
About Java common knowledge points in Jvm memory structure, Java memory model, Java object model difference is what to share here, I hope the above content can have some help for everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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.