In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to understand JAVA JVM, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
What is JVM?
JVM is the abbreviation of Java Virtual Machine (Java Virtual Machine). JVM is a specification for computing devices. It is a fictional computer, which is realized by simulating various computer functions on a real computer.
There are many virtual machines on the market.
Understanding the structure of JVM, through reasonable parameter configuration, will help us to give better play to the performance of JVM.
Memory structure
The main components of memory space
Method area
The method area (Method Area), which is the memory area shared by each thread, is used to store data such as type information, constants, static variables, and code cache compiled by the real-time compiler that have been loaded by the virtual machine.
Heap
For Java applications, the Java heap (Java Heap) is the largest block of memory managed by a virtual machine. 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 in the Java world allocate memory.
Virtual machine stack
A thread is private and its life cycle is the same as that of a thread. The virtual machine stack describes the thread memory model of Java method execution: when each method is executed, the Java virtual machine synchronously creates a stack frame (Stack Frame) to store local variables, Operand stack, dynamic connection, method exit and other information. The process in which each method is called until it is executed corresponds to the process of a stack frame in the virtual machine stack from entering the stack to leaving the stack.
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 executes Java methods (that is, bytecode) services for the virtual machine, while the local method stack serves the local (Native) methods used by the virtual machine.
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. It can be understood as marking what the next line of the program executes.
Method area, heap, thread sharing
Virtual machine stack, local method stack, program counters, thread private, when creating a thread (which can be understood as running a method), create a stack frame that specifically serves this thread
Memory allocation
Heap memory is the main memory we use, and the composition of heap memory is as follows
Including the younger generation and the older generation (the default ratio is 1:2)
Younger generation:
1.1 contains one Eden, two Survivor (default ratio 8:1:1). The younger generation is used to save newly created objects. If the younger generation does not have enough memory, a MinorGC will be performed. If you go through 15 MinorGC (default), those who are still alive will be transferred to the old age (if the new object is young and can not be put down, it will be put directly to the old age).
1.2 the younger generation uses the replication algorithm to divide the memory area into two blocks (Eden+Survivor and another Survivor). One block is used each time, and when GC moves the contents of one block to another, the objects in the original memory can be reclaimed.
Old age:
2.1 when there is not enough memory in the old days, there will be a MajorGC (it is also said to be FullGC)
Because GC will cause "Stop the world" and thread pause, it is necessary to reasonably adjust the heap memory size and allocate the proportion of the younger generation to the older generation, so as to achieve the purpose of reducing GC frequency and GC time.
Garbage collection
Almost all the object instances in the Java world are stored in the heap, and the first thing the garbage collector does before collecting the heap is to determine which of these objects are "alive" and which are "dead" (that is, objects that can no longer be used in any way).
The "reference counting algorithm" is generally used to determine the reference.
Memory optimization adjustment
To sum up, the purpose of memory tuning is to improve code execution efficiency, reduce GC frequency, and reduce GC time, which requires reasonable allocation of heap memory (total heap size, younger generation size).
Download installation tools and use tools: JDK Mission Control abbreviated as JMC
Download and install reference https://www.cnblogs.com/jhxxb/p/13279286.html
Local programs can be seen directly in the tool, or you can connect to JVM remotely. Generally, flight data is generated on the server, downloaded to the local server, and then opened with the tool.
Startup program
Generally, set the JVM parameter first and run the program (- Xms1024m-Xmx1024m-Xmn512m)
Xms: initial heap size, default idle memory 1x64
Xmx: maximum heap size, default physical memory 1x4
Xmn: Cenozoic size (25% 50% of the recommended heap for new objects). Default is 1max 3 for the entire heap.
Collect the flight data of the program
Jcmd JFR.start delay=10s duration=15m filename=log.jfr
Description: pid: the process number of the service. Use ps-ef | grep java query. (remove angle brackets when using)
Delay: delayed startup configuration. Delay=10s represents a delay of 10 seconds to start.
Duration: refers to the duration of logs collected. Duration=15m, which stands for collecting 15 minutes of JVM information.
Filename: means that the collected logs are stored in the specified log file. Filename=log.jfr, which represents storing the collected logs in log.jfr.
After reading the above, have you mastered how to understand JAVA JVM? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.