Home > Back-end >  [the JVM] JVM compiler optimization problem
[the JVM] JVM compiler optimization problem

Time:09-16

It is well known that the JVM is a scalar replacement and common subexpression elimination of compiler optimizations,
The theory I this AClass of getNum method should will only once, but why I break point during the debug this method ran twice?
 public class CompileTest {

Public class AClass {
Public int getNum (int I) {
The return of 1024 * 32 * I;
}
}

Public void test () {
AClass AClass=new AClass ();
Int num1=aClass. GetNum (25);
Int num2=aClass. GetNum (25);
}

Public static void main (String [] args) {
CompileTest CompileTest=new CompileTest ();
The (compileTest);
}
}


Scalar replacement, will take AClass getNum method block inline directly to the test method, while the common subexpression elimination should eliminate the code block 1024 * 32 * I, that the code block should be executed once, can recognize for advice on next?
  • Related