In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the memory structure in JVM is like, it has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The figure shows the datazone when the Java virtual machine is running:
1. The method area, also known as "permanent generation" or "non-heap", is used to store class information, constants, static variables, and memory areas that are shared by each thread. The default minimum value is 16MB and the maximum value is 64MB (unvalidated), and the size of the method area can be limited by the-XX:PermSize and-XX:MaxPermSize parameters.
Runtime pool: is part of the method area, Class file in addition to the class version, fields, methods, interfaces and other description information, there is also a constant pool of information, which is used to store a variety of symbolic references generated by the compiler, this part of the content will be loaded into the method area after the runtime pool.
two。 The virtual machine stack describes the memory model of java method execution: when each method is executed, a "stack frame" is created to store local variables (including parameters), operation stack, method exit, and so on. Each method is called to the process of execution, corresponding to a stack frame in the virtual machine stack from the stack to the stack process. The declaration cycle is the same as the thread and is private to the thread.
The local variable table stores a variety of basic data types known to the compiler (boolean, byte, char, short, int, float, long, double) and object references (reference pointers, not the object itself). Among them, 64-bit long and double type data will take up the space of two local variables, and only one of the other data types. The memory space required by the local variable table is allocated during compilation. When entering a method, how many local variables need to be allocated in the stack frame is completely determined. During the run, the stack frame does not change the size space of the local variable table.
3. The local method stack is basically similar to the virtual machine stack, except that the virtual machine stack serves the java methods executed by the virtual machine, while the local method stack serves the Native methods.
4. Heap, also known as java heap or GC heap, is the largest memory area managed by the java virtual machine, and it is also a memory area shared by various threads, which is created when JVM starts. This memory area holds the object instance and array (all new objects). Its size is set by the-Xms (minimum) and-Xmx (maximum) parameters,-Xms is the minimum memory requested when JVM starts, and-Xmx is the maximum memory that can be requested by JVM. When JVM starts, the maximum memory is retained. The address space reserved for object memory can be divided into the younger generation and the older generation.
By default, when the free heap memory is less than 40%, JVM increases the Heap to the size specified by-Xmx, and you can specify this ratio column through-XX:MinHeapFreeRation=. When the free heap memory is greater than 70%, JVM reduces the size of heap to the size specified by-Xms, which can be specified by XX:MaxHeapFreeRation=. For running systems, the value of-Xms is usually the same as that of-Xmx to avoid frequently adjusting the size of Heap at run time.
Parameter
Default Value
MinHeapFreeRatio
forty
MaxHeapFreeRatio
seventy
-Xms
3670k
-Xmx
64m
Note: in the case of 64-bit systems, these values generally need to be expanded by 30% to accommodate larger objects on 64-bit systems.
Since J2SE 1.2, JVM has used generational collection algorithms, using different algorithms in regions of different ages. The heap is divided into the new generation and the old age. The new generation mainly stores newly created objects and objects that have not yet entered the old age. The old age stores objects that still survive many times of Cenozoic GC (MinorGC).
Note 1: the Perm in the figure is not heap memory, but permanent.
Note 2: the Virtaul in the figure is the memory that has not been allocated in each area, that is, the maximum memory-the currently allocated memory.
Cenozoic: the Cenozoic includes one eden (Garden of Eden) and two survivor (usually called S0 and S1 or From and To). Most objects are initialized in eden. For two survivor, one is always empty and will serve as the active object in the eden and the destination for the other survivor during the next replication collection. Before objects age (that is, before they are copied to the tenured), they are replicated in this way between two survivor regions. You can use the-Xmn parameter to specify the size of the new generation, or you can use-XX:SurvivorRation to adjust the size of Eden Space and Survivor Space.
Old age: used to store objects that are still alive after many new generations of Minor GC, such as cache objects, new objects may also directly enter the old age, there are two main cases: ①. Large objects can be allocated directly in the old age instead of being allocated in the new generation by setting the startup parameter-XX:PretenureSizeThreshold=1024 (in bytes, the default is 0). two。 Large array objects, that is, no external objects are referenced in the array.
The memory occupied by the old age is the corresponding value of-Xmx minus the corresponding value of-Xmn.
5. The program counter is the smallest memory area, and its function is to indicate the line number of the bytecode executed by the current thread. In the model of the virtual machine, the bytecode interpreter works by changing the value of this counter to select the next bytecode instruction to be executed. Basic functions such as branching, looping, exception handling, thread recovery and so on need to rely on the counter.
Thank you for reading this article carefully. I hope the article "what is the memory structure in JVM" shared by the editor will be helpful to everyone? at the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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