jvisualvm analyzes hprof files

jvisualvm is the dump file analysis tool that comes with jdk1.8. The hprof file is the jvm. When an OutOfMemory exception occurs, the JVM will put the current virtual machine heap and other information into the hprof file, the name is approximately java_pid plus the process number , Such as: java_pid11656.hprof.

jvisualvm

The jvisualvm tool is an analysis tool that comes with jdk, which is not found in jdk11

Insert picture description here

Corresponding parameter configuration

The process of analyzing hprof files requires a large amount of calculation and consumes more memory. You can modify the corresponding configuration parameters

Insert picture description here

# Options used by VisualVM launcher by default:
# (can be overridden by explicit command line switches)
#

visualvm_default_options="-J-client -J-Xms124m -J-Xmx512m -J-Dsun.jvmstat.perdata.syncWaitMs=10000 -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.d3d=false -J-Dnetbeans.keyring.no.master=true -J-Dplugin.manager.install.global=false"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea

Insert picture description here

Insert picture description here

Analysis

The selected class is sorted according to the number of instances or size
, and the code position of the memory overflow can be located
Insert picture description here

Code:

package com.fancv.jvm;

import java.util.LinkedList;
import java.util.List;

public class MyOutofMemory {
    
    

    public static void main(String args[]) {
    
    

        List<Demo> mylist = new LinkedList<>();
        while (Boolean.TRUE) {
    
    
            mylist.add(new Demo());
        }
    }

}

class Demo {
    
    

    public Demo() {
    
    
    }
}

Startup parameters:

-XX:+HeapDumpOnOutOfMemoryError -Xmx200m  -Xmx300m

Guess you like

Origin blog.csdn.net/keep_learn/article/details/106876610