root@ubuntu-blade2:/sdf/jdk# java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
1. -client和-server
滿足不同場合,提供了兩種運行模式,一種是server模式,另一種是client模式。
從jdk1.5以來,當應用程序啟動時,如果用戶沒有在命令行中顯式指明虛擬機運行的模式,但啟動會自動嘗試檢查該應用是運行在一個server類型的機器上,還是client類型的機器上。
2. -cp和-classpath
設置虛擬機運行的classpath。在該路徑(jar或zip文件)下面搜索class文件。如果存在多個路徑(jar或zip文件),在windows采用;分隔,在unix采用:作為分隔符。在命令行中指定-classpath或-cp可以覆蓋CLASSPATH環境變量的設置。如果沒有指定classpath,默認是當前路徑。
3. -D<name>=<value>
定義運行期變量(或系統屬性),功能與環境變量相同
具體參考博客:https://www.cnblogs.com/lujiango/p/9619524.html
4. -verbose:
-verbose:class Java虛擬機運行期間,打印class的加載情況。系統中加載了哪些文件中的哪些類。
-verbose:gc 打印GC日志
-verbose:jni 打印詳細的JNI本地接口的使用情況
5. -version和-version<value>
-version打印當前JDK版本
-version:1.8以指定版本的虛擬機來運行Java程序
6. -showversion
打印jdk的版本,並繼續
java -showversion com.huawei.diagnose.thread.MyTest
7. -jre-restrict-search | -jre-no-restrict-search
在版本搜索中包含/排除用戶私有JRE
8 -? -help
打印幫助信息
9. -X
打印擴展(即-X參數)幫助
10. -ea[:<packageName>...|:<className>]和-enableassertion[:<packageName>...|:<className>]
激活斷言,默認情況為禁止,如果沒有跟參數,則標示激活所有斷言。如果跟隨參數,則標示僅對指定的包或類激活斷言。如果跟隨的參數是“...”,則標示只激活當前工作目錄下面的未命名包的斷言。如果不是以“...”為結尾,則表示激活指定類中的斷言。
如果一個命令行中包含多個選項(即多個-ea或-enableassertions),則以加載這些類的順序為准。
激活com.wombat.fruitbat包中的斷言,命令如下:
java -ea:com.wombat.fruitbat... <>
11. -da[:<packagename>...|:<classname>]和-disableassertions[:<packagename>...|:<classname>]
關閉斷言(默認也是關閉)
12. -esa | -enablesystemassertions
激活所有系統類中的斷言(即設置系統類的缺省斷言狀態為true)
13. -dsa | -disablesystemassertions
禁止所有系統類中的斷言(即設置系統類的缺省斷言狀態為false)
14. -agentlib:<libname>[=<options>]
加載本地代理庫
-agentlib:hprof
-agentlib:jdwp=help
-agentlib:hprof=help
15. java -X擴展運行參數
root@ubuntu-blade2:/opt# java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by :>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by :>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by :>
prepend in front of bootstrap class path
-Xdiag show additional diagnostic messages
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs reduce use of OS signals by Java/VM (see documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.
-XshowSettings show all settings and continue
-XshowSettings:all
show all settings and continue
-XshowSettings:vm show all vm related settings and continue
-XshowSettings:properties
show all property settings and continue
-XshowSettings:locale
show all locale related settings and continue
The -X options are non-standard and subject to change without notice.
15.1 -Xmixed
混合模式執行(默認),即解釋模式和JIT混合執行。
15.2 -Xint
解釋模式執行。禁止將類中的方法編譯成本地代碼,所有的字節碼以解析方式進行。
15.3 -Xbootclasspath:<directories and zip/jar files separated by ;>
將路徑,jar,zip庫加增加到啟動class的搜索路徑,以";"作為分隔符。
15.4 -Xbootclasspath/a:<directories and zip/jar files separated by ;>
將路徑,jar,zip庫加增加到缺省的bootclasspath,以";"作為分隔符。
15.5 -Xbootclasspath/p:<directories and zip/jar files separated by ;>
將路徑,jar,zip庫加增加到缺省的bootclasspath的前面,以";"作為分隔符。注意,應用程序使用該命令的目的是為了覆蓋rt.jar中的類。
15.6 -Xnoclassgc
不進行class的垃圾收集
15.7 -Xincgc
打開增量垃圾收集增量。垃圾收集開關在缺省情況下是關閉的。增量垃圾收集可以減少程序運行期偶發的長時間垃圾收集。增量垃圾收集器將在一定的時間與程序並發執行,在這段垃圾收集的時間內,對正在執行的程序有一定的性能影響。
15.8 -Xloggc:<file>
將GC信息打印到指定的文件中。與-verbose:gc類似,-Xloggc:<file>將GC信息中直接打印到一個文件中。如果兩個都提供了,那么以-Xloggc:<file>為准。
15.9 -Xbatch
關閉后台編譯。正常情況下,JVM將以后台的方式編譯class中的方法,一直按解析模式運行代碼,直到后台編譯完成。-Xbatch標記關閉后台編譯,所有方法的編譯作為前台任務完成,直到編譯完成。
15.10 -Xms<size>
指明堆內存的初始大小。該值必須是1024的倍數,並且大於1MB. 可以通過k或者M后綴表示是以KB字節為單位,m或者M表示以MB字節為單位。
-Xms6291456
-Xms6144k
-Xms6m
15.11 -Xmx<size>
指明最大的堆內存大小,該值必須是1204字節的倍數,k或者K表示KB, m或者M表示MB.
-Xmx83886080
-Xmx81920k
-Xmx80m
15.12 -Xss<size>
設置線程堆棧的大小。
15.13 -Xprof
打開CPU剖析功能。
15.14 -Xfuture
執行嚴格的類文件格式檢查。-Xfuture選項打開,將執行更嚴格的類文件格式檢查,這樣可以確保類文件與標准中定義的類文件格式更加順從。
15.15 -Xrs
減少由JVM使用的操作系統信號量。
15.16 -Xcheck:jni
對JNI函數執行附加的檢查特別地,虛擬機在處理JNI請求之前,會對傳給JNI調用的參數進行校驗,同時對運行期環境數據也進行校驗。
15.17 -Xshare:off
關於使用共享類數據。
15.18 -Xshare:auto
在可能的情況下,使用共享的類數據
15.19 -Xshare:on
一定使用共享的類數據,否則失敗