jvm - Please explain Hotspot optimization refactor from Preconditions.java in guava code base? -


i going through guava code base , in preconditions source there explanation quoted below:

all recent hotspots (as of 2009) really have natural code

if (guardexpression) {   throw new badexception(messageexpression); } 

refactored messageexpression moved separate string-returning method.

if (guardexpression) {    throw new badexception(badmsg(...)); } 

the alternative natural refactorings void or exception-returning methods slower. big deal - we're talking factors of 2-8 in microbenchmarks, not 10-20%. (this hotspot optimizer bug, should fixed, that's separate, big project).

the coding pattern above heavily used in java.util, e.g. in arraylist. there rangecheckmicrobenchmark in jdk used test this.

but methods in class want throw different exceptions, depending on args, appears pattern not directly applicable. can use ridiculous, devious trick of throwing exception in middle of construction of exception. hotspot fine that.

for jvm(s) applicable? why slow, cant understand? implies me developer? still applicable java8 jvms oracle , openjdk? how take advantage of piece of information while writing code?


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -