当没有VisualVM等可视化工具进行JVM内存分析,可以使用以下JDK自带的工具进行分析。

jps

查看java进程内部id
第一列:java进程内部id(1、238),第二列:主类的全类名

bash-4.2# jps -l
1 org.apache.catalina.startup.Bootstrap
238 sun.tools.jps.Jps

jstat

查看JVM各内存区域使用状况及GC信息

bash-4.2# jstat -gccause 1
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
53.09 0.00 96.00 60.70 94.23 91.42 444 1.794 8 0.723 2.517 Allocation Failure No GC

jmap

可以查看堆内存的使用情况以及可以转储堆文件

bash-4.2# jmap -heap 1
Attaching to process ID 1, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.382-b05

using thread-local object allocation.
Mark Sweep Compact GC

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 394264576 (376.0MB)
NewSize = 8388608 (8.0MB)
MaxNewSize = 131399680 (125.3125MB)
OldSize = 16777216 (16.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 85590016 (81.625MB)
used = 80954640 (77.20436096191406MB)
free = 4635376 (4.4206390380859375MB)
94.58420944798047% used
Eden Space:
capacity = 76087296 (72.5625MB)
used = 75909264 (72.39271545410156MB)
free = 178032 (0.1697845458984375MB)
99.76601612968346% used
From Space:
capacity = 9502720 (9.0625MB)
used = 5045376 (4.8116455078125MB)
free = 4457344 (4.2508544921875MB)
53.09401939655172% used
To Space:
capacity = 9502720 (9.0625MB)
used = 0 (0.0MB)
free = 9502720 (9.0625MB)
0.0% used
tenured generation:
capacity = 189595648 (180.8125MB)
used = 115075904 (109.74493408203125MB)
free = 74519744 (71.06756591796875MB)
60.695435372018665% used

54241 interned Strings occupying 5439040 bytes.

jstack

查看线程状态及线程调用栈轨迹

bash-4.2# jstack -F 1
Attaching to process ID 1, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.382-b05
Deadlock Detection:

No deadlocks found.

Thread 373: (state = BLOCKED)
- java.lang.Thread.sleep(long) @bci=0 (Compiled frame; information may be imprecise)
- sun.net.www.http.KeepAliveCache.run() @bci=3, line=172 (Interpreted frame)
- java.lang.Thread.run() @bci=11, line=750 (Interpreted frame)


Thread 348: (state = BLOCKED)


Thread 150: (state = BLOCKED)
- sun.misc.Unsafe.park(boolean, long) @bci=0 (Compiled frame; information may be imprecise)
- java.util.concurrent.locks.LockSupport.park(java.lang.Object) @bci=14, line=175 (Compiled frame)
- java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await() @bci=42, line=2039 (Compiled frame)
- java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take() @bci=24, line=1081 (Compiled frame)
- java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take() @bci=1, line=809 (Compiled frame)
- java.util.concurrent.ThreadPoolExecutor.getTask() @bci=149, line=1074 (Compiled frame)
- java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=26, line=1134 (Interpreted frame)
- java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=624 (Interpreted frame)
- java.lang.Thread.run() @bci=11, line=750 (Interpreted frame)

jcmd

bash-4.2# jcmd 1 GC.heap_info
1:
def new generation total 83584K, used 39663K [0x00000000e8800000, 0x00000000ee2b0000, 0x00000000f0550000)
eden space 74304K, 44% used [0x00000000e8800000, 0x00000000ea817400, 0x00000000ed090000)
from space 9280K, 73% used [0x00000000ed090000, 0x00000000ed7348c0, 0x00000000ed9a0000)
to space 9280K, 0% used [0x00000000ed9a0000, 0x00000000ed9a0000, 0x00000000ee2b0000)
tenured generation total 185152K, used 115966K [0x00000000f0550000, 0x00000000fba20000, 0x0000000100000000)
the space 185152K, 62% used [0x00000000f0550000, 0x00000000f768fad0, 0x00000000f768fc00, 0x00000000fba20000)
Metaspace used 123452K, capacity 130620K, committed 130816K, reserved 1163264K
class space used 14981K, capacity 16350K, committed 16384K, reserved 1048576K

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

0%