本文整理了Java中sun.misc.Unsafe.objectFieldOffset()
方法的一些代码示例,展示了Unsafe.objectFieldOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.objectFieldOffset()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:objectFieldOffset
[英]Gets the raw byte offset from the start of an object's memory to the memory used to store the indicated instance field.
[中]获取从对象内存开始到用于存储指定实例字段的内存的原始字节偏移量。
代码示例来源:origin: netty/netty
static long objectFieldOffset(Field field) {
return UNSAFE.objectFieldOffset(field);
}
代码示例来源:origin: redisson/redisson
static long objectFieldOffset(Field field) {
return UNSAFE.objectFieldOffset(field);
}
代码示例来源:origin: apache/ignite
/**
* Returns object field offset.
*
* @param field Field.
* @return Object field offset.
*/
public static long objectFieldOffset(Field field) {
return UNSAFE.objectFieldOffset(field);
}
代码示例来源:origin: wildfly/wildfly
static long objectFieldOffset(Field field) {
return UNSAFE.objectFieldOffset(field);
}
代码示例来源:origin: protostuff/protostuff
public UnsafeAccessor(java.lang.reflect.Field f)
{
super(f);
offset = us.objectFieldOffset(f);
}
代码示例来源:origin: prestodb/presto
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);
}
}
代码示例来源:origin: redisson/redisson
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);
}
代码示例来源:origin: JCTools/JCTools
private static long getProbeOffset() {
try {
return UNSAFE.objectFieldOffset(Thread.class.getDeclaredField("threadLocalRandomProbe"));
} catch (NoSuchFieldException e) {
return -1L;
}
}
代码示例来源:origin: ben-manes/caffeine
/**
* 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);
}
}
代码示例来源:origin: wildfly/wildfly
static Object readField(Field field, final Object obj) {
return unsafe.getObject(obj, unsafe.objectFieldOffset(field));
}
代码示例来源:origin: wildfly/wildfly
private FieldSetter(final Field field) {
this.clazz = field.getDeclaringClass();
this.fieldType = field.getType();
fieldOffset = unsafe.objectFieldOffset(field);
}
代码示例来源:origin: prestodb/presto
private static int computeOffset(Field field) {
if (Modifier.isStatic(field.getModifiers())) {
return (int) VMSupport.U.staticFieldOffset(field);
} else {
return (int) VMSupport.U.objectFieldOffset(field);
}
}
代码示例来源:origin: JCTools/JCTools
public static long fieldOffset(Class clz, String fieldName) throws RuntimeException
{
try
{
return UNSAFE.objectFieldOffset(clz.getDeclaredField(fieldName));
}
catch (NoSuchFieldException e)
{
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
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();
}
代码示例来源:origin: neo4j/neo4j
/**
* 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 );
}
}
代码示例来源:origin: apache/hbase
@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();
}
代码示例来源:origin: robovm/robovm
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;
}
}
}
代码示例来源:origin: robovm/robovm
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;
}
}
}
代码示例来源:origin: robovm/robovm
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;
}
}
代码示例来源:origin: prestodb/presto
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");
}
}
内容来源于网络,如有侵权,请联系作者删除!