Home > Java > Java Tutorial > body text

Java JVM virtual machine tuning methods

WBOY
Release: 2023-04-19 10:04:02
forward
1195 people have browsed it

jmap View memory information

jmap histo /pid > ./log.txt: View the number of instances of a process, the number of bytes of memory occupied, and the class it belongs to

Java JVM virtual machine tuning methods

jmap -heap /pid: View heap information

Java JVM virtual machine tuning methods

Java JVM virtual machine tuning methods

##jmap ‐dump:format=b, file=app.hprof /pid

Java JVM virtual machine tuning methods

Java JVM virtual machine tuning methods

Start the jvm visual management interface through the jvisualvm command and import the dump file for analysis: View instances of classes

Java JVM virtual machine tuning methods

jstack

Analyze deadlock: write a piece of deadlock code

public class DeadLockTest {
    private final static Object lock1 = new Object();
    private final static Object lock2 = new Object();
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock1) {
                    try {
                        System.out.println(Thread.currentThread().getName() + ": get the lock1");
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (lock2) {
                        System.out.println(Thread.currentThread().getName() + ": get the lock2");
                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock2) {
                    try {
                        System.out.println(Thread.currentThread().getName() + ": get the lock2");
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (lock1) {
                        System.out.println(Thread.currentThread().getName() + ": get the lock1");
                    }
                }
            }
        }).start();
    }
}
Copy after login

Java JVM virtual machine tuning methods

"Thread- 1" thread name; prio=5 priority=5; tid=0x0000000019aa9000 thread id; nid=0x6c4 thread corresponding local thread identification nid; java.lang.Thread.State: BLOCKED thread state

Start jvisualvm command Select the corresponding process to view the deadlocked thread

Java JVM virtual machine tuning methods

Jstack analyzes the stack information of threads with high CPU usage

Start a while loop to make the CPU Keep working

1. top -p /pid: Check the resource usage of the process

Java JVM virtual machine tuning methods

It is obvious that the process causes the CPU usage to be almost 100%.

2. Press H to view the resources occupied by each thread in the process

Java JVM virtual machine tuning methods

#3. Find the PID column that uses nearly 100% of the CPU, indicating the thread tid is 5027, convert it to hexadecimal to 13a3 through the converter,

4. Execute jstack 5026|grep -A 10 13a3 through jstack command, you can get the stack information of thread tid 13a3, and then find the cause Execution line number with 100% CPU usage

Java JVM virtual machine tuning methods##jinfo View jvm system parameters

jinfo -flags /pid: View jvm parameters

Java JVM virtual machine tuning methodsjinfo -sysprops /pid: View the system parameters of java

##Jstat View the amount of heap memory usage and class loading informationJava JVM virtual machine tuning methods

jstat -gc /pid: Garbage collection statistics

S0C: The size of the first survivor area, in KB; S1C: The size of the second survivor area; S0U: The used size of the first survivor area; S1U: the used size of the second survivor area; EC: the size of the Eden Garden; EU: the used size of the Eden Garden; OC: the old generation size; OU: the used size of the old generation; MC: Method area size (metaspace); MU: method area usage size; CCSC: compressed class space size; CCSU: compressed class space usage size; YGC: number of young generation garbage collections; YGCT: young generation garbage collection consumption time, unit s; FGC: Number of old generation garbage collections; FGCT: Old generation garbage collection time consumption, unit s; GCT: Total garbage collection time consumption, unit sJava JVM virtual machine tuning methods

jstat -gccapacity/pid: Heap memory statistics

NGCMN: the minimum capacity of the new generation; NGCMX: the maximum capacity of the new generation; NGC: the current capacity of the new generation; S0C: the size of the first survivor area; S1C: the size of the second survivor area; EC: the size of Eden Garden; OGCMN: the minimum capacity of the old generation; OGCMX: the maximum capacity of the old generation; OGC: the current old generation size; OC: the current old generation size; MCMN: the minimum metadata capacity; MCMX: the maximum metadata capacity; MC : Current metadata space size; CCSMN: Minimum compression class space size; CCSMX: Maximum compression class space size; CCSC: Current compression class space size; YGC: Number of young generation GCs; FGC: Number of old generation GCsJava JVM virtual machine tuning methods

jstat -gcnew /pid: View the new generation garbage collection statistics

TT: The number of times an object survives in the new generation; MTT: The maximum number of times an object survives in the new generation; DSS: Expected survivor area sizeJava JVM virtual machine tuning methods

jstat -gcnewcapacity/pid: Check the new generation memory capacity

S0CMX: Maximum survivor area size 1; S1CMX: Maximum survivor area 2 Zone size; ECMX: Maximum Eden Zone sizeJava JVM virtual machine tuning methods

jstat -gcold /pid: View old generation garbage collection statistics

##jstat -gcoldcapacity/pid: View old generation garbage collection statistics Memory capacity

Java JVM virtual machine tuning methods

jstat -gcmetacapacity/pid: View metadata space statistics

Java JVM virtual machine tuning methods

You can optimize the startup parameters of java applications through the jstat gc -pid command. jstat -gc pid 1000 10 (execute the command every 1 second, 10 times in total) to estimate how many new objects will be added to the Eden area per second. The time can be adjusted based on specific results. In fact, the optimization idea is simply to try to make the surviving objects after each Young GC less than 50% of the Survivor area, and keep them in the young generation. Try not to let the object enter the old age. Try to reduce the frequency of Full GC as much as possible to avoid the impact of frequent Full GC on JVM performance.

Memory Leak

For some old data, such as jvm-level memory is not cleaned up in time, resulting in more and more data being piled up. Over time, full gc will be frequently caused, thus causing memory loss. leakage. You can use the mature cache architecture ehcache, which has implemented LRU data elimination strategy.

The above is the detailed content of Java JVM virtual machine tuning methods. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!