optimization - Does java optimize multiple logical "not" ot "not equal" in different Methods? -


lets @ example codes following(modified have private fields):

 public class stupidnot{  private object a,b;  ...  public boolean notequal(){        return a!= b;  } }  public class anotherstupidnot{  private stupidnot sn;  private whatever obj;   public boolean anothernotequal(){        return  ! sn.notequal() && obj.someboolean()  } } 

... etc, idea if jvm or compiler optimizes multiple "not"'s , located in different methods?

this not optimized javac, can optimized jit compiler if knows stupidnot.notequal never overridden in loaded subclasses of stupidnot (if any). notequal inlined anothernotequal , after inlining optimization performed.

if stupidnot class has subclasses , of them override notequal method, it's still possible jit compiler optimizes case based on type profile (if it's known, example, in of cases using stupidnot class , not using subclasses). in case jit-compiler add quick type check anothernotequal method (if succeed) use inlined notequal , otherwise use slow virtual call.

also don't forget anothernotequal inlined other method it's quite simple.


Comments