Ethanlm commented on a change in pull request #3368:
URL: https://github.com/apache/storm/pull/3368#discussion_r548240226



##########
File path: storm-client/src/jvm/org/apache/storm/utils/Utils.java
##########
@@ -1039,7 +1039,7 @@ public static Double 
parseJvmHeapMemByChildOpts(List<String> options, Double def
                 }
                 Matcher m = optsPattern.matcher(option);
                 while (m.find()) {
-                    int value = Integer.parseInt(m.group(1));
+                    long value = Long.parseLong(m.group(1));

Review comment:
       https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.7
   
   > The left-hand operand of a binary operator appears to be fully evaluated 
before any part of the right-hand operand is evaluated.
   > The Java programming language guarantees that every operand of an operator 
(except the conditional operators &&, ||, and ? :) appears to be fully 
evaluated before any part of the operation itself is performed.
   
   So I would look at `value * unit / 1024.0 / 1024.0; ` as 
   ```
   int tmp = value * unit;
   double tmp1 = tmp / 1024.0;
   double tmp2 = tmp1 / 1024.0;
   ```
   
   And the Widening Primitive Conversion happens at each operation. Looking at 
the byte code of this short example
   
   java:
   ```
   public static void main(String[] args)  {
           int value = 2;
           int unit = 1024 * 1024 * 1024;
           double result = value * unit / 1024.0 / 1024.0 ;
           System.out.println(result);
   }
   ```
   bytecode:
   ```
     public static void main(java.lang.String[]);
       Code:
          0: iconst_2
          1: istore_1
          2: ldc           #2                  // int 1073741824
          4: istore_2
          5: iload_1
          6: iload_2
          7: imul
          8: i2d
          9: ldc2_w        #3                  // double 1024.0d
         12: ddiv
         13: ldc2_w        #3                  // double 1024.0d
         16: ddiv
         17: dstore_3
         18: getstatic     #5                  // Field 
java/lang/System.out:Ljava/io/PrintStream;
         21: dload_3
         22: invokevirtual #6                  // Method 
java/io/PrintStream.println:(D)V
         25: return
   }
   
   ```
   It first calculate `value * unit` based on integer. Then on line8, `i2d` is 
invoked to convert integer to double. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to