Created
January 18, 2023 01:00
-
-
Save navyxliu/1ded3fcd2f1563f290362cf03c9d13dc to your computer and use it in GitHub Desktop.
Example3.java
This file contains hidden or 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
// from ResourceScopeCloseMin.java | |
// https://bugs.openjdk.org/browse/JDK-8267532 | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
public class Example3 { | |
Runnable dummy = () -> {}; | |
static class ConfinedScope { | |
final Thread owner; | |
boolean closed; | |
final List<Runnable> resources = new ArrayList<>(); | |
private void checkState() { | |
if (closed) { | |
throw new AssertionError("Closed"); | |
} else if (owner != Thread.currentThread()) { | |
throw new AssertionError("Wrong thread"); | |
} | |
} | |
ConfinedScope() { | |
this.owner = Thread.currentThread(); | |
} | |
void addCloseAction(Runnable runnable) { | |
checkState(); | |
resources.add(runnable); | |
} | |
public void close() { | |
checkState(); | |
closed = true; | |
for (Runnable r : resources) { | |
r.run(); | |
} | |
} | |
} | |
public void confined_close() { | |
ConfinedScope scope = new ConfinedScope(); | |
try { // simulate TWR | |
scope.addCloseAction(dummy); | |
scope.close(); | |
} catch (RuntimeException ex) { | |
scope.close(); | |
throw ex; | |
} | |
} | |
public static void main(String[] args) { | |
var kase = new Example3(); | |
while (true) { | |
kase.confined_close(); | |
} | |
} | |
} |
Author
navyxliu
commented
Jan 18, 2023
java '-XX:CompileCommand=CompileOnly,Example3::confined_close' -XX:CompileCommand=quiet -XX:-UseOnStackReplacement -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UseTLAB -Xms64M -Xmx64M -XX:-PrintOptoAssembly -XX:+PrintInlining -XX:+PrintEscapeAnalysis -XX:+PrintEliminateAllocations -XX:-TieredCompilation -XX:+PrintCompilation -XX:+DoPartialEscapeAnalysis -XX:+Verbose Example3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment