In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about what the JVM logical memory model looks like. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The logical memory model of JVM is as follows
Now let's take a look at what each does one by one!
1. Program counter
A program counter (Program Counter Register) is a small piece of memory that can be seen as a line number indicator of the bytecode executed by the current thread. When the bytecode interpreter works in the conceptual model of the virtual machine, the bytecode interpreter selects the next bytecode instruction to be executed by changing the value of this counter. Branch, loop, jump, exception handling, thread recovery and other basic functions all rely on this counter.
2. Java virtual machine stack
Like program counters, the Java virtual machine stack (Java Virtual Machine Stacks) is thread-private and has the same life cycle as threads. Virtual machine stack describes the memory model of Java method execution: when each method is executed, a stack frame is created at the same time to store local variables, operation stack, dynamic link, method exit and other information. Each method is called until the completion of execution, corresponding to a stack frame in the virtual machine stack from the stack to the stack process.
3. Local method stack
The role of the local method stack (Native Method Stacks) is very similar to that of the virtual machine stack, except that the virtual machine stack performs Java methods (that is, bytecode) services for the virtual machines, while the local method stacks serve the Native methods used by the virtual machines. The language, usage and data structure of the methods in the local method stack are not mandatory in the virtual machine specification, so the specific virtual machine can implement it freely. Some virtual machines (such as the Sun HotSpot virtual machine) directly combine the local method stack and the virtual machine stack into one. Like the virtual machine stack, the local method stack area throws StackOverflowError and OutOfMemoryError exceptions.
4. Java heap
The Java heap is an area of memory shared by all threads and is created when the virtual machine starts. The sole purpose of this memory area is to store object instances, where almost all object instances allocate memory. This is described in the Java virtual machine specification: all object instances and arrays are allocated on the heap. The Java heap is the main area managed by the garbage collector. According to the Java virtual machine specification, the Java heap can be in physically discontiguous memory space, as long as it is logically continuous, just like our disk space.
5. Method area
Like the Java heap, the method area (Method Area) is a memory area shared by each thread, which is used to store class information, constants, static variables, compiled code and other data that have been loaded by the virtual machine. Although the Java virtual machine specification describes the method area as a logical part of the heap, it has an alias called Non-Heap (non-heap), which is supposed to distinguish it from the Java heap.
Object positioning
The object is created to use the object, and the Java program needs to manipulate the specific object on the heap through the reference on the stack. There are two mainstream ways to locate and access objects on the heap: handles and direct pointers:
Handle: a piece of memory will be divided in the Java heap to serve as a handle pool. The reference stores the handle address of the object, and the handle contains the specific address information of the object instance data and the type data:
Direct pointer (used by HotSpot): in this way, the layout of the Java heap object must consider how to place the information about the access type data. The object address is directly stored in reference:
These two methods of object access have their own advantages: the biggest advantage of using handles to access is that the address of the stable handle is stored in reference, and only the instance data pointer in the handle will be changed when the object is moved (it is a very common behavior when moving objects during garbage collection), but the reference itself will not change. The biggest advantage of using direct pointer is faster, it saves the time overhead of pointer positioning, because the object access is very frequent, so this kind of overhead product is much smaller and a very considerable execution cost.
Summary:
Name feature function configuration exception stack thread private, using a continuous memory space to store local variables, operation stack, dynamic link, method exit-XSsStackOverflowError OutOfMemoryError heap thread sharing The life cycle is the same as the virtual machine saves the object instance-Xms-Xmx-XmnOutOfMemoryError program counter thread private, occupies memory small byte code line number no method area thread sharing storage class loading information, constants, static variables, etc.-XX:PermSize-XX:MaxPermSizeOutOfMemoryError thank you for reading! This is the end of this article on "what is the logical memory model of JVM?". I hope the above content can be of some help to you, so that 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.