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

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

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

Unsafe.getAndSetObject介绍

[英]Atomically exchanges the given reference value with the current reference value of a field or array element within the given object o at the given offset.
[中]在给定的offset位置,将给定的参考值与给定对象o中的字段或数组元素的当前参考值进行原子交换。

代码示例

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

/**
 * Atomically return the current object reference value, and exchange it with the given new reference value.
 */
public static Object getAndSetObject( Object obj, long offset, Object newValue )
{
  return unsafe.getAndSetObject( obj, offset, newValue );
}

代码示例来源:origin: real-logic/agrona

@SuppressWarnings("unchecked")
private Node<E> swapTail(final Node<E> newTail)
{
  return (Node<E>)UNSAFE.getAndSetObject(this, TAIL_OFFSET, newTail);
}

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

@SuppressWarnings("unchecked")
  protected final LinkedQueueNode<E> xchgProducerNode(LinkedQueueNode<E> newVal)
  {
    return (LinkedQueueNode<E>) UNSAFE.getAndSetObject(this, P_NODE_OFFSET, newVal);
  }
}

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

protected final Node xchgProducerNode(Node node) {
    // TODO: add support for JDK < 8 per org.jctools.queues.MpscLinkedQueue / MpscLinkedQueue8
    return (Node) UNSAFE.getAndSetObject(this, P_NODE_OFFSET, node);
  }
}

代码示例来源:origin: org.agrona/Agrona

@SuppressWarnings("unchecked")
private Node<E> swapTail(final Node<E> newTail)
{
  return (Node<E>)UNSAFE.getAndSetObject(this, TAIL_OFFSET, newTail);
}

代码示例来源:origin: uk.co.real-logic/Agrona

@SuppressWarnings("unchecked")
  private Node<E> swapTail(final Node<E> newTail)
  {
    return (Node<E>)UNSAFE.getAndSetObject(this, TAIL_OFFSET, newTail);
  }
}

代码示例来源:origin: org.sincron/sincron-atomic

public Object getAndSet(Object update) {
    return UnsafeAccess.UNSAFE.getAndSetObject(this, OFFSET, update);
  }
}

代码示例来源:origin: io.snappydata/gemfire-core

/**
  * {@inheritDoc}
  */
 @SuppressWarnings("unchecked")
 @Override
 public final V getAndSet(T obj, V newValue) {
  return (V)unsafe.getAndSetObject(obj, offset, newValue);
 }
}

代码示例来源:origin: serkan-ozal/mysafe

@Override
public Object getAndSetObject(Unsafe unsafe, Object o, long offset, Object newValue) {
  return unsafe.getAndSetObject(o, offset, newValue);
}

代码示例来源:origin: org.jctools/jctools-core

@SuppressWarnings("unchecked")
  protected final LinkedQueueNode<E> xchgProducerNode(LinkedQueueNode<E> newVal)
  {
    return (LinkedQueueNode<E>) UNSAFE.getAndSetObject(this, P_NODE_OFFSET, newVal);
  }
}

代码示例来源:origin: org.agrona/agrona

@SuppressWarnings("unchecked")
private Node<E> swapTail(final Node<E> newTail)
{
  return (Node<E>)UNSAFE.getAndSetObject(this, TAIL_OFFSET, newTail);
}

代码示例来源:origin: org.neo4j/neo4j-unsafe

/**
 * Atomically return the current object reference value, and exchange it with the given new reference value.
 */
public static Object getAndSetObject( Object obj, long offset, Object newValue )
{
  return unsafe.getAndSetObject( obj, offset, newValue );
}

代码示例来源:origin: org.sincron/sincron-atomic

public Object getAndSet(Object update) {
    return UnsafeAccess.UNSAFE.getAndSetObject(this, OFFSET, update);
  }
}

代码示例来源:origin: org.sincron/sincron-atomic

public Object getAndSet(Object update) {
    return UnsafeAccess.UNSAFE.getAndSetObject(this, OFFSET, update);
  }
}

代码示例来源:origin: zeebe-io/zeebe

private ActorTaskQueueNode swapTail(final ActorTaskQueueNode newTail) {
 return (ActorTaskQueueNode) UNSAFE.getAndSetObject(this, TAIL_OFFSET, newTail);
}

代码示例来源:origin: io.zeebe/zb-util

private ActorTaskQueueNode swapTail(final ActorTaskQueueNode newTail) {
 return (ActorTaskQueueNode) UNSAFE.getAndSetObject(this, TAIL_OFFSET, newTail);
}

代码示例来源:origin: org.sincron/sincron-atomic

public Object getAndSet(Object update) {
    return UnsafeAccess.UNSAFE.getAndSetObject(this, OFFSET, update);
  }
}

代码示例来源:origin: org.sincron/sincron-atomic

public Object getAndSet(Object update) {
    return UnsafeAccess.UNSAFE.getAndSetObject(this, OFFSET, update);
  }
}

代码示例来源:origin: org.sincron/sincron-atomic

public Object getAndSet(Object update) {
    return UnsafeAccess.UNSAFE.getAndSetObject(this, OFFSET, update);
  }
}

代码示例来源:origin: com.oracle.substratevm/svm

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
  @SuppressWarnings("unchecked")
  public final T getAndSet(T newValue) {
    return (T) UnsafeAccess.UNSAFE.getAndSetObject(this, VALUE_OFFSET, newValue);
  }
}

相关文章

Unsafe类方法