Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333891

Method excluded with directive is not compiled after removal of directive

XMLWordPrintable

      The following test excludes a Java method from compilation with a compiler directive first. It clears the directive stack second. It expects to be able to compile the method.
      ```
      /**
       * @test ClearDirectivesTest
       * @requires vm.compiler1.enabled & vm.compiler2.enabled
       * @library /test/lib /
       * @modules java.base/jdk.internal.misc
       *
       * @build jdk.test.whitebox.WhiteBox
       * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
       *
       * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
       * -Xlog:codecache=trace
       * serviceability.dcmd.compiler.ClearDirectivesTest
       */

      package serviceability.dcmd.compiler;

      import jdk.test.lib.dcmd.JMXExecutor;
      import jdk.test.lib.process.OutputAnalyzer;
      import jdk.test.whitebox.WhiteBox;

      import java.lang.reflect.Method;

      import static jdk.test.lib.Asserts.assertEQ;

      import static compiler.whitebox.CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION;
      import static compiler.whitebox.CompilerWhiteBoxTest.COMP_LEVEL_NONE;

      public class ClearDirectivesTest {

          static int calc(int v) {
              int result = 0;
              for (int i = 0; i < v; ++i) {
                result += result * v + i;
              }
              return result;
          }

          public static void main(String[] args) throws Exception {
              Method method = ClearDirectivesTest.class.getDeclaredMethod("calc", int.class);
              String dirs = """
              [{
                 match: "*::calc",
                 c2: {Exclude: true}
              }]""";
              WhiteBox wb = WhiteBox.getWhiteBox();
              wb.addCompilerDirective(dirs);
              new JMXExecutor().execute("Compiler.directives_print");
              wb.enqueueMethodForCompilation(method, COMP_LEVEL_FULL_OPTIMIZATION);
              while (wb.isMethodQueuedForCompilation(method)) {
                  Thread.onSpinWait();
              }
              assertEQ(COMP_LEVEL_NONE, wb.getMethodCompilationLevel(method), "Compilation level");
              new JMXExecutor().execute("Compiler.directives_clear");
              new JMXExecutor().execute("Compiler.directives_print");
              wb.enqueueMethodForCompilation(method, COMP_LEVEL_FULL_OPTIMIZATION);
              while (wb.isMethodQueuedForCompilation(method)) {
                  Thread.onSpinWait();
              }
              assertEQ(COMP_LEVEL_FULL_OPTIMIZATION, wb.getMethodCompilationLevel(method), "Compilation level");
          }
      }
      ```

      The test failed:
      ```
      STDOUT:
      1 compiler directives added
      Running DCMD 'Compiler.directives_print' through 'JMXExecutor'
      ---------------- stdout ----------------

      Directive:
       matching: *.calc
       c1 directives:
        inline: -
        Enable:false Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false MemLimit:0 MemStat:0 PrintAssembly:false PrintCompilation:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpRep
      lay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false RepeatCompilation:0 DisableIntrinsic: ControlIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOpto
      Output:false TraceEscapeAnalysis:false PrintIdeal:false TraceSpilling:false Vectorize:false CloneMapDebug:false IGVPrintLevel:0 IncrementalInlineForceCleanup:false MaxNodeLimit:80000 TraceAutoVectorization: PrintIdealPhase:

       c2 directives:
        inline: -
        Enable:true Exclude:true BreakAtExecute:false BreakAtCompile:false Log:false MemLimit:0 MemStat:0 PrintAssembly:false PrintCompilation:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpRepla
      y:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false RepeatCompilation:0 DisableIntrinsic: ControlIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoOu
      tput:false TraceEscapeAnalysis:false PrintIdeal:false TraceSpilling:false Vectorize:false CloneMapDebug:false IGVPrintLevel:0 IncrementalInlineForceCleanup:false MaxNodeLimit:80000 TraceAutoVectorization: PrintIdealPhase:


      Directive: (default)
       matching: *.*
       c1 directives:
        inline: -
        Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false MemLimit:0 MemStat:0 PrintAssembly:false PrintCompilation:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpRepl
      ay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false RepeatCompilation:0 DisableIntrinsic: ControlIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoO
      utput:false TraceEscapeAnalysis:false PrintIdeal:false TraceSpilling:false Vectorize:false CloneMapDebug:false IGVPrintLevel:0 IncrementalInlineForceCleanup:false MaxNodeLimit:80000 TraceAutoVectorization: PrintIdealPhase:

       c2 directives:
        inline: -
        Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false MemLimit:0 MemStat:0 PrintAssembly:false PrintCompilation:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpRepl
      ay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false RepeatCompilation:0 DisableIntrinsic: ControlIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoO
      utput:false TraceEscapeAnalysis:false PrintIdeal:false TraceSpilling:false Vectorize:false CloneMapDebug:false IGVPrintLevel:0 IncrementalInlineForceCleanup:false MaxNodeLimit:80000 TraceAutoVectorization: PrintIdealPhase:


      ---------------- stderr ----------------

      ----------------------------------------

      WB error: failed to compile at level 4 method serviceability.dcmd.compiler.ClearDirectivesTest::calc
      Running DCMD 'Compiler.directives_clear' through 'JMXExecutor'
      ---------------- stdout ----------------

      ---------------- stderr ----------------

      ----------------------------------------

      Running DCMD 'Compiler.directives_print' through 'JMXExecutor'
      ---------------- stdout ----------------

      Directive: (default)
       matching: *.*
       c1 directives:
        inline: -
        Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false MemLimit:0 MemStat:0 PrintAssembly:false PrintCompilation:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpRepl
      ay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false RepeatCompilation:0 DisableIntrinsic: ControlIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoO
      utput:false TraceEscapeAnalysis:false PrintIdeal:false TraceSpilling:false Vectorize:false CloneMapDebug:false IGVPrintLevel:0 IncrementalInlineForceCleanup:false MaxNodeLimit:80000 TraceAutoVectorization: PrintIdealPhase:

       c2 directives:
        inline: -
        Enable:true Exclude:false BreakAtExecute:false BreakAtCompile:false Log:false MemLimit:0 MemStat:0 PrintAssembly:false PrintCompilation:false PrintInlining:false PrintNMethods:false BackgroundCompilation:true ReplayInline:false DumpRepl
      ay:false DumpInline:false CompilerDirectivesIgnoreCompileCommands:false RepeatCompilation:0 DisableIntrinsic: ControlIntrinsic: BlockLayoutByFrequency:true PrintOptoAssembly:false PrintIntrinsics:false TraceOptoPipelining:false TraceOptoO
      utput:false TraceEscapeAnalysis:false PrintIdeal:false TraceSpilling:false Vectorize:false CloneMapDebug:false IGVPrintLevel:0 IncrementalInlineForceCleanup:false MaxNodeLimit:80000 TraceAutoVectorization: PrintIdealPhase:


      ---------------- stderr ----------------

      ----------------------------------------

      WB error: failed to compile at level 4 method serviceability.dcmd.compiler.ClearDirectivesTest::calc
      [4.725s][debug][codecache] failed to find oopmap for cb: 0x00007f982c23fc08 offset: 531
      STDERR:
      java.lang.RuntimeException: Compilation level expected: 4 but was: 0
              at jdk.test.lib.Asserts.fail(Asserts.java:691)
              at jdk.test.lib.Asserts.assertEquals(Asserts.java:204)
              at jdk.test.lib.Asserts.assertEQ(Asserts.java:180)
              at serviceability.dcmd.compiler.ClearDirectivesTest.main(ClearDirectivesTest.java:59)
              at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
              at java.base/java.lang.reflect.Method.invoke(Method.java:580)
              at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
              at java.base/java.lang.Thread.run(Thread.java:1575)
      ```

            eastigeevich Evgeny Astigeevich
            eastigeevich Evgeny Astigeevich
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: