プライマリ・コンテンツに移動
Java Platform, Standard Edition Java仮想マシン・ガイド
リリース9
E90919-02
目次へ移動
目次

前
次

ディレクティブの理解

次のトピックでは、ディレクティブの動作と相互作用について確認します。

デフォルト・ディレクティブとは

デフォルト・ディレクティブは、すべての可能なディレクティブ・オプションのデフォルト値が含まれるコンパイラ・ディレクティブです。これはディレクティブ・スタックの最下部にあり、コンパイルに送信される各メソッドに一致します。

新規ディレクティブを設計する際、新規ディレクティブがデフォルト・ディレクティブとどのように異なるかを指定します。デフォルト・ディレクティブは、設計上の判断を導くためのテンプレートになります。

デフォルト・ディレクティブのディレクティブ・オプション値

空のディレクティブ・スタックを出力すると、デフォルト・ディレクティブの一致基準およびすべてのディレクティブ・オプションの値が明らかになります。
Directive: (default)
 matching: *.*
 c1 directives:
  inline: -
  Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false PrintAssembly:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpReplay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false DisableIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOutput:false TraceSpilling:false Vectorize:false VectorizeDebug:0 CloneMapDebug:false IGVPrintLevel:0 MaxNodeLimit:80000

 c2 directives:
  inline: -
  Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false PrintAssembly:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpReplay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false DisableIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOutput:false TraceSpilling:false Vectorize:false VectorizeDebug:0 CloneMapDebug:false IGVPrintLevel:0 MaxNodeLimit:80000

注意:

これらの出力ではすべてのディレクティブ・オプションとそれらの値の詳細が提供されますが、特定のオプションはc2コンパイラのみに適用されます。完全なリストについては、表2-2を参照してください。

新規ディレクティブのディレクティブ・オプション値

新規ディレクティブは、それらがデフォルト・ディレクティブとどのように異なるかを指定する必要があります。ディレクティブ・オプションが言及されていない場合、そのオプションはデフォルト・ディレクティブの値を保持します。

次に例を示します。
[
    {
        match: ["*Concurrent.*"],
        c2: {
            MaxNodeLimit: 1000,
        },
        Exclude:true,
    },
]
このディレクティブをディレクティブ・スタックに追加すると、デフォルト・ディレクティブはスタック内の最下位のディレクティブになります。この処理の詳細は、ディレクティブ・スタック内のディレクティブの順序を参照してください。最終的なディレクティブ・スタックの出力には、例の中で指定したディレクティブ・オプションのみがデフォルト・ディレクティブにある値と異なっていることが示されます。
Directive:
 matching: *Concurrent.*
 c1 directives:
  inline: -
  Enable:true Exclude:true BreakAtExecute:false BreakAtCompile:false Log:false PrintAssembly:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpReplay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false DisableIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOutput:false TraceSpilling:false Vectorize:false VectorizeDebug:0 CloneMapDebug:false IGVPrintLevel:0 MaxNodeLimit:80000 

 c2 directives:
  inline: -
  Enable:true Exclude:true BreakAtExecute:false BreakAtCompile:false Log:false PrintAssembly:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpReplay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false DisableIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOutput:false TraceSpilling:false Vectorize:false VectorizeDebug:0 CloneMapDebug:false IGVPrintLevel:0 MaxNodeLimit:1000 


Directive: (default)
 matching: *.*
 c1 directives:
  inline: -
  Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false PrintAssembly:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpReplay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false DisableIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOutput:false TraceSpilling:false Vectorize:false VectorizeDebug:0 CloneMapDebug:false IGVPrintLevel:0 MaxNodeLimit:80000 

 c2 directives:
  inline: -
  Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false PrintAssembly:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpReplay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false DisableIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOutput:false TraceSpilling:false Vectorize:false VectorizeDebug:0 CloneMapDebug:false IGVPrintLevel:0 MaxNodeLimit:80000 

コードへのディレクティブの適用

ディレクティブは、メソッド照合プロセスに基づいてコードに適用されます。コンパイルのために送信された各メソッドは、ディレクティブ・スタック内のディレクティブと照合されます。

メソッドとディレクティブ・スタックの照合を行うプロセスはCompilerBrokerによって実行されます。

メソッド照合プロセス

メソッドがコンパイルのために送信されると、その完全修飾名がディレクティブ・スタックの一致基準と比較されます。スタック内の最初の一致ディレクティブがメソッドに適用されます。スタック内の残りのディレクティブは無視されます。それ以外の一致が見つからない場合、デフォルト・ディレクティブが適用されます。

このプロセスは、コンパイルにおいてすべてのメソッドに対して繰り返されます。したがって、コンパイルでは複数のディレクティブが適用される場合があります。ただし、メソッド当たり1つのディレクティブのみが適用されます。スタック内のすべてのディレクティブは潜在的に適用可能であるため、アクティブであるとみなされます。アクティブなディレクティブと適用されたディレクティブの主な違いは次のとおりです。

  • ディレクティブがディレクティブ・スタックに存在する場合、そのディレクティブはアクティブです。

  • ディレクティブがコードに影響を及ぼしている場合、そのディレクティブは適用されています。

例2-1 一致が見つかった場合

コンパイルのために送信されたメソッドの例:
public int exampleMethod(int x){
	return x;
}
メソッド照合基準に基づいて、次の例のディレクティブ・スタックからDirective 2が適用されます。
Directive 2:
 matching: *.*example*
Directive 1:
 matching: *.*exampleMethod*
Directive 0: (default)
 matching: *.*

例2-2 一致が見つからない場合

次の例のメソッドがコンパイルのために送信された場合:
public int otherMethod(int y){
	return y;
}
次の例のディレクティブ・スタックのメソッド照合基準に基づいて、Directive 0 (デフォルト・ディレクティブ)が適用されます。
Directive 2:
 matching: *.*example*
Directive 1:
 matching: *.*exampleMethod*
Directive 0: (default)
 matching: *.*

その他のガイドライン

  • ディレクティブのメソッド照合基準を慎重に記述します。指定されたメソッドに適用されるディレクティブを検証するフィードバック・メカニズムはありません。かわりに、JMXなどのプロファイラを使用して、適用されたディレクティブの累積的な影響を測定できます。

  • CompilerBrokerは、不正なコード(対応していないプラットフォームのハードウェアに命令を強制するなど)を作成するディレクティブ・オプションを無視します。警告メッセージが表示されます。

  • ディレクティブ・オプションには、一般的なコマンドライン・フラグと同じ制限があります。たとえば、インライン・コードに対する命令が処理されるのは、中間表現(IR)が大きくなりすぎない場合にかぎられます。

コンパイラ・コントロールと下位互換性

コンパイラ・コントロール・ディレクティブとともに、CompileCommandおよびコマンドライン・フラグを使用できます。

コンパイラ・コントロールはすべてのユース・ケースでCompileCommandを置き換えることができますが、下位互換性は引き続き提供されます。両方を同時に利用することもできます。優先されるのはコンパイラ・コントロールです。競合は、次の優先順位付けに基づいて処理されます。
  1. コンパイラ・コントロール

  2. CompileCommand

  3. コマンドライン・フラグ

  4. デフォルト値

例2-3 コンパイラ・コントロールとCompileCommandの併用

次のリストは、いくつかのコンパイル・オプションとこれらのオプションに値を割り当てる方法を示しています。
  • コンパイラ・コントロール:

    • Exclude: true

    • BreakAtExecute: false

  • CompileCommand:

    • BreakAtExecute: true

    • BreakAtCompile: true

  • デフォルト値:

    • Exclude: false

    • BreakAtExecute: false

    • BreakAtCompile: false

    • Log: false

この例のオプションと値を使用した結果としてのコンパイルへの影響は、下位互換性の競合を処理するルールによって決まります。
  • Exclude: true

  • BreakAtExecute: false

  • BreakAtCompile: true

  • Log: false