当前位置:网站首页>Memory surge problem location

Memory surge problem location

2022-06-09 03:43:00 seven billion two hundred and fifty-eight million two hundred a

One 、 Memory related commands

Start a local web service , use jps Command to view the corresponding process .
 Insert picture description here
1. View memory information , The number of instances and the size of occupied memory .

jmap -histo PID > ./log.txt

 Insert picture description here

Open the file as follows

Field explain
num Serial number
instances Number of instances
bytes Occupied space size
class name Class name ,[C is a char[],[S is a short[],[I is a int[],[B is a byte[],[[I is a int[][]

 Insert picture description here

2. View heap information

jmap -heap PID

 Insert picture description here
Heap memory dump

jmap ‐dump:format=b,file=eureka.hprof PID

 Insert picture description here
 Insert picture description here
You can also set memory overflow to automatically export dump file , But pay attention when the memory is large , It may not lead out .

 -XX:+HeapDumpOnOutOfMemoryError 
 -XX:HeapDumpPath=./ ( route )

Two 、 Memory surge problem location Demo

test Demo

public class User {
	private int id;
	private String name;
	byte[] a = new byte[1024*100];
	public User(){}
	public User(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
}
public class OOMDumpTest {
    public static List<Object> list = new ArrayList<>();
    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        int i = 0;
        int j = 0;
        while (true) {
            list.add(new User(i++, UUID.randomUUID().toString()));
            new User(j--, UUID.randomUUID().toString());
        }
    }
}

JVM Parameter setting

‐Xms10M ‐Xmx10M ‐XX:+PrintGCDetails ‐XX:+HeapDumpOnOutOfMemoryError ‐XX:HeapDumpPath=D:\test\jvm.dump

 Insert picture description here

The generated jvm.dump File loading jvisualvm Command tool , Through the visual interface, you can see where the problem is .
 Insert picture description here

This article is for study and exchange only , Deletion of infringement contact .

原网站

版权声明
本文为[seven billion two hundred and fifty-eight million two hundred a]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090326163278.html