Diego Elias Damasceno Costa created LOG4J2-2478:
---------------------------------------------------

             Summary: JMH Benchmarks in not consuming all computed variables 
(risk of DCE)
                 Key: LOG4J2-2478
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2478
             Project: Log4j 2
          Issue Type: Bug
          Components: Tests
         Environment: I am reporting the result of 5 full executions with 
default parameters (iterations, forks, warmups, etc..)

Tests run on a Computational server with CPU: E5-1660-3.3GHZ (6 cores + HT), 64 
GB RAM.
            Reporter: Diego Elias Damasceno Costa
         Attachments: logginglog4j2-jmhantipatterns-retu.csv

We are conducting a scientific study to investigate bad practices/anti-patterns 
on creating micro-benchmarks using JMH, and we found an instance of harmfull 
non-consumed computation in `AbstractStringLayoutStringEncodingBenchmark`.

As a good practice, every computation performed in inside the benchmark should 
be consumed (see [JMH 
Documentation|[http://hg.openjdk.java.net/code-tools/jmh/file/66fb723292d4/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_08_DeadCode.java].]
 

This is partially done here with the self-made consume method, but on some 
benchmarks (such as baseline, usAsciiGetBytes) the return is not consumed in 
the benchmark, which opens the possibility of a Dead-Code Elimination to be 
performed by JVM. 

*There is a very simple solution:* just return the long primitive calculated by 
_consume()_ at the end of each benchmark. This is done on other benchmarks of 
the project as well.

In our tests, benchmarks were lightly affected (see attachment), with 
Throughputs 5-35% lower after our fix patch. 

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to