The following program hangs in >50% cases within 100 seconds. It looks like a livelock (Java process consumes 100% of one CPU core).
In rare cases, JVM crashes at a random place instead of a livelock.
It's important to notice that the issue is observed only on the emulated CPU, i.e. when running x64 JVM on ARM64 hardware under Rosetta. The program works fine on linux-x64 JVM and on macos-aarch64 JVM. There is a chance of a Rosetta bug, however, I've seen no issues if JFR recording is not enabled.
Command:
java -Xlog:gc JfrHang
--- JfrHang.java ---
import jdk.jfr.Configuration;
import jdk.jfr.Recording;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class JfrHang {
public static void main(String[] args) throws Exception {
Recording recording = new Recording(Configuration.getConfiguration("profile"));
recording.start();
for (int i = 0; i < 5; i++) {
new Thread(() -> {
List<Object> list = new ArrayList<>();
while (true) {
loop(list);
}
}).start();
}
}
private static void loop(List<Object> list) {
switch (ThreadLocalRandom.current().nextInt(8)) {
case 0:
list.add(java.time.LocalDateTime.now());
break;
case 1:
list.add(System.nanoTime());
break;
case 2:
list.add(String.format("%s %d", "fmt", 123));
break;
case 3:
list.add(list.size());
break;
case 7:
list.clear();
break;
}
}
}
JDK version:
OpenJDK 64-Bit Server VM (19+36-2238) for bsd-amd64 JRE (19+36-2238), built on 2022-08-12T20:29:01Z by "mach5one" with clang Apple LLVM 12.0.0 (clang-1200.0.32.29)
JDK 17.0.2 also had the same issue.
The bug occurs in C1 (-XX:TieredStopAtLevel=1), C2 (-XX:-TieredCompilation) and Mixed modes, but not in -Xint.
In rare cases, JVM crashes at a random place instead of a livelock.
It's important to notice that the issue is observed only on the emulated CPU, i.e. when running x64 JVM on ARM64 hardware under Rosetta. The program works fine on linux-x64 JVM and on macos-aarch64 JVM. There is a chance of a Rosetta bug, however, I've seen no issues if JFR recording is not enabled.
Command:
java -Xlog:gc JfrHang
--- JfrHang.java ---
import jdk.jfr.Configuration;
import jdk.jfr.Recording;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class JfrHang {
public static void main(String[] args) throws Exception {
Recording recording = new Recording(Configuration.getConfiguration("profile"));
recording.start();
for (int i = 0; i < 5; i++) {
new Thread(() -> {
List<Object> list = new ArrayList<>();
while (true) {
loop(list);
}
}).start();
}
}
private static void loop(List<Object> list) {
switch (ThreadLocalRandom.current().nextInt(8)) {
case 0:
list.add(java.time.LocalDateTime.now());
break;
case 1:
list.add(System.nanoTime());
break;
case 2:
list.add(String.format("%s %d", "fmt", 123));
break;
case 3:
list.add(list.size());
break;
case 7:
list.clear();
break;
}
}
}
JDK version:
OpenJDK 64-Bit Server VM (19+36-2238) for bsd-amd64 JRE (19+36-2238), built on 2022-08-12T20:29:01Z by "mach5one" with clang Apple LLVM 12.0.0 (clang-1200.0.32.29)
JDK 17.0.2 also had the same issue.
The bug occurs in C1 (-XX:TieredStopAtLevel=1), C2 (-XX:-TieredCompilation) and Mixed modes, but not in -Xint.