作用:記錄下一條JVM指令的執(zhí)行地址
特點:
問題辨析:
棧內(nèi)存溢出
案例1:CPU占用過多
定位
ps H -eo pid,tid,%cpu | grep 進程id
(線程id為10進制)jstack 進程id
(線程id為16進制)id
進一步定位到代碼的源碼行號案例2:程序運行較長時間無結果
用jstack
命令定位查看是否發(fā)生死鎖
用native修飾
堆通過new
創(chuàng)建的對象都會使用堆內(nèi)存
特點
堆內(nèi)存溢出
將堆內(nèi)存設置小些,以方便排查堆內(nèi)存溢出問題
堆內(nèi)存診斷
工具
PS C:\Users\28599\Desktop\JVM\代碼\jvm\jvm>jmap -heap 8284
Attaching to process ID 8284, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.331-b09
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 4250927104 (4054.0MB)
NewSize = 88604672 (84.5MB)
MaxNewSize = 1416626176 (1351.0MB)
OldSize = 177733632 (169.5MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 66584576 (63.5MB)
used = 1331712 (1.27001953125MB)
free = 65252864 (62.22998046875MB)
2.0000307578740157% used
From Space:
capacity = 11010048 (10.5MB)
used = 0 (0.0MB)
free = 11010048 (10.5MB)
0.0% used
To Space:
capacity = 11010048 (10.5MB)
used = 0 (0.0MB)
free = 11010048 (10.5MB)
0.0% used
PS Old Generation
capacity = 177733632 (169.5MB)
used = 1052296 (1.0035476684570312MB)
free = 176681336 (168.49645233154297MB)
0.5920635212135877% used
3162 interned Strings occupying 280536 bytes.
jvisualvm
執(zhí)行堆dump
查找大的對象
方法區(qū)存儲每個類的結構,如運行時常量池、字段和方法數(shù)據(jù),以及方法和構造函數(shù)的代碼,包括類和實例初始化和接口初始化中使用的特殊方法。
JDK7 之前(永久代)用于存儲已被虛擬機加載的類信息、常量、字符串常量、類靜態(tài)變量、即時編譯器編譯后的代碼等數(shù)據(jù)。每當一個類初次被加載的時候,它的元數(shù)據(jù)都會被放到永久代中。永久代大小有 限制,如果加載的類太多,很可能導致永久代內(nèi)存溢出,即 java.lang.OutOfMemoryError: PermGen。
JDK8 徹底將永久代移除出 HotSpot JVM,將其原有的數(shù)據(jù)遷移至 Java Heap 或 Native Heap(Metaspace),取代它的是另一個內(nèi)存區(qū)域被稱為元空間(Metaspace)。
元空間(Metaspace):元空間是方法區(qū)的在 HotSpot JVM 中的實現(xiàn),方法區(qū)主要用于存儲類信息、常 量池、方法數(shù)據(jù)、方法代碼、符號引用等。元空間的本質(zhì)和永久代類似,都是對 JVM 規(guī)范中方法區(qū)的實 現(xiàn)。不過元空間與永久代之間大的區(qū)別在于:元空間并不在虛擬機中,而是使用本地內(nèi)存。 可以通過 -XX:MetaspaceSize 和 -XX:MaxMetaspaceSize 配置內(nèi)存大小。
常量池javap -v .\HelloWorld.class
Classfile /C:/Users/28599/Desktop/JVM/代碼/jvm/jvm/out/production/jvm/cn/itcast/jvm/t5/HelloWorld.class
Last modified 2023-1-3; size 567 bytes
MD5 checksum 8efebdac91aa496515fa1c161184e354
Compiled from "HelloWorld.java"
public class cn.itcast.jvm.t5.HelloWorld
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #6.#20 // java/lang/Object."":()V
#2 = Fieldref #21.#22 // java/lang/System.out:Ljava/io/PrintStream;
#3 = String #23 // hello world
#4 = Methodref #24.#25 // java/io/PrintStream.println:(Ljava/lang/String;)V
#5 = Class #26 // cn/itcast/jvm/t5/HelloWorld
#6 = Class #27 // java/lang/Object
#7 = Utf8 #8 = Utf8 ()V
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 LocalVariableTable
#12 = Utf8 this
#13 = Utf8 Lcn/itcast/jvm/t5/HelloWorld;
#14 = Utf8 main
#15 = Utf8 ([Ljava/lang/String;)V
#16 = Utf8 args
#17 = Utf8 [Ljava/lang/String;
#18 = Utf8 SourceFile
#19 = Utf8 HelloWorld.java
#20 = NameAndType #7:#8 // "":()V
#21 = Class #28 // java/lang/System
#22 = NameAndType #29:#30 // out:Ljava/io/PrintStream;
#23 = Utf8 hello world
#24 = Class #31 // java/io/PrintStream
#25 = NameAndType #32:#33 // println:(Ljava/lang/String;)V
#26 = Utf8 cn/itcast/jvm/t5/HelloWorld
#27 = Utf8 java/lang/Object
#28 = Utf8 java/lang/System
#29 = Utf8 out
#30 = Utf8 Ljava/io/PrintStream;
#31 = Utf8 java/io/PrintStream
#32 = Utf8 println
#33 = Utf8 (Ljava/lang/String;)V
{public cn.itcast.jvm.t5.HelloWorld();
descriptor: ()V
flags: ACC_PUBLIC
stack=2, locals=1, args_size=1
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3 // String hello world
5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
LineNumberTable:
line 6: 0
line 7: 8
LocalVariableTable:
Start Length Slot Name Signature
0 9 0 args [Ljava/lang/String;
}
SourceFile: "HelloWorld.java"
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧