Java常用命令

jps

jps主要用来输出JVM进程状态信息。
–m 输出传入main方法的参数
–l 输出main类或Jar的全限名
–v 输出传入JVM的参数

[badm@vm6-sj1-pro-had-32-107 data]$ jps -m -l
5390 com.ocr.OCR 20170103 ./hy-tb-vehicle-attach-20190108 ./data/ocr_20170103

jmap

jdk安装后会自带一些小工具,jmap命令主要用于打印指定Java进程的共享对象内存映射或堆内存细节。
jmap命令可以获得运行中的jvm的堆的快照,从而可以离线分析堆,以检查内存泄漏,检查一些严重影响性能的大对象的创建,检查系统中什么对象最多,各种对象所占内存的大小等等。
JVM内存
Java常用命令_第1张图片
大部分新对象在Eden Space上分配,当Eden Space满了,则要用到Survivor Space来回收。YGC的算法是很快的。多次YGC之后,还存活的对象就会被移到Old Generation(old space)上,当Old Generation满了的时候,就会FGC,FGC有通常比较慢。Permanent Space只要你在开始时分配了足够大的空间,那它可以不用管。
合理减少对象进入老生代; Old Space可能会一直增长,有时没有办法避免不让对象进入Old Space,当然也有一些程序是从来都不执行FGC的; 是不是尽全力防止对象进入老生代?显然不是,有些对象如果长久存在在新生代里,显然加重了YGC的负担,多次YGC之后仍然存活的对象显然应该放到Old Space里。
Old Space增长缓慢,FullGC次数少,FullGC的时间短(大部情况应该要在1秒内)。
常见错误
outOfMemoryError 年老代内存不足。
outOfMemoryError:PermGen Space 永久代内存不足。
outOfMemoryError:GC overhead limit exceed 垃圾回收时间占用系统运行时间的98%或以上。
jamp 参数
–heap
–histo
–dump

jmap -heap pid

[badm@vm6-sj1-pro-had-32-107 h_chenliling]$ jmap -heap 53854
Attaching to process ID 53854, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.74-b02

using thread-local object allocation.
Parallel GC with 28 thread(s)

Heap Configuration:  #堆内存初始化配置
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 16785604608 (16008.0MB) #JVM堆的最大大小
   NewSize                  = 350224384 (334.0MB)
   MaxNewSize               = 5595201536 (5336.0MB)  #设置JVM堆的‘新生代’的最大大小
   OldSize                  = 700448768 (668.0MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB) #JVM堆的‘持久代’的初始大小
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB #JVM堆的‘持久代’的最大大小
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:     
   capacity = 155713536 (148.5MB)
   used     = 27457888 (26.185882568359375MB)
   free     = 128255648 (122.31411743164062MB)
   17.63359095512416% used
From Space:
   capacity = 6815744 (6.5MB)
   used     = 6620264 (6.313575744628906MB)
   free     = 195480 (0.18642425537109375MB)
   97.13193453275241% used
To Space:
   capacity = 8912896 (8.5MB)
   used     = 0 (0.0MB)
   free     = 8912896 (8.5MB)
   0.0% used
PS Old Generation
   capacity = 700448768 (668.0MB)
   used     = 110872024 (105.73580169677734MB)
   free     = 589576744 (562.2641983032227MB)
   15.828712828858883% used

jmap -histo pid

说明:instances(实例数)、bytes(大小)、classs name(类名)。它基本是按照使用使用大小逆序排列的。

[badm@vm6-sj1-pro-had-32-107 h_chenliling]$ jmap -histo 1654 |head -50

 num     #instances         #bytes  class name
----------------------------------------------
   1:         38142      281905240  [C
   2:         13941      100597448  [B
   3:          7698       35544272  [I
   4:        119316        3818112  java.util.HashMap$Node
   5:          4209         913152  [Ljava.util.HashMap$Node;
   6:         26944         862208  java.util.concurrent.ConcurrentHashMap$Node
   7:         31421         754104  java.lang.String
   8:          7016         449024  java.util.concurrent.ConcurrentHashMap
   9:          3503         377488  [Ljava.util.concurrent.ConcurrentHashMap$Node;
  10:           935         318320  [Ljava.lang.String;
  11:          4541         298088  [Ljava.lang.Object;
  12:          5088         284928  java.util.LinkedHashMap
  13:          5514         264672  java.util.HashMap
  14:          7474         239168  java.util.concurrent.FutureTask
  15:          2022         230600  java.lang.Class
  16:          7476         179424  java.util.concurrent.LinkedBlockingQueue$Node
  17:          7474         179376  com.ocr.OCR$1
  18:          7474         179376  java.util.concurrent.Executors$RunnableAdapter
  19:          1481         165872  java.net.SocksSocketImpl
  20:          5059         161888  java.lang.ref.ReferenceQueue

class标识说明:
B 代表 byte
C 代表 char
D 代表 double
F 代表 float
I 代表 int
J 代表 long
Z 代表 boolean
前边有 [ 代表数组, [I 就相当于 int[]
对象用 [L+ 类名表示

jstack

jstack能得到运行java程序的java stack和native stack的信息。可以轻松得知当前线程的运行情况。
jstack
–F
–m
–l long listing. Prints additional information about locks
–h

jstack -l pid

 [badm@vm6-sj1-pro-had-32-107 h_chenliling]$ jstack -l 53854
 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.74-b02 mixed mode):
"Attach Listener" #54 daemon prio=9 os_prio=0 tid=0x00007f6794001000 nid=0x16bdb waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   Locked ownable synchronizers:
	- None
"pool-1-thread-3" #23 prio=5 os_prio=0 tid=0x00007f6858120000 nid=0x18993 runnable [0x00007f6798dca000]
   java.lang.Thread.State: RUNNABLE
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:170)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	- locked <0x00000003d9874440> (a java.io.BufferedInputStream)//被锁代码行
	at sun.net.www.MeteredStream.read(MeteredStream.java:134)
	- locked <0x00000003d9874c78> (a sun.net.www.http.KeepAliveStream)
	at java.io.FilterInputStream.read(FilterInputStream.java:133) //被锁代码行
	at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3336)
	at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3329)
	at com.ocr.OCR.getFile(OCR.java:233)
	at com.ocr.OCR.access$000(OCR.java:45)
	at com.ocr.OCR$1.run(OCR.java:407)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
	- <0x00000003d8b42678> (a java.util.concurrent.ThreadPoolExecutor$Worker)

你可能感兴趣的:(JSE)