Skip to content

Instantly share code, notes, and snippets.

@navyxliu
Last active April 17, 2020 22:11
Show Gist options
  • Save navyxliu/6df98f8dfef948ca2b3ea428794faa75 to your computer and use it in GitHub Desktop.
Save navyxliu/6df98f8dfef948ca2b3ea428794faa75 to your computer and use it in GitHub Desktop.
intrinsic _getInt nullifies the unsafe access
$cat TestHaltNode.java
import jdk.internal.misc.Unsafe;
public class TestHaltNode {
static final Unsafe UNSAFE = Unsafe.getUnsafe();
static boolean f;
static int address;
private static int getAddress() {
return address;
}
public static void test3() {
if (f) {
UNSAFE.getInt(getAddress());
}
}
public static void test4() {
if (f) {
UNSAFE.putInt(getAddress(), 0);
}
}
public static void stringCompareTo(String a, String b) {
}
static public void main(String[] args) {
test3();
f = true;
test3();
}
}
cat t.sh
javac --add-exports java.base/jdk.internal.misc=ALL-UNNAMED TestHaltNode.java
java -XX:+UnlockDiagnosticVMOptions $* -XX:CompileCommand=compileonly,TestHaltNode::* --add-exports java.base/jdk.internal.misc=ALL-UNNAMED -XX:-TieredCompilation -XX:+PrintCompilation -XX:+PrintInlining -cp . TestHaltNode |& grep -v "### Excluding compile" |grep -v "made not compilable on level" | grep -v "### Excluding generation of native wrapper"
if you invoke t.sh with -Xint or -Xcomp -XX:DisableIntrinis=_getInt, the hotspot will crash.
if you invoke t.sh with -Xcomp, because UNSAFE.getInt will be treated as intrinsic _getInt, nothing will happen. We expect to hit a HaltNode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment