| 3 | import java.lang.reflect.Field; |
| 4 | |
| 5 | interface Unsafe { |
| 6 | |
| 7 | static sun.misc.Unsafe instance = getDeclaredStaticField(sun.misc.Unsafe.class, "theUnsafe"); |
| 8 | |
| 9 | @SuppressWarnings("unchecked") |
| 10 | static <T> T getDeclaredStaticField(final Class<?> cls, final String name) { |
| 11 | try { |
| 12 | final Field f = cls.getDeclaredField(name); |
| 13 | f.setAccessible(true); |
| 14 | return (T) f.get(null); |
| 15 | } catch (final Exception e) { |
| 16 | throw new RuntimeException(e); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | static long objectFieldOffset(final Class<?> cls, final String name) { |
| 21 | try { |
| 22 | return instance.objectFieldOffset(cls.getDeclaredField(name)); |
| 23 | } catch (final Exception e) { |
| 24 | throw new RuntimeException(e); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | static boolean compareAndSwapObject(final Object inst, final long fieldOffset, final Object oldValue, |
| 29 | final Object newValue) { |
| 30 | return instance.compareAndSwapObject(inst, fieldOffset, oldValue, newValue); |
| 31 | } |
| 32 | } |
no test coverage detected
searching dependent graphs…