MCPcopy Create free account
hub / github.com/traneio/future / Unsafe

Interface Unsafe

future-java/src/main/java/io/trane/future/Unsafe.java:5–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import java.lang.reflect.Field;
4
5interface 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}

Callers 7

unsafeInstanceMethod · 0.95
UnsafeInterface · 0.95
objectFieldOffsetMethod · 0.95
PromiseClass · 0.95
casMethod · 0.95

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…