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

poor performance of constant expression calculation

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: dkC59003 Date: 10/26/98



      Javac fails to compile the small (just 20 lines) class "tce4tree" displayed below in any
      acceptable amount of time.

      I have tried to comment-away the lines marked as A,B,C and compile it with JDK 1.2fcs-O.
      The folowing amounts of time were elapsed for compilation on UltraSPARC-1(200MHz) and
      Pentium-II(266MHz,solaris):

      Junked| |
      lines:| Sparc | P-II
      ------+--------+------
      A,B,C | 1m21s | 26s
      B & C | 5m12s | 1m31s
      C only| 21m46s | 6m02s

      It is easy to see, that compilation time grows geometrically in this experiment
      (each commented-away line reduces compilation time by appreximately 4 times).
      It seems like javac doesn't even try to reuse results of previous calculation of
      final variables values, and possibly back-trace every occurence of final variable
      in a constant expression.

      This problem also affects JDK 1.1.6. (I guess that all JDK 1.1.x are affected too.)

      However, the class "tce4linear" displayed below is easily compiled by JDK 1.1.x and 1.2.

      ---

      class tce4tree {
          static void main (String args[]) {
      final float x1 = 1f;
      final float x4 = x1 + x1 + x1 + x1;
      final float x16 = x4 + x4 + x4 + x4;
      final float x64 = x16 + x16 + x16 + x16;
      final float x256 = x64 + x64 + x64 + x64;
      final float x1024 = x256 + x256 + x256 + x256;
      final float x4096 = x1024 + x1024 + x1024 + x1024;
      final float x16384 = x4096 + x4096 + x4096 + x4096;
      final float x65536 = x16384 + x16384 + x16384 + x16384;
      final float x262144 = x65536 + x65536 + x65536 + x65536;
      final float x1048576 = x262144 + x262144 + x262144 + x262144;
      final float x4194304 = x1048576 + x1048576 + x1048576 + x1048576;
      final float x16777216 = x4194304 + x4194304 + x4194304 + x4194304;
      /*A*/ final float x67108864 = x16777216 + x16777216 + x16777216 + x16777216;
      /*B*/ final float x268435456 = x67108864 + x67108864 + x67108864 + x67108864;
      /*C*/ final float x1073741824 = x268435456 + x268435456 + x268435456 + x268435456;
          };
      }

      ---

      class tce4linear {

          static void main (String args[]) {
      final float x1 = 1f;
      final float x4 = x1 * 4;
      final float x16 = x4 * 4;
      final float x64 = x16 * 4;
      final float x256 = x64 * 4;
      final float x1024 = x256 * 4;
      final float x4096 = x1024 * 4;
      final float x16384 = x4096 * 4;
      final float x65536 = x16384 * 4;
      final float x262144 = x65536 * 4;
      final float x1048576 = x262144 * 4;
      final float x4194304 = x1048576 * 4;
      final float x16777216 = x4194304 * 4;
      final float x67108864 = x16777216 * 4;
      final float x268435456 = x67108864 * 4;
      final float x1073741824 = x268435456 * 4;
          };

      }

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                wmaddoxsunw William Maddox (Inactive)
                Reporter:
                dkhukhrosunw Dmitry Khukhro (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: