Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesleyegberto/5db3de9aaaea163e2414bb881bd6420d to your computer and use it in GitHub Desktop.
Save wesleyegberto/5db3de9aaaea163e2414bb881bd6420d to your computer and use it in GitHub Desktop.
Inconsistency of -Xss and -XX:ThreadStackSize in the java launcher
$ java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
$ java -XX:+PrintFlagsFinal TestThreadStackSize | grep 'intx ThreadStackSize'
intx ThreadStackSize = 1024 {pd product}
$ java -Xss2m -XX:ThreadStackSize=3k -XX:+PrintFlagsFinal TestThreadStackSize | grep 'intx ThreadStackSize'
intx ThreadStackSize := 3072 {pd product}
$ java -XX:ThreadStackSize=3k -Xss2m -XX:+PrintFlagsFinal TestThreadStackSize | grep 'intx ThreadStackSize'
intx ThreadStackSize := 2048 {pd product}
=>0x00007f321801b800 JavaThread "Thread-0" [_thread_in_vm, id=26066, stack(0x00007f321d770000,0x00007f321d871000)]
// 1MB stack + 4KB guard page
0x00000000403ba800 JavaThread "main" [_thread_blocked, id=26053, stack(0x00007f32233e9000,0x00007f32234ea000)]
// 1MB stack + 4KB guard page
=>0x00007fb14801c800 JavaThread "Thread-0" [_thread_in_vm, id=26153, stack(0x00007fb14d490000,0x00007fb14d791000)]
// 3MB stack + 4KB guard page
0x000000004016f800 JavaThread "main" [_thread_blocked, id=26140, stack(0x00007fb153c0a000,0x00007fb153e0b000)]
// 2MB stack + 4KB guard page
=>0x00007f2ea0036800 JavaThread "Thread-0" [_thread_in_vm, id=26171, stack(0x00007f2ea649f000,0x00007f2ea66a0000)]
// 2MB stack + 4KB guard page
0x0000000040edf800 JavaThread "main" [_thread_blocked, id=26158, stack(0x00007f2eac719000,0x00007f2eac91a000)]
// 2MB stack + 4KB guard page
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class TestThreadStackSize {
private static void crashVM() {
try {
makeSegfault(getUnsafe());
} catch (Exception e) {
// swallow
}
}
private static Unsafe getUnsafe() throws Exception {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
}
private static void makeSegfault(Unsafe u) throws Exception {
u.getInt(0);
}
public static void main(String[] args) throws Exception {
Thread t = new Thread(new Runnable() {
public void run() {
crashVM();
}
});
t.start();
t.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment