sun.misc.Unsafe.getObject()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(316)

本文整理了Java中sun.misc.Unsafe.getObject()方法的一些代码示例,展示了Unsafe.getObject()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.getObject()方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:getObject

Unsafe.getObject介绍

暂无

代码示例

代码示例来源:origin: netty/netty

static Object getObject(Object object, long fieldOffset) {
  return UNSAFE.getObject(object, fieldOffset);
}

代码示例来源:origin: LMAX-Exchange/disruptor

@SuppressWarnings("unchecked")
  protected final E elementAt(long sequence)
  {
    return (E) UNSAFE.getObject(entries, REF_ARRAY_BASE + ((sequence & indexMask) << REF_ELEMENT_SHIFT));
  }
}

代码示例来源:origin: redisson/redisson

static Object getObject(Object object, long fieldOffset) {
  return UNSAFE.getObject(object, fieldOffset);
}

代码示例来源:origin: neo4j/neo4j

public static Object getObject( Object obj, long offset )
{
  return unsafe.getObject( obj, offset );
}

代码示例来源:origin: ben-manes/caffeine

/**
 * A plain load (no ordering/fences) of an element from a given offset.
 *
 * @param buffer this.buffer
 * @param offset computed via {@link UnsafeRefArrayAccess#calcElementOffset(long)}
 * @return the element at the offset
 */
@SuppressWarnings("unchecked")
public static <E> E lpElement(E[] buffer, long offset) {
 return (E) UNSAFE.getObject(buffer, offset);
}

代码示例来源:origin: apache/ignite

/**
 * Gets reference from object field.
 *
 * @param obj Object.
 * @param fieldOff Field offset.
 * @return Reference from object field.
 */
public static Object getObjectField(Object obj, long fieldOff) {
  return UNSAFE.getObject(obj, fieldOff);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Privileged method to get the context class loader of the given thread.
 *
 * @param thread the thread to introspect
 * @return the context class loader
 */
static ClassLoader getContextClassLoader(final Thread thread) {
  return (ClassLoader) unsafe.getObject(thread, contextClassLoaderOffs);
}

代码示例来源:origin: reactor/reactor-core

@SuppressWarnings("unchecked")
  final E elementAt(long sequence)
  {
    return (E) UNSAFE.getObject(entries, REF_ARRAY_BASE + ((sequence & indexMask) << REF_ELEMENT_SHIFT));
  }
}

代码示例来源:origin: JCTools/JCTools

/**
 * A plain load (no ordering/fences) of an element from a given offset.
 *
 * @param buffer this.buffer
 * @param offset computed via {@link UnsafeRefArrayAccess#calcElementOffset(long)}
 * @return the element at the offset
 */
@SuppressWarnings("unchecked")
public static <E> E lpElement(E[] buffer, long offset)
{
  return (E) UNSAFE.getObject(buffer, offset);
}

代码示例来源:origin: JCTools/JCTools

@SuppressWarnings("unchecked")
protected final E lpElement(long offset) {
  return (E) UNSAFE.getObject(buffer, offset);
}

代码示例来源:origin: JCTools/JCTools

@SuppressWarnings("unchecked")
protected final E lpElement(E[] buffer, long offset) {
  return (E) UNSAFE.getObject(buffer, offset);
}

代码示例来源:origin: redisson/redisson

/**
 * Warning: crashes if not an object ref !
 * use getField().get() for a safe version ..
 *
 * @param obj
 * @return
 * @throws IllegalAccessException
 */
public final Object getObjectValue(Object obj) throws IllegalAccessException {
  if (!isAndroid && memOffset >= 0) {
    return FSTUtil.unFlaggedUnsafe.getObject(obj, memOffset);
  }
  return field.get(obj);
}

代码示例来源:origin: com.typesafe.akka/akka-actor

public static void copyUSAsciiStrToBytes(String str, byte[] bytes) {
  if (isJavaVersion9Plus) {
    final byte[] chars = (byte[]) instance.getObject(str, stringValueFieldOffset);
    System.arraycopy(chars, 0, bytes, 0, chars.length);
  } else {
    final char[] chars = (char[]) instance.getObject(str, stringValueFieldOffset);
    int i = 0;
    while (i < str.length()) {
      bytes[i] = (byte) chars[i++];
    }
  }
}

代码示例来源:origin: com.typesafe.akka/akka-actor_2.11

public static void copyUSAsciiStrToBytes(String str, byte[] bytes) {
  if (isJavaVersion9Plus) {
    final byte[] chars = (byte[]) instance.getObject(str, stringValueFieldOffset);
    System.arraycopy(chars, 0, bytes, 0, str.length());
  } else {
    final char[] chars = (char[]) instance.getObject(str, stringValueFieldOffset);
    int i = 0;
    while (i < str.length()) {
      bytes[i] = (byte) chars[i++];
    }
  }
}

代码示例来源:origin: com.typesafe.akka/akka-actor_2.12

public static void copyUSAsciiStrToBytes(String str, byte[] bytes) {
  if (isJavaVersion9Plus) {
    final byte[] chars = (byte[]) instance.getObject(str, stringValueFieldOffset);
    System.arraycopy(chars, 0, bytes, 0, str.length());
  } else {
    final char[] chars = (char[]) instance.getObject(str, stringValueFieldOffset);
    int i = 0;
    while (i < str.length()) {
      bytes[i] = (byte) chars[i++];
    }
  }
}

代码示例来源:origin: groovy/groovy-core

@Override
public char[] toCharArray(String string) {
  char[] value = (char[]) UNSAFE.getObject(string, STRING_VALUE_FIELD_OFFSET);
  int offset = UNSAFE.getInt(string, STRING_OFFSET_FIELD_OFFSET);
  int count = UNSAFE.getInt(string, STRING_COUNT_FIELD_OFFSET);
  if (offset == 0 && count == value.length) {
    // no need to copy
    return value;
  } else {
    return string.toCharArray();
  }
}

代码示例来源:origin: ben-manes/caffeine

@SuppressWarnings("unchecked")
@Nullable Node<E> getNextRelaxed() {
 return (Node<E>) UnsafeAccess.UNSAFE.getObject(this, NEXT_OFFSET);
}

代码示例来源:origin: ben-manes/caffeine

Object getRelaxedObject() {
  return UnsafeAccess.UNSAFE.getObject(this, MoreRelaxedFields.OVALUE_OFFSET);
 }
}

代码示例来源:origin: JCTools/JCTools

@SuppressWarnings("unchecked")
private E getElement(long index) {
  final long offset = offset(index);
  return (E) UnsafeAccess.UNSAFE.getObject(buffer, offset);
}

代码示例来源:origin: JCTools/JCTools

@SuppressWarnings("unchecked")
private E getElement(long index) {
  final long offset = offset(index);
  return (E) UNSAFE.getObject(buffer, offset);
}

相关文章

Unsafe类方法