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

StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested

    XMLWordPrintable

    Details

      Description

      The debug "exactness" check produces a wrong bytecode when a no-arg method is pushed to StringConcatFactory BSM. This happens only with -Djava.lang.invoke.stringConcat.debug=true, and -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT. Note that no Java language string concat expression would result in javac emitting a no-arg SCF call, and we only have the failure on a targeted test that calls BSM directly.

      A targeted test fails with:

      Caused by: java.lang.VerifyError: Local variable table overflow
      Exception Details:
        Location:
          java/lang/String$Concat.concat()Ljava/lang/String; @12: istore
        Reason:
          Local index 0 is invalid
        Bytecode:
          0000000: bb00 0959 03b7 000d 59b6 0011 3600 b600
          0000010: 1459 b600 1915 009f 000d bb00 1b59 121d
          0000020: b700 20bf b0
        Stackmap Table:
          same_locals_1_stack_item_frame(@36,Object[#22])

      at sun.misc.Unsafe.defineAnonymousClass(Native Method)
      at java.lang.invoke.StringConcatFactory$BytecodeStringBuilderStrategy.generate(StringConcatFactory.java:1024)
      at java.lang.invoke.StringConcatFactory$BytecodeStringBuilderStrategy.access$000(StringConcatFactory.java:732)
      at java.lang.invoke.StringConcatFactory.generate(StringConcatFactory.java:656)
      ... 11 more

      In turn, this happens because "exactness" check needs a single slot to hold a temporary variable. In the case of non-arg method, local variable table is not large enough, and it overflows.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shade Aleksey Shipilev
              Reporter:
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: