ディレクティブの理解

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

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

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

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

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

空のディレクティブ・スタックを出力すると、デフォルト・コンパイラ・ディレクティブ内のすべてのディレクティブ・オプションの一致基準および値が明らかになります。
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: *.*

新規ディレクティブの記述に関するガイドライン

  • 指定されたメソッドに適用されるディレクティブを検証するフィードバック・メカニズムはありません。かわりに、Java Management Extensions (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