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

Unnecessary boxing conversions in void-returning lambdas

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 24
    • None
    • tools
    • b08

    Description

      After the recent changes to lowering of lambdas, javac is generating unnecessary boxing conversions for expression bodied lambdas that implement a void returning method.

      class T {
        int g() { return 0; }
        Runnable r = () -> g();
      }

      Before:

        private void lambda$new$0();
          descriptor: ()V
          flags: (0x1002) ACC_PRIVATE, ACC_SYNTHETIC
          Code:
            stack=1, locals=1, args_size=1
               0: aload_0
               1: invokevirtual #17 // Method g:()I
               4: pop
               5: return
            LineNumberTable:
              line 3: 0

      After:

        private void lambda$new$0();
          descriptor: ()V
          flags: (0x1002) ACC_PRIVATE, ACC_SYNTHETIC
          Code:
            stack=1, locals=1, args_size=1
               0: aload_0
               1: invokevirtual #17 // Method g:()I
               4: invokestatic #21 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
               7: pop
               8: return
            LineNumberTable:
              line 3: 0

      Note the new call to Integer.valueOf

      javac is not an optimizing compiler, but the new calls are unnecessary can result in additional allocations, and would be nice to omit.

      Attachments

        Issue Links

          Activity

            People

              cushon Liam Miller-Cushon
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: