[
https://issues.apache.org/jira/browse/HADOOP-11709?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14361929#comment-14361929
]
Sean Busbey commented on HADOOP-11709:
--------------------------------------
Javac (Oracle 1.7.0_51) will propagate the constant, but it doesn't eliminate
the local store.
original:
{code}
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
{code}
patched:
{code}
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
{code}
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.)
> Time.NANOSECONDS_PER_MILLISECOND - use class level final constant instead of
> method variable
> ---------------------------------------------------------------------------------------------
>
> Key: HADOOP-11709
> URL: https://issues.apache.org/jira/browse/HADOOP-11709
> Project: Hadoop Common
> Issue Type: Improvement
> Reporter: Ajith S
> Assignee: Ajith S
> Priority: Trivial
> Labels: beginner, newbie
>
> NANOSECONDS_PER_MILLISECOND constant can be moved to class level instead of
> creating it in each method call.
> {code}
> org.apache.hadoop.util.Time.java
> public static long monotonicNow() {
> final long NANOSECONDS_PER_MILLISECOND = 1000000;
> return System.nanoTime() / NANOSECONDS_PER_MILLISECOND;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)