自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

常用的JDK自帶命令行工具

開(kāi)發(fā) 開(kāi)發(fā)工具
在這里可 以找得到這些工具的列表,雖然官網(wǎng)上免責(zé)聲明為 “The tools described in this section are unsupported and experimental in nature and should be used with that in mind. They might not be available in future JDK versions.”,但實(shí)際上這些工具還是非常有用的,尤其可以站在JVM的角度來(lái)定位問(wèn)題。

在這里可 以找得到這些工具的列表,雖然官網(wǎng)上免責(zé)聲明為 “The tools described in this section are unsupported and experimental in nature and should be used with that in mind. They might not be available in future JDK versions.”,但實(shí)際上這些工具還是非常有用的,尤其可以站在JVM的角度來(lái)定位問(wèn)題。我在此簡(jiǎn)單羅列一些常用的工具和命令,以及相應(yīng)的執(zhí)行結(jié)果 示例。如果你經(jīng)常和JVM打交道,最好對(duì)這些工具的常用命令熟記。

http://s9.51cto.com/wyfs01/M02/32/8E/wKioJlKFfgqR31KVAAAvdAX2v08897.jpg

jstat,這個(gè)工具很強(qiáng)大,可以監(jiān)測(cè)Java虛擬機(jī)GC多方面的狀態(tài),具體參數(shù)含義參見(jiàn)此鏈接

  1. ./jstat -gc 84012 1000 3 
  2.   
  3. S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT 
  4. 2112.0 2112.0  0.0    0.0   17024.0    0.0     63872.0     1319.9   21248.0 4728.1 743416  209.646   5      0.046  209.692 
  5. 2112.0 2112.0  0.0    0.0   17024.0    0.0     63872.0     1319.9   21248.0 4728.1 743849  209.755   5      0.046  209.801 
  6. 2112.0 2112.0  0.0    0.0   17024.0    0.0     63872.0     1319. 

jmap,這大概是最常用的命令。下面這個(gè)命令不但可以列出類(lèi)的實(shí)例數(shù)量,還有強(qiáng)制進(jìn)行一次full GC的“副作用”,這樣的副作用對(duì)于定位某些問(wèn)題很有幫助,參見(jiàn)《使用堆外內(nèi)存》:

  1. ./jmap -histo:live 84012 
  2.   
  3.  num     #instances         #bytes  class name 
  4. ---------------------------------------------- 
  5.    1:           824        1177656  [B 
  6.    2:          8096        1106672 
  7. ... 

使用-heap參數(shù),則可以打印堆的使用情況:

  1. ./jmap -heap 84012 
  2.   
  3. Attaching to process ID 84012, please wait... 
  4. Debugger attached successfully. 
  5. Server compiler detected. 
  6. JVM version is 20.65-b04-462 
  7.   
  8. using parallel threads in the new generation. 
  9. using thread-local object allocation. 
  10. Concurrent Mark-Sweep GC 
  11.   
  12. Heap Configuration: 
  13.    MinHeapFreeRatio = 40 
  14.    MaxHeapFreeRatio = 70 
  15.    MaxHeapSize      = 132120576 (126.0MB) 
  16.    NewSize          = 21757952 (20.75MB) 
  17.    MaxNewSize       = 174456832 (166.375MB) 
  18.    OldSize          = 65404928 (62.375MB) 
  19.    NewRatio         = 7 
  20.    SurvivorRatio    = 8 
  21.    PermSize         = 21757952 (20.75MB) 
  22.    MaxPermSize      = 85983232 (82.0MB) 
  23.   
  24. Heap Usage: 
  25. New Generation (Eden + 1 Survivor Space): 
  26.    capacity = 19595264 (18.6875MB) 
  27.    used     = 16785688 (16.008079528808594MB) 
  28.    free     = 2809576 (2.6794204711914062MB) 
  29.    85.66196403375837% used 
  30. Eden Space: 
  31.    capacity = 17432576 (16.625MB) 
  32.    used     = 16785688 (16.008079528808594MB) 
  33.    free     = 646888 (0.6169204711914062MB) 
  34.    96.28920017328477% used 
  35. From Space: 
  36.    capacity = 2162688 (2.0625MB) 
  37.    used     = 0 (0.0MB) 
  38.    free     = 2162688 (2.0625MB) 
  39.    0.0% used 
  40. To Space: 
  41.    capacity = 2162688 (2.0625MB) 
  42.    used     = 0 (0.0MB) 
  43.    free     = 2162688 (2.0625MB) 
  44.    0.0% used 
  45. concurrent mark-sweep generation: 
  46.    capacity = 65404928 (62.375MB) 
  47.    used     = 1390576 (1.3261566162109375MB) 
  48.    free     = 64014352 (61.04884338378906MB) 
  49.    2.126102791520541% used 
  50. Perm Generation: 
  51.    capacity = 21757952 (20.75MB) 
  52.    used     = 4852336 (4.6275482177734375MB) 
  53.    free     = 16905616 (16.122451782226562MB) 
  54.    22.301437194088855% used 

使用-permstat參數(shù),查看永久區(qū):

  1. ./jmap -permstat 84012 
  2.   
  3. Attaching to process ID 84012, please wait... 
  4. Debugger attached successfully. 
  5. Server compiler detected. 
  6. JVM version is 20.65-b04-462 
  7. 1239 intern Strings occupying 104312 bytes. 
  8. finding class loader instances ..Warning: skipping invalid TLAB for thread t@59779 
  9. Warning: skipping invalid TLAB for thread t@59527 
  10. Warning: skipping invalid TLAB for thread t@59907 
  11. Warning: skipping invalid TLAB for thread t@60163 
  12. Warning: skipping invalid TLAB for thread t@60419 
  13. Warning: skipping invalid TLAB for thread t@60675 
  14. Finding object size using Printezis bits and skipping over... 
  15. done. 
  16. computing per loader stat ..done. 
  17. please wait.. computing liveness...done. 
  18. class_loader    classes bytes   parent_loader   alive?  type 
  19.   
  20.     590 3973048   null      live 
  21. 0x00000007f44cace0  0   0     null      live    sun/misc/Launcher$ExtClassLoader@0x00000007faff8a40 
  22. 0x00000007f44c1478  8   143928  0x00000007f44cace0  live    sun/misc/Launcher$AppClassLoader@0x00000007fb056e88 
  23.   
  24. total = 3   598 4116976     N/A     alive=3dead=0     N/A 

把內(nèi)存中的堆dump成一個(gè)鏡像文件:

  1. ./jmap -dump:live,format=b,file=/Users/xiongyi/Documents/dump.core 84012 

#p#

jstack,線程堆棧打印。注意waiting to lock <xxx>在等待鎖,比如進(jìn)入臨界區(qū)時(shí);locked <xxx>表示當(dāng)前同步操作,線程鎖住了某資源;而waiting on <xxx>指的是在同步塊內(nèi),wait方法的執(zhí)行中暫時(shí)地釋放了該鎖的占用,等喚醒的時(shí)候需要重新獲取:

  1. ./jstack 84012 
  2.   
  3. 2013-11-11 18:30:35 
  4. Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.65-b04-462 mixed mode): 
  5.   
  6. "Attach Listener" daemon prio=9 tid=7ff64e206800 nid=0x117782000 waiting on condition [00000000] 
  7.    java.lang.Thread.State: RUNNABLE 
  8.   
  9. "Low Memory Detector" daemon prio=5 tid=7ff64c80f000 nid=0x117c96000 runnable [00000000] 
  10.    java.lang.Thread.State: RUNNABLE 
  11.   
  12. "C2 CompilerThread1" daemon prio=9 tid=7ff64c80e800 nid=0x117b93000 waiting on condition [00000000] 
  13.    java.lang.Thread.State: RUNNABLE 
  14.   
  15. "C2 CompilerThread0" daemon prio=9 tid=7ff64c80d800 nid=0x117a90000 waiting on condition [00000000] 
  16.    java.lang.Thread.State: RUNNABLE 
  17.   
  18. "Signal Dispatcher" daemon prio=9 tid=7ff64c80d000 nid=0x11798d000 runnable [00000000] 
  19.    java.lang.Thread.State: RUNNABLE 
  20.   
  21. "Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7ff64c80c000 nid=0x11788a000 waiting on condition [00000000] 
  22.    java.lang.Thread.State: RUNNABLE 
  23.   
  24. "Finalizer" daemon prio=8 tid=7ff64e13d800 nid=0x11767f000 in Object.wait() [11767e000] 
  25.    java.lang.Thread.State: WAITING (on object monitor) 
  26.     at java.lang.Object.wait(Native Method) 
  27.     - waiting on <7f44c0ed0> (a java.lang.ref.ReferenceQueue$Lock) 
  28.     at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) 
  29.     - locked <7f44c0ed0> (a java.lang.ref.ReferenceQueue$Lock) 
  30.     at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) 
  31.     at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:171) 
  32.   
  33. "Reference Handler" daemon prio=10 tid=7ff64e13c800 nid=0x11757c000 in Object.wait() [11757b000] 
  34.    java.lang.Thread.State: WAITING (on object monitor) 
  35.     at java.lang.Object.wait(Native Method) 
  36.     - waiting on <7f44c0018> (a java.lang.ref.Reference$Lock) 
  37.     at java.lang.Object.wait(Object.java:485) 
  38.     at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) 
  39.     - locked <7f44c0018> (a java.lang.ref.Reference$Lock) 
  40.   
  41. "main" prio=5 tid=7ff64c800800 nid=0x10f709000 runnable [10f708000] 
  42.    java.lang.Thread.State: RUNNABLE 
  43.     at test.Test.main(Test.java:7) 
  44.   
  45. "VM Thread" prio=9 tid=7ff64e138000 nid=0x117479000 runnable 
  46.   
  47. "Gang worker#0 (Parallel GC Threads)" prio=9 tid=7ff64e000000 nid=0x112b0f000 runnable 
  48.   
  49. "Gang worker#1 (Parallel GC Threads)" prio=9 tid=7ff64e001000 nid=0x112c12000 runnable 
  50.   
  51. "Gang worker#2 (Parallel GC Threads)" prio=9 tid=7ff64e001800 nid=0x112d15000 runnable 
  52.   
  53. "Gang worker#3 (Parallel GC Threads)" prio=9 tid=7ff64e002000 nid=0x112e18000 runnable 
  54.   
  55. "Gang worker#4 (Parallel GC Threads)" prio=9 tid=7ff64e002800 nid=0x112f1b000 runnable 
  56.   
  57. "Gang worker#5 (Parallel GC Threads)" prio=9 tid=7ff64e003800 nid=0x11301e000 runnable 
  58.   
  59. "Gang worker#6 (Parallel GC Threads)" prio=9 tid=7ff64e004000 nid=0x113121000 runnable 
  60.   
  61. "Gang worker#7 (Parallel GC Threads)" prio=9 tid=7ff64e004800 nid=0x113224000 runnable 
  62.   
  63. "Concurrent Mark-Sweep GC Thread" prio=9 tid=7ff64e0e2000 nid=0x1170f0000 runnable 
  64. "Gang worker#0 (Parallel CMS Threads)" prio=9 tid=7ff64e0e0800 nid=0x1166ea000 runnable 
  65.   
  66. "Gang worker#1 (Parallel CMS Threads)" prio=9 tid=7ff64e0e1800 nid=0x1167ed000 runnable 
  67.   
  68. "VM Periodic Task Thread" prio=10 tid=7ff64c820800 nid=0x117d99000 waiting on condition 
  69.   
  70. "Exception Catcher Thread" prio=10 tid=7ff64c801800 nid=0x10f936000 runnable 
  71. JNI global references: 963 

jinfo,可以打印JVM執(zhí)行的參數(shù)信息,有一個(gè)非常大的作用在于,部分JVM參數(shù)在執(zhí)行過(guò)程中是可以修改的,請(qǐng)參見(jiàn)這篇《通過(guò)jinfo工具在full GC前后做heap dump》,通過(guò)jinfo改變參數(shù)HeapDumpBeforeFullGC和HeapDumpAfterFullGC,輸出heap dump后,再改回來(lái)。

jhat,可以比對(duì)core文件之間的對(duì)象變化,支持對(duì)象查詢(xún)語(yǔ)言(OQL),請(qǐng)參見(jiàn)這里

  1. ./jhat -stack true -refs true -port 8080 -baseline /xxx/dump-baseline.core -debug 1 /Users/xiongyi/Documents/dump-newer.core 

javap,用于反編譯class文件,對(duì)于JVM指令集,這里有完整的文檔

  1. javap -c -v ./Test.class 
  2. Classfile xxx/Test.class 
  3.   Last modified Nov 11, 2013; size 441 bytes 
  4.   MD5 checksum 69488187cc8a8f166bc6dd0d517fb4cb 
  5.   Compiled from "Test.java" 
  6. public class test.Test 
  7.   SourceFile: "Test.java" 
  8.   minor version: 0 
  9.   major version: 50 
  10.   flags: ACC_PUBLIC, ACC_SUPER 
  11. Constant pool: 
  12.    #1 = Methodref          #6.#16         //  java/lang/Object."":()V 
  13.    #2 = Integer            1048576 
  14.    #3 = Fieldref           #17.#18        //  java/lang/System.out:Ljava/io/PrintStream; 
  15.    #4 = Methodref          #19.#20        //  java/io/PrintStream.println:(Ljava/lang/Object;)V 
  16.    #5 = Class              #21            //  test/Test 
  17.    #6 = Class              #22            //  java/lang/Object 
  18.    #7 = Utf8 
  19.    #8 = Utf8               ()V 
  20.    #9 = Utf8               Code 
  21.   #10 = Utf8               LineNumberTable 
  22.   #11 = Utf8               main 
  23.   #12 = Utf8               ([Ljava/lang/String;)V 
  24.   #13 = Utf8               StackMapTable 
  25.   #14 = Utf8               SourceFile 
  26.   #15 = Utf8               Test.java 
  27.   #16 = NameAndType        #7:#8          //  "":()V 
  28.   #17 = Class              #23            //  java/lang/System 
  29.   #18 = NameAndType        #24:#25        //  out:Ljava/io/PrintStream; 
  30.   #19 = Class              #26            //  java/io/PrintStream 
  31.   #20 = NameAndType        #27:#28        //  println:(Ljava/lang/Object;)V 
  32.   #21 = Utf8               test/Test 
  33.   #22 = Utf8               java/lang/Object 
  34.   #23 = Utf8               java/lang/System 
  35.   #24 = Utf8               out 
  36.   #25 = Utf8               Ljava/io/PrintStream; 
  37.   #26 = Utf8               java/io/PrintStream 
  38.   #27 = Utf8               println 
  39.   #28 = Utf8               (Ljava/lang/Object;)V 
  40.   public test.Test(); 
  41.     flags: ACC_PUBLIC 
  42.     Code: 
  43.       stack=1locals=1args_size=1 
  44.          0: aload_0 
  45.          1: invokespecial #1                  // Method java/lang/Object."":()V 
  46.          4: return 
  47.       LineNumberTable: 
  48.         line 4: 0 
  49.   
  50.   public static void main(java.lang.String[]); 
  51.     flags: ACC_PUBLIC, ACC_STATIC 
  52.     Code: 
  53.       stack=2locals=2args_size=1 
  54.          0: ldc           #2                  // int 1048576 
  55.          2: newarray       byte 
  56.          4: astore_1 
  57.          5: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream; 
  58.          8: aload_1 
  59.          9: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/Object;)V 
  60.         12: goto          0 
  61.       LineNumberTable: 
  62.         line 7: 0 
  63.         line 8: 5 
  64.         line 9: 12 
  65.       StackMapTable: number_of_entries = 1 
  66.            frame_type = 0 /* same */ 
  67.   

原文鏈接:http://www.raychase.net/1647

責(zé)任編輯:陳四芳 來(lái)源: 四火的嘮叨
相關(guān)推薦

2010-11-24 17:12:17

MySQL命令行

2020-12-10 16:16:08

工具代碼開(kāi)發(fā)

2020-12-11 06:44:16

命令行工具開(kāi)發(fā)

2011-01-18 19:11:26

Postfix命令行

2009-12-09 09:25:52

Linux命令行svn命令

2010-11-24 15:41:56

MySQL命令行

2023-06-09 07:45:29

Kuberneteskubectl

2010-10-12 17:29:22

MySQL命令行

2010-05-17 15:41:26

2022-03-11 09:00:51

2009-08-11 09:58:22

Linux命令行Linux命令svn命令

2013-12-09 14:29:13

OpenStack命令行工具API

2010-07-15 09:27:25

Perl命令行

2010-07-26 09:22:05

Perl命令行

2010-02-04 15:17:48

Linux wget

2018-04-03 13:50:27

Linux容器命令行工具

2017-06-15 10:32:56

OracleDBV命令行工具

2010-11-16 13:32:00

Oracle命令行

2015-07-01 09:15:46

linuxQuora命令行

2010-05-25 18:43:39

MySQL命令行
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)