In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to analyze the JVM runtime data area principle, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Preface
The Java virtual machine defines several areas of run-time data that are used by programs, some of which are created as the virtual machine starts and destroyed as the virtual machine exits. Others correspond to threads one by one, and these data areas corresponding to threads are created as the thread begins and destroyed at the end of the thread.
PC register
The PC register is a small piece of memory that can be seen as a line number indicator of the bytecode executed by the current thread. Each thread needs a separate PC register, which is also the thread's private memory. If the java method is being executed, the PC register records the address of the virtual machine bytecode instruction (the address of the current instruction). Undefined if it is also the Native method. This memory area is the only one that does not specify any OutOfMemoryError conditions in the virtual machine.
Virtual machine stack
Virtual machine stack is a memory model that describes the execution of java methods. Each method creates a stack frame (Stack Frame) to store local variables, Operand stacks, dynamic links, method exits and other information. From the call to the completion of the execution of each method, there is a stack frame in the virtual machine stack from the stack to the stack process. The function of the virtual machine stack is similar to that of the traditional language stack, which is used to store local variables and some results that have not been calculated. It also plays an important role in method calls and return values.
The main content of the virtual machine stack is the stack frame. Stack frames are data structures used to store data and part of the process results, and are also used to handle dynamic links (Dynamic Linking), method return values, and exception dispatches (Dispatch Exception). The stack frame is created with the method call and destroyed with the end of the method-- whether the method completes normally or an exception is completed (an exception that is not caught within the method) is counted as the end of the method.
Method area
The method area is an unstored area that is shared by all threads. It is used to store data such as class information, constants, static variables, even compiled code, which have been loaded by the virtual machine. The size of the method area determines how many classes the system can save.
In JDK1.6 and JDK1.7, the method zone can be understood as permanent generation (only for HotSpot virtual machines, other virtual machines may not have the concept of permanent generation). Permanent generation can be specified with the parameters-XX: PermSize and-XX MaxPermSize, and by default-XX MaxPermSize is 64m. A large permanent generation can hold more class information. If the system uses some dynamic proxies, it is possible to generate a large number of classes at run time, and to ensure that there is no memory overflow, you need to set a reasonable permanent generation size. The HotSpot virtual machine extends GC generational collection to the method area, even if the permanent generation of the Java heap is used to implement the method area, so that HotSpot's garbage collector can manage this part of memory just like managing the Java heap without having to develop a special memory manager for the method area. (the main goal of memory collection with permanent belt is for constant pool recycling and type unloading, so the benefits are generally small).
In JDK1.8, the permanent generation has been removed and replaced by MetaSpace, the size of which can be specified using the parameter-XX MaxMetaSpaceSize. A large meta-space can enable the system to support more classes, just a piece of direct memory outside the stack. If you do not specify a size, by default, the virtual machine consumes all available system memory. The metadata of the class is put into direct memory, and the string pool and the static variables of the class are put into the java heap, so that the metadata of how many classes can be loaded is no longer controlled by MaxPermSize, but by the actual available space of the system.
The biggest difference between metaspace and permanent generation: permanent generation uses JVM heap memory, while metaspace uses native physical memory, so if the metaspace is not set, its size is limited by native physical memory.
Running constant pool
The runtime constant pool (Runtime Constant Pool) is part of the method area. In addition to the description of the version, field, method, interface and other information of the class in the Class file, another piece of information is the constant pool, which is used to store all kinds of literals and symbol references generated during compilation. This part of the content will be stored in the runtime pool of the method area after the class is loaded. The Java virtual machine has strict rules on the format of every part of the Class file (including the constant pool, of course). Every byte used to store which kind of data must meet the specification requirements, so that it can be recognized, loaded and executed by the virtual machine.
Another feature of the runtime constant pool compared to the constant pool of Class files is that it is dynamic. The Java language does not require constants to be generated at compile time, nor does the constant pool content in the Class file enter the runtime constant pool, such as the intern () method of String.
Local method stack
The function of the local method stack is similar to that of the virtual machine stack, except that the virtual machine stack serves to execute Java methods, while the local method stack serves Native methods. The language, mode and data structure used by the heap local method stack in the virtual machine specification are not mandatory, so the virtual machine can implement it freely. Even some virtual machines (such as HotSpot virtual machines) directly combine the local method stack and the virtual machine stack into one.
Java reactor
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 hold instances of objects, where almost all (but not all) instances of objects are allocated memory. Because modern virtual machines adopt generation-by-generation collection algorithm, Java heap can be subdivided into new generation (Eden area, From Survivor area and To Survivor area) and old age from the point of view of GC.
The new generation is used to store new objects. It generally occupies 1 stroke and 3 spaces of the heap. Due to the frequent creation of objects, the new generation will frequently trigger MinorGC for garbage collection. The Cenozoic era can be divided into three regions: Eden, ServivorFrom and ServivorTo.
The Eden zone is the birthplace of new Java objects (if the newly created object takes up a lot of memory, it is allocated directly to the old age). When there is not enough memory in the Eden area, MinorGC will be touched to carry out a garbage collection in the Cenozoic area. The survivor of ServivorFrom's last GC, as the scanner of the GC this time. ServivorTo . Retained a survivor of the MinorGC process.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.