【一】java 虚拟机 监控示例 Eclipse Memory Analyser
1.堆内存溢出示例代码
import java.util.ArrayList;
import java.util.List;
public class TestHeap {
public static void main(String[] args) {
List<User> list = new ArrayList<>();
while(true) {
list.add(new User()); }
}
}
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.chaoyijuechen.easypoi.TestHeap.main(TestHeap.java:10)

问:这是个小程序,可以快速定位内存溢出的位置,若是大应用中呢?代码上百万行,很难通过代码定位。这时该如何定位呢?
答:通过分析工具定位!
问:如何通过分析工具定位?
答:首先,将内存转储成一个快照,然后通过快照对当前环境进行分析。
问:如何生存快照?
答:通过Java虚拟机的参数设置!
-XX:+HeapDumpOnOutOfMemoryError 将Java堆内存溢出的堆存储快照dump
-vmargs //虚拟机设置
-Xms40m //初始内存
-Xmx256m //最大内存
-Xmn16m //最小内存
-XX:PermSize=128M //非堆内存
-XX:MaxPermSize=256M
最终会生成文件在项目根目录下:java_pid1124.hprof,内容如下: ( java version 1.8.0_181)
4a41 524f 4c45 2e30
2e31
7fe8 4b05 81d0
4c5f 4f4e
007f e84c 04c2 d073 756e 2f73
792f 706b 2f43 6f6e
6e74 496e 666f
45aa 4c6a 612f
696c 2f53 3c54 453b 3e3b 4c6a
612f 6c61 6e67 2f4f 626a 743b 406c 696e 6b4d 686f
1f00 007f e84a 41ec 106e
616d 6e64 496e 666f
4f66 1a00
007f e84b 84ab 6e27
206e 756c 6c01
001c 8fa0 416c
614e 756d 6e67
437a
4c6a 612f 6c61 6e67 2f43 6c61
3c2a 3e3b 4c6a 612f 6c61 6e67 2f43
6c61 3c2a 3e3b 295a
45b0 e028 4c6a
612f 6c61 6e67 2f53 696e 673b 5b4c
6a61 2f6c 616e 672f 6e67
3b4c 6a61 2f69 6f2f 6c65 3b29
..........
不同版本的jdk生存的快照文件可能不一样。 ( java version 1.8.0_144)

然后下载Eclipse Memory Analyer分析工具进行分析
【Mac版 Eclipse Memory Analyzer报错问题】MemoryAnalyzer-1.8.1.20180910-macosx.cocoa.x86_64.zip
下载后双击解压:在文件夹窗口的显示名称是mat,命令行中看名称是mat.App。鼠标双击mat,报如下错误错

查看此log文件
!SESSION -- ::43.357 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_181
java.vendor=Oracle Corporation
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=zh_CN
Framework arguments: -keyring /Users/guchunchao/.eclipse_keyring
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -keyring /Users/guchunchao/.eclipse_keyring !ENTRY org.eclipse.osgi -- ::48.803
!MESSAGE Application error
!STACK
java.lang.IllegalStateException: The platform metadata area could not be written: /private/var/folders/37/y__4k3h10q77946z33vk7hqm0000gn/T/AppTranslocation/65F1F51A-AE28-408E-BD87-E0A4EAA7E11E/d/mat.app/Contents/MacOS/workspace/.metadata. By default the platform writes its content
under the current working directory when the platform is launched. Use the -data parameter to
specify a different content area for the platform.
at org.eclipse.core.internal.runtime.DataArea.assertLocationInitialized(DataArea.java:)
at org.eclipse.core.internal.runtime.DataArea.getStateLocation(DataArea.java:)
at org.eclipse.core.internal.preferences.InstancePreferences.getBaseLocation(InstancePreferences.java:)
at org.eclipse.core.internal.preferences.InstancePreferences.initializeChildren(InstancePreferences.java:)
at org.eclipse.core.internal.preferences.InstancePreferences.<init>(InstancePreferences.java:)
at org.eclipse.core.internal.preferences.InstancePreferences.internalCreate(InstancePreferences.java:)
at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:)
at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:)
at org.eclipse.core.internal.preferences.PreferencesService.createNode(PreferencesService.java:)
at org.eclipse.core.internal.preferences.RootPreferences.getChild(RootPreferences.java:)
at org.eclipse.core.internal.preferences.RootPreferences.getNode(RootPreferences.java:)
at org.eclipse.core.internal.preferences.RootPreferences.node(RootPreferences.java:)
at org.eclipse.core.internal.preferences.AbstractScope.getNode(AbstractScope.java:)
at org.eclipse.core.runtime.preferences.InstanceScope.getNode(InstanceScope.java:)
at org.eclipse.ui.preferences.ScopedPreferenceStore.getStorePreferences(ScopedPreferenceStore.java:)
at org.eclipse.ui.preferences.ScopedPreferenceStore.<init>(ScopedPreferenceStore.java:)
at org.eclipse.ui.plugin.AbstractUIPlugin.getPreferenceStore(AbstractUIPlugin.java:)
at org.eclipse.ui.internal.Workbench.lambda$(Workbench.java:)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:)
at org.eclipse.mat.ui.rcp.Application.start(Application.java:)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:)
at org.eclipse.equinox.launcher.Main.run(Main.java:)
原因:/private/var/folders/37/y__4k3h10q77946z33vk7hqm0000gn/T/AppTranslocation/65F1F51A-AE28-408E-BD87-E0A4EAA7E11E/d/mat.app/Contents/MacOS/workspace/.metadata文件是只读的。
解决方案:
1、新建/Users/guchunchao/eclipse-analyser-log 目录
2、重新定义log文件所在位置:打开mat.app/Contents/Eclipse/MemoryAnalyzer.ini,填入如下2行数据,位置一定要放在 --launcher.library之前
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-.jar
-data
/Users/guchunchao/eclipse-analyser-log
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.700.v20180518-
-vmargs
-Xmx1024m
-Dorg.eclipse.swt.internal.carbon.smallFonts
-XstartOnFirstThread
将mat复制到【应用程序】中,这样就可以通过【启动台】点击打开了

图1

图2


【一】java 虚拟机 监控示例 Eclipse Memory Analyser的更多相关文章
- Java虚拟机监控命令
熟悉java的人都知道jdk的bin目录中有很多小工具,其中就包括用于监视虚拟机和故障处理的工具,今天就来仔细了解下各个工具的用法 jps JVM Process Status Tool,用于显示指定 ...
- jstat命令 -- Java虚拟机监控统计工具
http://blog.sina.com.cn/s/blog_5f5716580100u76r.html 语法:jstat [generalOption | outputOptions vmid [i ...
- Java虚拟机性能调优(一)
Java虚拟机监控与调优,借助Java自带分析工具. jps:JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程 jstat:JVM Statistics M ...
- Java虚拟机内存模型及垃圾回收监控调优
Java虚拟机内存模型及垃圾回收监控调优 如果你想理解Java垃圾回收如果工作,那么理解JVM的内存模型就显的非常重要.今天我们就来看看JVM内存的各不同部分及如果监控和实现垃圾回收调优. JVM内存 ...
- 《深入理解Java虚拟机》-----第4章 虚拟机性能监控与故障处理工具
理论总是作为指导实践的工具,能把这些知识应用到实际工作中才是 我们的最终目的. 给一个系统定位问题的时候,知识.经验是关键基础,数据是依据,工具是运用知识处理数据的手段.这里说的数据包括:运行日志.异 ...
- Java虚拟机详解(七)------虚拟机监控和分析工具(1)——命令行
通过前面的几篇博客,我们介绍了Java虚拟机的内存分配以及内存回收等理论知识,了解这些知识对于我们在实际生产环境中提高系统的运行效率是有很大的帮助的.但是话又说回来,在实际生产环境中,线上项目正在运行 ...
- 虚拟机性能监控与故障处理工具(深入理解java虚拟机三)
JDK自带的工具可以方便的帮助我们处理一些问题,包括查看JVM参数,分析内存变化,查看内存区域,查看线程等信息. 我们熟悉的有java.exe,javac.exe,javap.exe(偶尔用),jps ...
- 深入理解JAVA虚拟机 虚拟机性能监控和故障处理工具
jre的bin目录下的工具,都非常小.它都是tools.jar下面的代码的一层封装而已.tools.jar不是java标准,是Hotspot实现的. 名称 作用 jps JVM Process Sta ...
- 《深入理解Java虚拟机》虚拟机性能监控与故障处理工具
上节学习回顾 从课本章节划分,<垃圾收集器>和<内存分配策略>这两篇随笔同属一章节,主要是从理论+实验的手段来讲解JVM的内存处理机制.好让我们对JVM运行机制有一个良好的概念 ...
随机推荐
- 使用item pipeline处理保存数据
一个Item Pipeline 不需要继承特定基类,只需要实现某些特定方法,面向接口. class MyPipeline(object): def __init__(self): "&quo ...
- Python 分布式进程
#-*-coding:utf-8-*- '''分布式进程指的是将Process进程分不到多台机器上,充分利用多台机器的性能完成复杂的任务''' #服务器端 #--------------------- ...
- 组件之间的数据传递--Vuex
安装Vuex: npm install Vuex -S 在main.js中引入 import Vue from 'vue' import App from './App' import Vuex fr ...
- 每添加一张图片后,GDI对象 + 3 原因: ImageList_AddIcon(hIcon) 后没调用 DestroyIcon(hIcon)
今天无意间在[任务管理器]中发现,每添加1张图片后,应用程序的 GDI对象 + 3,添加图片后,再把所有图片删除, GDI对象数量没减少! 排查原因,发现: GDI对象 + 3 的代码是: int o ...
- touch-paint
效果如下 代码如下: //index.html <!DOCTYPE html> <html lang="zh-CN"> <head> <m ...
- BSGS与exBSGS学习笔记
\(BSGS\)用于解决这样一类问题: 求解\(A^x ≡B(modP)\)的最小\(x\),其中\(P\)为质数. 这里我们采用分块的方法,把\(x\)分解为\(i *t-b\)(其中\(t\)是分 ...
- (栈)leetcode 946. Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could ha ...
- 基本类型(2):oracle中有4个大对象(lobs)类型可用,分别是blob,clob,bfile,nclob。
1)blob:二进制lob,为二进制数据,最长可达4GB,存贮在数据库中. 2)clob:字符lob,字符数据,最长可以达到4GB,存贮在数据库中. 3)bfile:二进制文件;存贮在数据库之外的只读 ...
- 关键字(2):循环和分支结构for/while/loop/switch
FOR i IN tRange1.first .. tRange1.last LOOP IF Instr(CardNum, tRange1(i), ) = THEN GLOBAL_VARBLE.nPo ...
- 物理服务器Linux下软RAID和UUID方式挂载方法--Megacli64
一.业务部门需求说明:公司最近来了一批服务器,用于大数据业务部署.数据节点服务器由14块物理磁盘,其中有2块是900G的盘,12块是4T的盘.在服务器系统安装时,进入系统的BIOS界面:1)将2块90 ...