Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.27k
stars
720
forks
source link
JIT: Unsafe putByte/putShort/putChar must narrow store to appropriate size #19207
Methods such as Unsafe.putByte(...), Unsafe.putShort(...) may only store one/two bytes. By loading a 4-byte integer onto the stack and calling Unsafe.putShort(...), the attached application UnsafeSetMethodsTest.tar.gz demonstrates that the JIT incorrectly stores 4 bytes.
public static Method setShort:"(Lsun/misc/Unsafe;Ljava/lang/Object;J)V"
stack 5 locals 4
{
aload_0;
aload_1;
lload_2;
ldc int -2122153084;
invokevirtual Method sun/misc/Unsafe.putShort:"(Ljava/lang/Object;JS)V";
return;
}
The test program shows that the interpreter stores the correct number of bytes, after JIT compilation, a full 4 bytes are stored.
$ java -Xjit:count=1,disableAsyncCompilation TestUnsafe
Values in o1
i == -2122153084
s == -31868
c == 33668
b == -124
Values in o2
i == -2122153084
s == -2122153084
c == -2122153084
b == -2122153084
Summary of problem
Methods such as Unsafe.putByte(...), Unsafe.putShort(...) may only store one/two bytes. By loading a 4-byte integer onto the stack and calling Unsafe.putShort(...), the attached application UnsafeSetMethodsTest.tar.gz demonstrates that the JIT incorrectly stores 4 bytes.
The test program shows that the interpreter stores the correct number of bytes, after JIT compilation, a full 4 bytes are stored.