Depth understanding of JVM

Depth understanding of java virtual machine

Talk about the content

  1. Learn history
  2. Garbage collection
  3. Performance monitoring tools
  4. Tuning the real case
  5. Understanding the structure of the class file
  6. Class loading mechanism
  7. Bytecode execution engine
  8. Optimizing compiler and a virtual machine running
  9. Java threads senior

1.  environmental structures

   Installation jdk

 

 

2.  Memory Overflow scene simulation

public  class to Test01 { 

public  static  void main (String [] args) { 

// Test Memory Overflow 

List <Demo> List = new new the ArrayList <Demo> (); 

the while ( to true ) { 

List.add ( new new Demo ()); 

} 

// stop creating objects will always know the memory consumption of heap memory consumed (in fact, does not really have the 8G of memory consumed) 

// when it reaches a line it will be reported on the error, and then will report a memory overflow 

// an OutOfMemoryError 

} 

} 
class Demo { 
}

 

This snapshot can be found in your project file error

 

But we can not read so it is necessary to http://www.eclipse.org/mat/downloads.php to download an eclipse of MemoryAnalyzer analysis tool

如果你直接下载会非常慢所以选择一个其他的镜像这样下载就会快点

 

下载解压后打开

 

点击file->Open Heap Dump 选中产生的那个文件

 

然后生成一个

 

 

选中这个图标可以查看我们的堆内存运行情况 加载堆内存的信息

 

 

这个就代表很可能在main里面出现问题了 占得百分比高达95.6%

 

Shallow Heap 对象本分所占用的内存大小不包含它的引用对象

Retained Heap 代表当前对象的大小包括当前可直接或者间接引用对象的大小的总和。

点开那个占用堆内存最多线程

 

继续点开会发现 他创建了很多个这样的对象造成的堆内存溢出

 

Jvm 的可视化监控工具

这个工具在哪呢在我们安装的jdk

 

因为我们的jdk已经配置在我们的path路径下因此在任何路径下都可以访问的到所以在

命令行中可以输入这个值 会将这个可视化界面弹出来

 

我们可以看到这个图像化界面只有18k那么真正的代码放在了lib目录下的一个jar包里面

 

这个jps这个命令会列出来所有的java进程,我们看到有JConsole 这个进程 但是为什么没有jps这个进程呢是因为

这个命令执行完之后就结束了。

 

当我们点进去就能对这个进程进行监控

 

 

我们大概就能看到这样的窗口了

 

 

 

Java 之父

詹姆斯  高林斯

 

Guess you like

Origin www.cnblogs.com/zhulina-917/p/11387900.html