Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-11709

Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8.0, 3.0.0-alpha1
    • Component/s: None
    • Labels:
    • Target Version/s:
    • Hadoop Flags:
      Reviewed

      Description

      NANOSECONDS_PER_MILLISECOND constant can be moved to class level instead of creating it in each method call.

      org.apache.hadoop.util.Time.java
       public static long monotonicNow() {
          final long NANOSECONDS_PER_MILLISECOND = 1000000;
      
          return System.nanoTime() / NANOSECONDS_PER_MILLISECOND;
        }
      

        Activity

        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-Mapreduce-trunk-Java8 #139 (See https://builds.apache.org/job/Hadoop-Mapreduce-trunk-Java8/139/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        • hadoop-common-project/hadoop-common/CHANGES.txt
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Mapreduce-trunk-Java8 #139 (See https://builds.apache.org/job/Hadoop-Mapreduce-trunk-Java8/139/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java hadoop-common-project/hadoop-common/CHANGES.txt
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-Hdfs-trunk-Java8 #130 (See https://builds.apache.org/job/Hadoop-Hdfs-trunk-Java8/130/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/CHANGES.txt
        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Hdfs-trunk-Java8 #130 (See https://builds.apache.org/job/Hadoop-Hdfs-trunk-Java8/130/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/CHANGES.txt hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-Hdfs-trunk #2071 (See https://builds.apache.org/job/Hadoop-Hdfs-trunk/2071/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/CHANGES.txt
        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Hdfs-trunk #2071 (See https://builds.apache.org/job/Hadoop-Hdfs-trunk/2071/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/CHANGES.txt hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-Mapreduce-trunk #2089 (See https://builds.apache.org/job/Hadoop-Mapreduce-trunk/2089/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/CHANGES.txt
        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Mapreduce-trunk #2089 (See https://builds.apache.org/job/Hadoop-Mapreduce-trunk/2089/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/CHANGES.txt hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-Yarn-trunk #873 (See https://builds.apache.org/job/Hadoop-Yarn-trunk/873/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/CHANGES.txt
        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Yarn-trunk #873 (See https://builds.apache.org/job/Hadoop-Yarn-trunk/873/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/CHANGES.txt hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-Yarn-trunk-Java8 #139 (See https://builds.apache.org/job/Hadoop-Yarn-trunk-Java8/139/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        • hadoop-common-project/hadoop-common/CHANGES.txt
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-Yarn-trunk-Java8 #139 (See https://builds.apache.org/job/Hadoop-Yarn-trunk-Java8/139/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java hadoop-common-project/hadoop-common/CHANGES.txt
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Hadoop-trunk-Commit #7382 (See https://builds.apache.org/job/Hadoop-trunk-Commit/7382/)
        HADOOP-11709. Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c)

        • hadoop-common-project/hadoop-common/CHANGES.txt
        • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Hadoop-trunk-Commit #7382 (See https://builds.apache.org/job/Hadoop-trunk-Commit/7382/ ) HADOOP-11709 . Time.NANOSECONDS_PER_MILLISECOND - use class-level final constant instead of method variable. Contributed by Ajith S. (ozawa: rev 43dde502b3be2133d62f1f074f016f35a56a7e2c) hadoop-common-project/hadoop-common/CHANGES.txt hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Time.java
        Hide
        ozawa Tsuyoshi Ozawa added a comment -

        Committed this to trunk and branch-2. Thanks Ajith S for your contribution, and thanks Haohui Mai and Sean Busbey for your reviews.

        Show
        ozawa Tsuyoshi Ozawa added a comment - Committed this to trunk and branch-2. Thanks Ajith S for your contribution, and thanks Haohui Mai and Sean Busbey for your reviews.
        Hide
        ozawa Tsuyoshi Ozawa added a comment -

        +1, committing this shortly.

        Show
        ozawa Tsuyoshi Ozawa added a comment - +1, committing this shortly.
        Hide
        ajithshetty Ajith S added a comment -

        test cases are not required as no new scenario is introduced, the existing test cases passing is enough

        Show
        ajithshetty Ajith S added a comment - test cases are not required as no new scenario is introduced, the existing test cases passing is enough
        Hide
        hadoopqa Hadoop QA added a comment -

        -1 overall. Here are the results of testing the latest attachment
        http://issues.apache.org/jira/secure/attachment/12705583/001-HDFS-7919.patch
        against trunk revision 93d0f4a.

        +1 @author. The patch does not contain any @author tags.

        -1 tests included. The patch doesn't appear to include any new or modified tests.
        Please justify why no new tests are needed for this patch.
        Also please list what manual steps were performed to verify this patch.

        +1 javac. The applied patch does not increase the total number of javac compiler warnings.

        +1 javadoc. There were no new javadoc warning messages.

        +1 eclipse:eclipse. The patch built with eclipse:eclipse.

        +1 findbugs. The patch does not introduce any new Findbugs (version 2.0.3) warnings.

        +1 release audit. The applied patch does not increase the total number of release audit warnings.

        +1 core tests. The patch passed unit tests in hadoop-common-project/hadoop-common.

        Test results: https://builds.apache.org/job/PreCommit-HADOOP-Build/5971//testReport/
        Console output: https://builds.apache.org/job/PreCommit-HADOOP-Build/5971//console

        This message is automatically generated.

        Show
        hadoopqa Hadoop QA added a comment - -1 overall . Here are the results of testing the latest attachment http://issues.apache.org/jira/secure/attachment/12705583/001-HDFS-7919.patch against trunk revision 93d0f4a. +1 @author . The patch does not contain any @author tags. -1 tests included . The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch. +1 javac . The applied patch does not increase the total number of javac compiler warnings. +1 javadoc . There were no new javadoc warning messages. +1 eclipse:eclipse . The patch built with eclipse:eclipse. +1 findbugs . The patch does not introduce any new Findbugs (version 2.0.3) warnings. +1 release audit . The applied patch does not increase the total number of release audit warnings. +1 core tests . The patch passed unit tests in hadoop-common-project/hadoop-common. Test results: https://builds.apache.org/job/PreCommit-HADOOP-Build/5971//testReport/ Console output: https://builds.apache.org/job/PreCommit-HADOOP-Build/5971//console This message is automatically generated.
        Hide
        ajithshetty Ajith S added a comment -

        Thank you for the inputs. Submitting patch to move the variable to a class level constant. Please review the same

        Show
        ajithshetty Ajith S added a comment - Thank you for the inputs. Submitting patch to move the variable to a class level constant. Please review the same
        Hide
        busbey Sean Busbey added a comment -

        Javac (Oracle 1.7.0_51) will propagate the constant, but it doesn't eliminate the local store.

        original:

        public static long monotonicNow();
            Signature: ()J
            flags: ACC_PUBLIC, ACC_STATIC
            LineNumberTable:
              line 48: 0
              line 50: 4
            LocalVariableTable:
              Start  Length  Slot  Name   Signature
                     4       8     0 NANOSECONDS_PER_MILLISECOND   J
            Code:
              stack=4, locals=2, args_size=0
                 0: ldc2_w        #3                  // long 1000000l
                 3: lstore_0
                 4: invokestatic  #5                  // Method java/lang/System.nanoTime:()J
                 7: ldc2_w        #3                  // long 1000000l
                10: ldiv
                11: lreturn
        

        patched:

          public static long monotonicNow();
            Signature: ()J
            flags: ACC_PUBLIC, ACC_STATIC
            LineNumberTable:
              line 51: 0
            Code:
              stack=4, locals=0, args_size=0
                 0: invokestatic  #3                  // Method java/lang/System.nanoTime:()J
                 3: ldc2_w        #4                  // long 1000000l
                 6: ldiv     
                 7: lreturn  
        

        I'm guessing that any decent jit will notice that the store is dead and remove it. this still seems like an okay low-priority optimization for the warm up period. (the marking of Trivial and beginner should do enough to signal the relatively low gain.)

        Show
        busbey Sean Busbey added a comment - Javac (Oracle 1.7.0_51) will propagate the constant, but it doesn't eliminate the local store. original: public static long monotonicNow(); Signature: ()J flags: ACC_PUBLIC, ACC_STATIC LineNumberTable: line 48: 0 line 50: 4 LocalVariableTable: Start Length Slot Name Signature 4 8 0 NANOSECONDS_PER_MILLISECOND J Code: stack=4, locals=2, args_size=0 0: ldc2_w #3 // long 1000000l 3: lstore_0 4: invokestatic #5 // Method java/lang/ System .nanoTime:()J 7: ldc2_w #3 // long 1000000l 10: ldiv 11: lreturn patched: public static long monotonicNow(); Signature: ()J flags: ACC_PUBLIC, ACC_STATIC LineNumberTable: line 51: 0 Code: stack=4, locals=0, args_size=0 0: invokestatic #3 // Method java/lang/ System .nanoTime:()J 3: ldc2_w #4 // long 1000000l 6: ldiv 7: lreturn I'm guessing that any decent jit will notice that the store is dead and remove it. this still seems like an okay low-priority optimization for the warm up period. (the marking of Trivial and beginner should do enough to signal the relatively low gain.)
        Hide
        wheat9 Haohui Mai added a comment -

        I don't quite follow that why this is necessary as it is a simple exercise of constant propagation from the compiler point of view?

        Show
        wheat9 Haohui Mai added a comment - I don't quite follow that why this is necessary as it is a simple exercise of constant propagation from the compiler point of view?

          People

          • Assignee:
            ajithshetty Ajith S
            Reporter:
            ajithshetty Ajith S
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development