JVMのパラメータの詳細
29806 ワード
12年卒业して最初の年を処理するまでここ数年は醤油を打つことに属していて、当初Javaを独学してから仕事を探しに来て、そして最初の面接に合格してラッキーでしたが、その後のこの时間はずっと古い本を食べている状态でした.最近本当に気分が悪くて、いろいろな黄老邪!ずっと堕落した状態にあって、やってはいけないことを知っていてやった!考えてみれば心が砕ける!問題を逃さないで、30年もコードを引くと言ったのに、まだ何年も経っていない.今日はJVMのパラメータを整理します!これに対してJVMには多くのパラメータがありますが、一般の開発者が認識とスタックサイズを実行する場合はGC、リモートデバッグのパラメータでOKです.
JVM Parameters
まず、JVMのパラメータ形式について説明します.-X先頭のパラメータはすべて非標準のパラメータ(すべてのJVMが実現したわけではない) -XXはいずれも不安定であり、製造環境での の使用は推奨されない.
もちろん、これらのコマンドやオプションを常に覚えている人はいません.java-help(すべての標準オプションをリスト)java-X(すべての非標準オプションを大文字でリスト)を使用することができます.たとえば、以下は私のマシンのオプションです.
アプリケーションで現在適用されているパラメータをクエリーする場合、たとえば次のコードを使用してクエリーできます.
用途に応じていくつかの分類を行います
3つの目立たないが役に立つパラメータ(知っている挙手)
-XX:+PrintCommandLineFlags:JVMの初期化が完了した後の初期化とは異なるすべてのパラメータとその値を印刷します-XX:+PrintFlagsFinal:設定可能なすべてのパラメータと「パラメータ処理」を表示した後のデフォルト値は、異なるバージョンのデフォルト値を表示し、設定に成功したかどうかを表示します.出力された情報には、「初期デフォルト値」が使用されます.「=」は、初期デフォルト値-XX:+PrintFlagsInitialではなく、「パラメータ処理」の前に設定可能なすべてのパラメータとその値を使用し、プログラムを直接終了します.たとえば、この2つのパラメータを使用しない場合、起動情報は次のとおりです.
次の2つのパラメータを起動します.
いくつかの開発者が使用する標準パラメータ
-client:JVM使用clientモードを設定し、特徴起動が速い(神機がはっきりしない(I 5/8 G/SSD)-server:JVM使用serverモードを設定します.64ビットJDKはデフォルトでこのモードを起動します-agentlib:libname[=options]:ローカルのlib-agentlib:hprofをロードするために使用されます:JVMの実行状況を取得するために使用されます-agentpath:pathnamep[=options]:作成パスをロードするローカルライブラリ-Dproperty=value:システム属性名/値ペアの設定-jar:jarパッケージの形式でアプリケーション-javaagent:jarpath[=options]を実行するように設定します:premainメソッドを実装mainメソッドを実行する前に、このメソッドを利用してJVMレベルのhookを遊ぶことができる興味深いもの-verbose:jni:nativeメソッドの呼び出し状況を出力してJNIを遊ぶための必須スキル:
Java対戦サイズに関するJVMメモリパラメータ
-Xms:Javaスタックの初期化サイズの設定-Xmx:最大のjavaスタックサイズの設定-Xmn:Young領域サイズの設定-Xss:javaスレッドスタックサイズの設定-XX:PermSize and MaxPermSize:持続帯域サイズの設定-XX:NewRatio:若い世代と古い世代の比の設定-XX:NewSize:若い世代のサイズの設定-XX:SurvivorRation=n:若い世代におけるEの2つのSとの比の設定
ごみ捨て情報の印刷とごみ捨て情報の設定(シリアル、パラレル、同時などの動作の収集器)
-verbose:gc:GCの実行および実行時間を記録します.一般的にGCにボトルネック-XX:+PrintGCDetailsがあるかどうかを確認するために使用されます.GCの実行時の詳細を記録します.新しいメモリサイズと消費時間を含む-XX:-P rintGctimeStamps:収集したタイムスタンプの印刷-XX:+UseParallelGC:パラレルゴミ収集器-XX:-UseConcMarkSweepGC:コンカレントフラグを使用して収集器-XX:-UseSerialGC:シリアルゴミ収集器-Xloggc:filename:GCレコードを設定するファイル-XX:+UseGCLogFileRotation:GCログファイルを有効にする自動ダンプ-XX:GCLogFileSize=1 M:GCログファイルのサイズ制御
デバッグパラメータ
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -XX:HeapDumpPath=./java_pid.hprof :Path to directory or file name for heap dump. -XX:-PrintConcurrentLocks :Print java.util.concurrent locks in Ctrl-Break thread dump. -XX:-PrintCommandLineFlags :Print flags that appeared on the command line.
パフォーマンスについて
-Xprof -Xrunhprof
クラスのロードと追跡クラスのロードとアンインストールの情報
Xbootclasspath:ロードする必要があるが、クラスパスを検証したくないことを指定します.JVMは、すべてのクラスをロードする前にチェックし、各クラスに対してint値を1つずつ適用します.-X:+TraceClassLoading:トレースクラスロードの情報(メモリリークの診断に役立ちます)-X:+TraceClassUnloading:トレースクラスアンインストールの情報(メモリリークの診断に役立ちます)
JVM Parameters
まず、JVMのパラメータ形式について説明します.
1
2
3
4
5
6
7
8
9
*
-XX:+
: -XX:PrintGCDetails GC ( )
*
-XX:
-XX:NewRatio=2
*
-XX:
-XX:HeapDumpPath=./java_pid.hprof
もちろん、これらのコマンドやオプションを常に覚えている人はいません.java-help(すべての標準オプションをリスト)java-X(すべての非標準オプションを大文字でリスト)を使用することができます.たとえば、以下は私のマシンのオプションです.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$ java -help
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
-classpath
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D=
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:...|:]
-enableassertions[:...|:]
enable assertions with specified granularity
-da[:...|:]
-disableassertions[:...|:]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:[=]
load native agent library , e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:[=]
load native agent library by full pathname
-javaagent:[=]
load Java programming language agent, see java.lang.instrument
-splash:
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
$ java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:
set search path for bootstrap classes and resources
-Xbootclasspath/a:
append to end of bootstrap class path
-Xbootclasspath/p:
prepend in front of bootstrap class path
-Xdiag show additional diagnostic messages
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc: log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms set initial Java heap size
-Xmx set maximum Java heap size
-Xss 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.
アプリケーションで現在適用されているパラメータをクエリーする場合、たとえば次のコードを使用してクエリーできます.
1
2
3
4
5
6
7
8
9
10
11
12
13
package JDK.JVM;
import com.opslab.StringUtil;
import java.lang.management.ManagementFactory;
import java.util.List;
public class JvmParamerters {
public static void main(String[] args){
List paramters = ManagementFactory.getRuntimeMXBean().getInputArguments();
System.out.println(StringUtil.join(paramters,":"));
}
}
用途に応じていくつかの分類を行います
3つの目立たないが役に立つパラメータ(知っている挙手)
-XX:+PrintCommandLineFlags:JVMの初期化が完了した後の初期化とは異なるすべてのパラメータとその値を印刷します-XX:+PrintFlagsFinal:設定可能なすべてのパラメータと「パラメータ処理」を表示した後のデフォルト値は、異なるバージョンのデフォルト値を表示し、設定に成功したかどうかを表示します.出力された情報には、「初期デフォルト値」が使用されます.「=」は、初期デフォルト値-XX:+PrintFlagsInitialではなく、「パラメータ処理」の前に設定可能なすべてのパラメータとその値を使用し、プログラムを直接終了します.たとえば、この2つのパラメータを使用しない場合、起動情報は次のとおりです.
1
2
$ java -XX:+PrintGCDetails -Xloggc:./gc.log JDK.JVM.JvmParamerters
app starting...
次の2つのパラメータを起動します.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ java -XX:+PrintGCDetails -Xloggc:./gc.log -XX:+PrintCommandLineFlags -XX:+PrintFlagsFinal \
JDK.JVM.JvmParamerters
-XX:InitialHeapSize=130056064 -XX:MaxHeapSize=2080897024 -XX:+PrintCommandLineFlags
-XX:+PrintFlagsFinal -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
-XX:+UseCompressedOops -XX:+UseParallelGC
[Global flags]
...-javaagent:jarpath[=options]
uintx InitialHeapSize := 130056064 {product}
uintx InitialRAMFraction = 64 {product}
uintx InitialSurvivorRatio = 8 {product}
intx InitialTenuringThreshold = 7 {product}
uintx InitiatingHeapOccupancyPercent = 45 {product}
bool Inline = true {product}
...
bool PrintGCDetails := true {manageable}
bool PrintGCTaskTimeStamps = false {product}
bool PrintGCTimeStamps := true {manageable}
...
いくつかの開発者が使用する標準パラメータ
-client:JVM使用clientモードを設定し、特徴起動が速い(神機がはっきりしない(I 5/8 G/SSD)-server:JVM使用serverモードを設定します.64ビットJDKはデフォルトでこのモードを起動します-agentlib:libname[=options]:ローカルのlib-agentlib:hprofをロードするために使用されます:JVMの実行状況を取得するために使用されます-agentpath:pathnamep[=options]:作成パスをロードするローカルライブラリ-Dproperty=value:システム属性名/値ペアの設定-jar:jarパッケージの形式でアプリケーション-javaagent:jarpath[=options]を実行するように設定します:premainメソッドを実装mainメソッドを実行する前に、このメソッドを利用してJVMレベルのhookを遊ぶことができる興味深いもの-verbose:jni:nativeメソッドの呼び出し状況を出力してJNIを遊ぶための必須スキル:
1
-agentlib:jprofilerti=port=8849 -Xbootclasspath/a:/usr/local/jprofiler5/bin/agent.jar
Java対戦サイズに関するJVMメモリパラメータ
-Xms:Javaスタックの初期化サイズの設定-Xmx:最大のjavaスタックサイズの設定-Xmn:Young領域サイズの設定-Xss:javaスレッドスタックサイズの設定-XX:PermSize and MaxPermSize:持続帯域サイズの設定-XX:NewRatio:若い世代と古い世代の比の設定-XX:NewSize:若い世代のサイズの設定-XX:SurvivorRation=n:若い世代におけるEの2つのSとの比の設定
1
$ java -Xmx128 -Xms64 -Xmn32m -Xss16m Main
ごみ捨て情報の印刷とごみ捨て情報の設定(シリアル、パラレル、同時などの動作の収集器)
-verbose:gc:GCの実行および実行時間を記録します.一般的にGCにボトルネック-XX:+PrintGCDetailsがあるかどうかを確認するために使用されます.GCの実行時の詳細を記録します.新しいメモリサイズと消費時間を含む-XX:-P rintGctimeStamps:収集したタイムスタンプの印刷-XX:+UseParallelGC:パラレルゴミ収集器-XX:-UseConcMarkSweepGC:コンカレントフラグを使用して収集器-XX:-UseSerialGC:シリアルゴミ収集器-Xloggc:filename:GCレコードを設定するファイル-XX:+UseGCLogFileRotation:GCログファイルを有効にする自動ダンプ-XX:GCLogFileSize=1 M:GCログファイルのサイズ制御
デバッグパラメータ
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -XX:HeapDumpPath=./java_pid.hprof :Path to directory or file name for heap dump. -XX:-PrintConcurrentLocks :Print java.util.concurrent locks in Ctrl-Break thread dump. -XX:-PrintCommandLineFlags :Print flags that appeared on the command line.
パフォーマンスについて
-Xprof -Xrunhprof
クラスのロードと追跡クラスのロードとアンインストールの情報
Xbootclasspath:ロードする必要があるが、クラスパスを検証したくないことを指定します.JVMは、すべてのクラスをロードする前にチェックし、各クラスに対してint値を1つずつ適用します.-X:+TraceClassLoading:トレースクラスロードの情報(メモリリークの診断に役立ちます)-X:+TraceClassUnloading:トレースクラスアンインストールの情報(メモリリークの診断に役立ちます)