forked from coderplay/javaopt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnsafeAccess.java
More file actions
24 lines (20 loc) · 569 Bytes
/
UnsafeAccess.java
File metadata and controls
24 lines (20 loc) · 569 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package javaopt.queue;
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class UnsafeAccess {
public static final Unsafe unsafe;
static {
try {
// This is a bit of voodoo to force the unsafe object into
// visibility and acquire it.
// This is not playing nice, but as an established back door it is
// not likely to be
// taken away.
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
unsafe = (Unsafe) field.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}