2

JITコンパイラロジックをチェックするためのテストクラスに従っています:

public static final int COUNT = 2_000_000_000;

public static final MyLogger LOG = new MyLogger(false);

//Here IS_DEBUG is false
public static final boolean IS_DEBUG = LOG.isDebug();

private void run() throws Exception
{
    System.out.println(getSum(COUNT));

    //Compilation without OSR
    System.out.println(getSum(COUNT + 2));

    //Change value IS_DEBUG -> true over reflection
    setFinalStatic(TestDeadCode.class.getField("IS_DEBUG"), true);
    //Show true
    System.out.println(IS_DEBUG);
    
    COUNT = COUNT / 2;
    System.out.println(getSum(COUNT + 3));
}

private int getSum(int count)
{
    int result = 0;
    for (int j = 0; j < count; j++)
    {
        result = result + 1;
        if (IS_DEBUG)
        {
            //Dead code here
            System.out.println("debug: " + result);
        }
    }
    return result;
}

メソッドrun()を呼び出すと、「デッドコード」

System.out.println("debug: " + result);

決して実行されません。JVMのバグですか?

Java のバージョン:

Java(TM) SE ランタイム環境 (ビルド 1.7.0_17-b02)

Java HotSpot(TM) 64 ビット サーバー VM (ビルド 23.7-b01、混合モード)

更新: PrintCompilation 出力:

79    1 %           com.nau.sample.deadcode.TestDeadCode::getSum @ 7 (34 bytes)

85    1             com.nau.sample.deadcode.TestDeadCode::getSum (34 bytes)
4

0 に答える 0