4 ms·
log.debug(“foo count: “ + fooHandler.incrementAndReturnFooCount()); Should the JIT call incrementAndReturnFooCount if debug logs are disabled? This is a long
by hamburglar 5y ago
log.debug(“foo count: “ + fooHandler.incrementAndReturnFooCount());
Should the JIT call incrementAndReturnFooCount if debug logs are disabled? This is a long-recognized pitfall of C preprocessor macros that look like function calls but may simply be defined away, causing unexpected behavior.
- akvadrako 5y agoIt should call it if it has side effects, otherwise not. Java isn't C; the runtime can be a lot smarter.
- hamburglar 5y agoI guess I’m not up on the state of the art with respect to the JRE’s ability to determine whether arbitrary code has side effects. That’s quite a broad problem. If I write fizzbuzz but use log.debug for output, does it optimize my main() to be empty unless I run it with debug enabled?