fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import sun.misc.Unsafe;
  8. import java.lang.reflect.Constructor;
  9. import java.lang.reflect.InvocationTargetException;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. new Accessor().run();
  17. }
  18. }
  19.  
  20. class Data{
  21. int x = 0;
  22. }
  23.  
  24. class Accessor{
  25. private Data data;
  26. private Object base;
  27. private long off;
  28. public static final Unsafe unsafe;
  29.  
  30. public void run(){
  31. data = new Data();
  32.  
  33. base = data;
  34. off = 12;
  35.  
  36. unsafe.putInt(base,off,1);
  37. assert(data.x == 1);
  38. }
  39.  
  40. static{
  41. try {
  42. Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor();
  43. unsafeConstructor.setAccessible(true);
  44. unsafe = unsafeConstructor.newInstance();
  45. throw new RuntimeException(e);
  46. }
  47. }
  48. }
  49.  
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty