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

Crash in JVM_GetClassModifiers when redefining a class' private method during resolution of the bootstrap specifier

    XMLWordPrintable

Details

    Description

      The following program crashes when trying to redefine the class' private method during resolution of the bootstrap method used within that private method. The bootstrap method is being resolved resulting from the private method containing an invokedynamic instruction.

      ==============================================
      /*
       * @test
       * @library /test/lib
       * @modules java.base/jdk.internal.misc
       * @modules java.compiler
       * java.instrument
       * jdk.jartool/sun.tools.jar
       * @run main RedefineClassHelper
       * @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine+class*=trace RedefineInterfaceMethods
       */
      public class RedefineInterfaceMethods {

          static final int RET = -2;

          static interface B {
              int ORIGINAL_RETURN = 1;
              int NEW_RETURN = 2;
              private int privateMethod() {
                  Runnable race1 = () -> System.out.println("Hello from inside privateMethod");
                  race1.run();
                  return ORIGINAL_RETURN;
              }
              public default int defaultMethod(String p) {
                  return privateMethod();
              }
          }

          public static String redefinedPrivateMethod =
              "interface RedefineInterfaceMethods$B {" +
              " int ORIGINAL_RETURN = 1;" +
              " int NEW_RETURN = 2;" +
              " private int privateMethod() {" +
              " Runnable race1 = () -> System.out.println(\"Hello from inside privateMethod\");" +
              " race1.run();" +
              " return NEW_RETURN;" +
              " }" +
              " public default int defaultMethod(String p) {" +
      // " System.out.println(p + \"from interface B's defaultMethod\");" +
              " return privateMethod();" +
              " }" +
              "}";

          static class Impl implements B {
          }


          public static void main(String[] args) throws Exception {

              Impl impl = new Impl();

              int res = impl.defaultMethod("Hello ");
              if (res != B.ORIGINAL_RETURN)
                  throw new Error("defaultMethod returned " + res +
                                  " expected " + B.ORIGINAL_RETURN);
              RedefineClassHelper.redefineClass(B.class, redefinedPrivateMethod);

              res = impl.defaultMethod("Goodbye ");
              if (res != B.NEW_RETURN)
                  throw new Error("defaultMethod returned " + res +
                                  " expected " + B.NEW_RETURN);
          }
      }

      Attachments

        Issue Links

          Activity

            People

              sspitsyn Serguei Spitsyn
              lfoltan Lois Foltan
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: