Last active
May 19, 2021 10:05
-
-
Save juliofalbo/5f3d50f8cd02baa7a33b838204590c3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
public class DeoptimizationExample { | |
public static void main(String[] args) { | |
for (int i = 0; i < 50000; i++) { | |
MyInterface myInterface; | |
if (i < 45000) { | |
// The first 45.000 executions will enter here | |
myInterface = new MyInterfaceImpl(); | |
} else { | |
myInterface = new MyInterfaceLoggerImpl(); | |
} | |
myInterface.addARandomNumber(50); | |
} | |
} | |
} | |
interface MyInterface { | |
void addARandomNumber(double value); | |
} | |
class MyInterfaceImpl implements MyInterface { | |
@Override | |
public void addARandomNumber(double value) { | |
double random = Math.random(); | |
double finalResult = random + value; | |
} | |
} | |
class MyInterfaceLoggerImpl implements MyInterface { | |
@Override | |
public void addARandomNumber(double value) { | |
System.out.println("The value is: " + Math.random() + value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Júlio,
I just want you to ask if it is ok when I use your example on my website https://jitclipse.io/?
In my video I show your source code with you as the author.