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

Bootstrap Method Called Multiple Times Despite Initial Resolution Failure

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 11
    • 9
    • hotspot
    • None

      Java Virtual Machine Specification Section 5.4.3 Resolution states:

      "In the case of failed resolution of an invokedynamic instruction, the bootstrap
      method is not re-executed on subsequent resolution attempts."

      The attached example demonstrates a failure to capture the resolution result when the BSM has thrown an exception during execution of the BSM, thus failing to create a CallSite object. Upon reexecution of the same invokedynamic bytecode, the BSM is invoked a second time even though the first resolution failed, which according to Section 5.4.3 it should not be.

      The following commands reproduces the issue:
      % javac --add-modules java.base --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED BSMCalledTwice.java
      Note: BSMCalledTwice.java uses or overrides a deprecated API.
      Note: Recompile with -Xlint:deprecation for details.

      % java --add-modules java.base --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED BSMCalledTwice

      %java TestC
      Caught Error:
      call site initialization exception
      java.lang.BootstrapMethodError: call site initialization exception
              at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:384)
              at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:250)
              at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:240)
              at TestC.main(Unknown Source)
      Caused by: java.lang.invoke.StringConcatException: Mismatched number of concat constants: recipe wants 0 constants, but only 1 are passed
              at java.base/java.lang.invoke.StringConcatFactory.doStringConcat(StringConcatFactory.java:597)
              at java.base/java.lang.invoke.StringConcatFactory.makeConcatWithConstants(StringConcatFactory.java:547)
              at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:327)
              ... 3 more
      Caught Error:
      call site initialization exception
      java.lang.BootstrapMethodError: call site initialization exception
              at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:384)
              at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:250)
              at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:240)
              at TestC.main(Unknown Source)
      Caused by: java.lang.invoke.StringConcatException: Mismatched number of concat constants: recipe wants 0 constants, but only 1 are passed
              at java.base/java.lang.invoke.StringConcatFactory.doStringConcat(StringConcatFactory.java:597)
              at java.base/java.lang.invoke.StringConcatFactory.makeConcatWithConstants(StringConcatFactory.java:547)
              at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:327)
              ... 3 more

            hseigel Harold Seigel (Inactive)
            lfoltan Lois Foltan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: