Avor Nadal wrote:So I was wondering who far can the JVM go to detect dead code in if-else and switch blocks. Does it only recognise null checks or can it also do comparisons with primitive types? And what about Strings?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ulf Dittmer wrote:All such decisions are liable to be revisited (and possibly reversed) during the JVM runtime due to the data the JVM gathers about code execution, and the analytics it performs on that data.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ulf Dittmer wrote:The JVM gathers statistics about which methods are called how often, and how long their execution takes....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Tim Driven Development | Test until the fear goes away
Winston Gutkowski wrote:The question then becomes one of common sense: Where does the time and complexity required to find a piece of dead code outweigh the value in finding it?
Ulf Dittmer wrote:I'm fairly certain that the JVM would not make optimizations on a sub-method level at runtime. If "doSomethingElse" is not called with any parameter but "C", then the javac compiler could in theory optimize some of the code away. I don't know if it does; but you can check by examining the generated bytecode if you're really interested. See http://www.javaranch.com/journal/200607/ThreadsAndJavap.html for an introduction to using javap for this.
Tim Cooke wrote:All sounds ok right? Wrong. Let's say the queue is quiet and the consumer spins reading null every time from the array slots. After x number of reads (10s or 100s of thousand) the compiler makes a decision that the read calls will never produce anything but null and will inline that code to just null. So now when the producer puts something on the queue, the consumer will never read it.
Avor Nadal wrote:But I had the hope that this type of information had been leaked sometime, as others have ;) .
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Avor Nadal wrote:Have you ever seen that in a real application? Because it would be really serious :O .
Tim Driven Development | Test until the fear goes away