Java Code Examples for sun.misc.Unsafe#getObject()
The following examples show how to use
sun.misc.Unsafe#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForkJoinWorkerThread.java From a-foundation with Apache License 2.0 | 6 votes |
/** * Returns a new group with the system ThreadGroup (the * topmost, parent-less group) as parent. Uses Unsafe to * traverse Thread.group and ThreadGroup.parent fields. */ private static ThreadGroup createThreadGroup() { try { final Field f = Unsafe.class.getDeclaredField ("theUnsafe"); f.setAccessible (true); Unsafe u = (Unsafe) f.get (null); Class<?> tk = Thread.class; Class<?> gk = ThreadGroup.class; long tg = u.objectFieldOffset(tk.getDeclaredField("group")); long gp = u.objectFieldOffset(gk.getDeclaredField("parent")); ThreadGroup group = (ThreadGroup) u.getObject(Thread.currentThread(), tg); while (group != null) { ThreadGroup parent = (ThreadGroup)u.getObject(group, gp); if (parent == null) return new ThreadGroup(group, "InnocuousForkJoinWorkerThreadGroup"); group = parent; } } catch (Exception e) { throw new Error(e); } // fall through if null as cannot-happen safeguard throw new Error("Cannot create ThreadGroup"); }
Example 2
Source File: Test7190310_unsafe.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static Object getRef2(Unsafe unsafe, Reference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 3
Source File: UnsafeSubstitutionsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("all") public static Object[] unsafePutObject(Unsafe unsafe, Object obj, long offset, Object value1, Object value2, Object value3) { Object[] res = new Object[3]; unsafe.putObject(obj, offset, value1); res[0] = unsafe.getObject(obj, offset); unsafe.putObjectVolatile(obj, offset, value2); res[1] = unsafe.getObject(obj, offset); unsafe.putOrderedObject(obj, offset, value3); res[2] = unsafe.getObject(obj, offset); return res; }
Example 4
Source File: Test7190310_unsafe.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
static Object getRef3(Unsafe unsafe, Object ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 5
Source File: Test7190310_unsafe.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
static Object getRef2(Unsafe unsafe, Reference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 6
Source File: Test7190310_unsafe.java From hottub with GNU General Public License v2.0 | 4 votes |
static Object getRef4(Unsafe unsafe, Test7190310_unsafe ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 7
Source File: Test7190310_unsafe.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
static Object getRef4(Unsafe unsafe, Test7190310_unsafe ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 8
Source File: WriteBarrierAdditionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static Object testUnsafeLoad(Unsafe theUnsafe, Object a, Object b, Object c) throws Exception { final int offset = (c == null ? 0 : ((Integer) c).intValue()); final long displacement = (b == null ? 0 : ((Long) b).longValue()); return theUnsafe.getObject(a, offset + displacement); }
Example 9
Source File: Test7190310_unsafe.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
static Object getRef2(Unsafe unsafe, Reference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 10
Source File: Test7190310_unsafe.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
static Object getRef1(Unsafe unsafe, WeakReference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 11
Source File: Test7190310_unsafe.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
static Object getRef4(Unsafe unsafe, Test7190310_unsafe ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 12
Source File: Test7190310_unsafe.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
static Object getRef2(Unsafe unsafe, Reference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 13
Source File: Test7190310_unsafe.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
static Object getRef4(Unsafe unsafe, Test7190310_unsafe ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 14
Source File: Test7190310_unsafe.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
static Object getRef1(Unsafe unsafe, WeakReference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 15
Source File: Test7190310_unsafe.java From hottub with GNU General Public License v2.0 | 4 votes |
static Object getRef1(Unsafe unsafe, WeakReference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 16
Source File: Test7190310_unsafe.java From hottub with GNU General Public License v2.0 | 4 votes |
static Object getRef3(Unsafe unsafe, Object ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 17
Source File: Test7190310_unsafe.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
static Object getRef3(Unsafe unsafe, Object ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 18
Source File: Test7190310_unsafe.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
static Object getRef3(Unsafe unsafe, Object ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 19
Source File: Test7190310_unsafe.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
static Object getRef1(Unsafe unsafe, WeakReference ref, long referent_offset) throws Exception { return unsafe.getObject(ref, referent_offset); }
Example 20
Source File: BeanAccessor.java From TarsJava with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Object getBeanValue(Object bean, String fieldName) { if (bean == null || fieldName == null) { return null; } Class<?> clazz = bean.getClass(); Map<String, Field> fieldMap = getBeanFieldMap(clazz); Field field = fieldMap.get(fieldName); Unsafe unsafe = getUnsafeInstance(); if (unsafe == null) { try { if (!field.isAccessible()) { field.setAccessible(true); } return field.get(bean); } catch (Exception e) { throw new RuntimeException(e); } } long offset = getBeanFieldOffset(clazz, fieldName); if (offset == -1) { return null; } Class<?> type = field.getType(); if (type == boolean.class) { return unsafe.getBoolean(bean, offset); } else if (type == byte.class) { return unsafe.getByte(bean, offset); } else if (type == short.class) { return unsafe.getShort(bean, offset); } else if (type == char.class) { return unsafe.getChar(bean, offset); } else if (type == int.class) { return unsafe.getInt(bean, offset); } else if (type == long.class) { return unsafe.getLong(bean, offset); } else if (type == float.class) { return unsafe.getFloat(bean, offset); } else if (type == double.class) { return unsafe.getDouble(bean, offset); } return unsafe.getObject(bean, offset); }