As we know some people say java JIT is faster then C++. I had some idea to utilize JIT and remove some instructions at runtime code.
Here is sample code i tried:
/**
* Created by kadirbasol on 4/6/14.
*/
public class RemoveJump {
public final boolean test;
private static RemoveJump instance = new RemoveJump();
public static final RemoveJump getInstance() {
return instance;
}
private RemoveJump() {
//set the test on the constructor once and
//remove this if statement forever from testLoop
test = false;
}
public final long getData() {
return 1000000000;
}
public final void testLoop() {
long l = System.currentTimeMillis();
int ppp = 0;
long count = System.currentTimeMillis();
final long data = getData();
//this loop should be removed from function because
//RemoveJump set test to false and modified testLoop function
for (int i = 0; i < data ; i++) {
if(test) {
ppp++;
}
if(test) {
ppp++;
}
if(test) {
ppp++;
}
if(test) {
ppp++;
}
if(test) {
ppp++;
}
}
long lastTime = System.currentTimeMillis() - l;
System.out.println(lastTime);
System.out.println(ppp);
}
public static void main(String[] args) {
RemoveJump.getInstance().testLoop();
}
}
there are 5 if statement on the code. Is it possible to remove these 5 check if statements at function ? The constructor will set final boolean variable once and remove the jump. Constructor will modify the testLoop function.
But the code i tried has no effect. JIT is not modifying code ? why ? if not , can we modify JVM function on the constructor? i heard about http://asm.ow2.org , asm java library for generating or modifying JVM.