fork download
  1. import java.lang.reflect.Field;
  2.  
  3. public class Main {
  4. public static void main(String[] args) throws Exception {
  5. Class usf = Class.forName("sun.misc.Unsafe");
  6. Field unsafeField = usf.getDeclaredField("theUnsafe");
  7. unsafeField.setAccessible(true);
  8. sun.misc.Unsafe unsafe = (sun.misc.Unsafe)unsafeField.get(null);
  9. // Class cache = Class.forName("java.lang.Integer$IntegerCache");
  10. Class cache = Integer.class.getDeclaredClasses()[0];
  11. Field c = cache.getDeclaredField("cache");
  12. Integer[] array = (Integer[])unsafe.getObject(unsafe.staticFieldBase(c), unsafe.staticFieldOffset(c));
  13.  
  14. array[132] = array[133];
  15.  
  16. System.out.printf("%d",2 + 2);
  17. }
  18. }
  19.  
Success #stdin #stdout 0.08s 34344KB
stdin
Standard input is empty
stdout
5