Created
October 24, 2023 21:49
-
-
Save navyxliu/dc69de73231d9eb71eff4c15966e76ff to your computer and use it in GitHub Desktop.
RelockInDeopt.java
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
// java -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,RelockInDeopt::snippet2 -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:+PrintCompilation -XX:+TraceDeoptimization -XX:+PrintEliminateLocks -XX:+PrintDeoptimizationDetails -XX:-PrintInlining -Xbatch -XX:+PrintEliminateAllocations RelockInDeopt | |
class RelockInDeopt { | |
static int staticInt = 0; | |
static Object staticObj = null; | |
public static void snippet2() { | |
Object escaped = new Object(); | |
Object nonEscaped = new Object(); | |
synchronized (nonEscaped) { | |
synchronized (escaped) { | |
staticObj = escaped; | |
staticInt++; | |
if (staticInt >= 9_999) { | |
staticObj = null; // deoptimize | |
} | |
} | |
} | |
} | |
public static void main(String[] args) { | |
var kase = new RelockInDeopt(); | |
for (int i = 0; i < 10_000; ++i) { | |
snippet2(); | |
} | |
} | |
} |
Author
navyxliu
commented
Oct 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment