Eliminating dead-code and constant folding

Dead-code and constant folding are often referred to as redundant code and our modern compilers are pretty good at eliminating them. An example of dead-code is code that will never be reached. Consider the following example:

    . . .     int value = 10;    if (value != null)    {      System.out.println("The value is " + value + ".");    } else       {         System.out.println("The value is null."); // This is         a line of Dead-Code    }    . . . 

In our preceding example, the line identified as dead-code is never reached since the variable value will never be equal to null. It is set to 10 immediately before the conditional if statement evaluates the variable.

The problem is that benchmarking code can sometimes be removed in the attempt ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.