This class may be removed in the future. Consider the replacements in JEP 193 'Variable Handles': http://openjdk.java.net/jeps/193
static long objectFieldOffset(Field field) { return UNSAFE.objectFieldOffset(field); }
static long objectFieldOffset(Field field) { return UNSAFE.objectFieldOffset(field); }
/** * Returns object field offset. * * @param field Field. * @return Object field offset. */ public static long objectFieldOffset(Field field) { return UNSAFE.objectFieldOffset(field); }
static long objectFieldOffset(Field field) { return UNSAFE.objectFieldOffset(field); }
public UnsafeAccessor(java.lang.reflect.Field f) { super(f); offset = us.objectFieldOffset(f); }
public static int getMinDiff(Class<?> klass) { try { int off1 = (int) U.objectFieldOffset(klass.getDeclaredField("f1")); int off2 = (int) U.objectFieldOffset(klass.getDeclaredField("f2")); int off3 = (int) U.objectFieldOffset(klass.getDeclaredField("f3")); int off4 = (int) U.objectFieldOffset(klass.getDeclaredField("f4")); return MathUtil.minDiff(off1, off2, off3, off4); } catch (NoSuchFieldException e) { throw new IllegalStateException("Infrastructure failure, klass = " + klass, e); } }
UnsafeAtomicReferenceFieldUpdater(Unsafe unsafe, Class<U> tClass, String fieldName) throws NoSuchFieldException { Field field = tClass.getDeclaredField(fieldName); if (!Modifier.isVolatile(field.getModifiers())) { throw new IllegalArgumentException("Must be volatile"); } this.unsafe = unsafe; offset = unsafe.objectFieldOffset(field); }
private static long getProbeOffset() { try { return UNSAFE.objectFieldOffset(Thread.class.getDeclaredField("threadLocalRandomProbe")); } catch (NoSuchFieldException e) { return -1L; } }
/** * Returns the location of a given static field. * * @param clazz the class containing the field * @param fieldName the name of the field * @return the address offset of the field */ public static long objectFieldOffset(Class<?> clazz, String fieldName) { try { return UNSAFE.objectFieldOffset(clazz.getDeclaredField(fieldName)); } catch (NoSuchFieldException | SecurityException e) { throw new Error(e); } }
static Object readField(Field field, final Object obj) { return unsafe.getObject(obj, unsafe.objectFieldOffset(field)); }
private FieldSetter(final Field field) { this.clazz = field.getDeclaringClass(); this.fieldType = field.getType(); fieldOffset = unsafe.objectFieldOffset(field); }
private static int computeOffset(Field field) { if (Modifier.isStatic(field.getModifiers())) { return (int) VMSupport.U.staticFieldOffset(field); } else { return (int) VMSupport.U.objectFieldOffset(field); } }
public static long fieldOffset(Class clz, String fieldName) throws RuntimeException { try { return UNSAFE.objectFieldOffset(clz.getDeclaredField(fieldName)); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } } }
private synchronized long getFieldOffset(Field f) { Long l = (Long)fieldOffsetCache.get(f); if (l == null) { l = new Long(unsafe.objectFieldOffset(f)); fieldOffsetCache.put(f, l); } return l.longValue(); }
/** * Get the object-relative field offset. */ public static long getFieldOffset( Class<?> type, String field ) { try { return unsafe.objectFieldOffset( type.getDeclaredField( field ) ); } catch ( NoSuchFieldException e ) { String message = "Could not get offset of '" + field + "' field on type " + type; throw new LinkageError( message, e ); } }
@Override int headerSize() { try { return (int) UnsafeAccess.theUnsafe.objectFieldOffset( HeaderSize.class.getDeclaredField("a")); } catch (NoSuchFieldException | SecurityException e) { LOG.error(e.toString(), e); } return super.headerSize(); }
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } } }
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } } }
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } }
private static VMOptions getOptions() { // try Hotspot VMOptions hsOpts = getHotspotSpecifics(); if (hsOpts != null) return hsOpts; // try JRockit VMOptions jrOpts = getJRockitSpecifics(); if (jrOpts != null) return jrOpts; // When running with CompressedOops on 64-bit platform, the address size // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. // Try to guess the reference field size with this naive trick. int oopSize; try { long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); oopSize = (int) Math.abs(off2 - off1); } catch (NoSuchFieldException e) { throw new IllegalStateException("Infrastructure failure", e); } if (oopSize != U.addressSize()) { return new VMOptions("Auto-detected", 3); // assume compressed references have << 3 shift } else { return new VMOptions("Auto-detected"); } }