ADDITIONAL SYSTEM INFORMATION :
OS X + Linux
A DESCRIPTION OF THE PROBLEM :
JitRex creates bytecode in a pre-stackmaps manner. In some cases, this bytecode can crash the JVM.
Example provided later in this form.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Adjust the path to Java in repro.sh to point to 17.0.8 (and possibly others as well).
Run ./repro.sh
JVM will crash - # SIGSEGV (0xb) at pc=0x00000001064e5c10, pid=96307, tid=25347
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JVM should not crash, and executes the bytecode to perform regex matching.
ACTUAL -
JVM crashes:
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00000001064e5c10, pid=96307, tid=25347
---------- BEGIN SOURCE ----------
Requires jitrex 0.1.20.jar
I've also uploaded the .tgz file here: https://filetransfer.io/data-package/rM9xhQMu#link
It should contain 3 files
* jitrex
* repro.sh
* ReproSimple.java
--------- .sh file --------
#!/bin/bash
set -e
LIBS=jitrex-0.1.20.jar
# ADJUST THIS:
JAVA_BIN=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin
JAVA_FLAGS="-Xms2G -Xmx4G -Xss1M -Xlog:jit*=debug:file=./jit_humio.log:time,tags:filecount=5,filesize=1024000"
javac -classpath ${LIBS} ReproSimple.java
${JAVA_BIN}/java -classpath .:${LIBS} ${JAVA_FLAGS} ReproSimple
------ Java File --------
import com.humio.jitrex.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class ReproSimple {
final static String regexPattern = "(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}),(\\S+),(\\S+),(\\S+),(\\S+),(\\S+),(\\S+),(\\S+),(\\S+),(\\S+),(\\S+),(.*)";
public static void main(String[] args) throws InterruptedException {
System.out.println("Starting");
work();
System.out.println("Ended");
}
static void work() {
String[] haystack = new String[] {
"2023-10-01 01:23:46,warn,maccle,Something happened.",
"",
"0".repeat(50)
};
long sum = 0;
for (int iter=1; iter<=100; iter++) {
System.out.print("("+iter+")");
Pattern p = Pattern.compile(regexPattern, 0);
Matcher m = p.matcher("");
for (int k=0; k<haystack.length; k++) {
for (int i=0; i < 1 * 1000 ; i++) {
m.reset(CharSeq.fromString(haystack[k]));
if (m.find()) {
sum += m.start() + m.end();
}
}
}
}
if (sum<0) System.out.println(sum);
}
static class CharSeq implements CharSequence {
ByteBuffer buf;
int start, end;
public static CharSeq fromString(String s) {
CharSeq r = new CharSeq();
r.buf = ByteBuffer.wrap(s.getBytes(StandardCharsets.ISO_8859_1));
r.start = 0;
r.end = r.buf.limit();
return r;
}
public int length() { return end - start; }
public char charAt(int index) {
if (index < 0 || start + index >= end) throw new IndexOutOfBoundsException("" + index);
return (char)(buf.get(start + index) & 0xFF);
}
public CharSequence subSequence(int start, int end) {
throw new UnsupportedOperationException();
}
}
}
---------- END SOURCE ----------
FREQUENCY : always