Does any Java compiler or JVM ignore a statement for optimization? -



Does any Java compiler or JVM ignore a statement for optimization? -

suppose have next statement

arraylist.size();

this statement in nothing. java compiler or jvm ignore statement optimization purposes?

in effect, compiler or jvm assumes there no side effects of statement , hence removes optimization.

as stated in comments, it's not no-op: @ least, must perform null check. moreover, there may subclasses of arraylist working differently. in theory, fetch info database or alike. normally, nobody subclass arraylist doing this, such list implementation makes sense.

the compiler (jit, not javac) must able prove it's side-effect free. usually, it's quite simple as

it knows, if there overriden implementation of arraylist.size().1 if there none, sees it's simple getter , inlines it.23 this reduces problem useless field load, gets reduces null check. the null check can eliminated too, if performed before (e.g., due previous useless statement :d). otherwise, can moved out of loop, if arraylist loop invariant.

will java compiler or jvm ignore statement optimization purposes?

so i'd conclude it's quite probable happen.

1 may alter later such class gets loaded , deoptimization take place. 2 assuming decides it's worth optimizing. 3 may fail, if method on inlining limit, e.g., due bad coding style or because of other inlining.

java optimization

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -