Switching to semi-dynamic discovery of sun.misc.Unsafe entity
This commit is contained in:
parent
19347dadbc
commit
69196a998f
1 changed files with 10 additions and 3 deletions
|
|
@ -11,9 +11,16 @@ public final class Unsafe {
|
|||
public final static sun.misc.Unsafe instance;
|
||||
static {
|
||||
try {
|
||||
Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
field.setAccessible(true);
|
||||
instance = (sun.misc.Unsafe) field.get(null);
|
||||
sun.misc.Unsafe found = null;
|
||||
for(Field field : sun.misc.Unsafe.class.getDeclaredFields()) {
|
||||
if (field.getType() == sun.misc.Unsafe.class) {
|
||||
field.setAccessible(true);
|
||||
found = (sun.misc.Unsafe) field.get(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) throw new IllegalStateException("Can't find instance of sun.misc.Unsafe");
|
||||
else instance = found;
|
||||
} catch(Throwable t) {
|
||||
throw new ExceptionInInitializerError(t);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue