Skip to content

Instantly share code, notes, and snippets.

@navyxliu
Created January 18, 2023 01:00
Show Gist options
  • Save navyxliu/1ded3fcd2f1563f290362cf03c9d13dc to your computer and use it in GitHub Desktop.
Save navyxliu/1ded3fcd2f1563f290362cf03c9d13dc to your computer and use it in GitHub Desktop.
Example3.java
// 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();
}
}
}
@navyxliu
Copy link
Author

Example3_ex_handler

@navyxliu
Copy link
Author

@navyxliu
Copy link
Author

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