本文整理汇总了Java中java.lang.invoke.VarHandle类的典型用法代码示例。如果您正苦于以下问题:Java VarHandle类的具体用法?Java VarHandle怎么用?Java VarHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VarHandle类属于java.lang.invoke包,在下文中一共展示了VarHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryOnNext
import java.lang.invoke.VarHandle; //导入依赖的package包/类
public static <T> boolean tryOnNext(ConditionalSubscriber<T> actual, Object target, VarHandle WIP, VarHandle ERRORS, T item) {
if ((int)WIP.getAcquire(target) == 0 && WIP.compareAndSet(target, 0, 1)) {
boolean b = actual.tryOnNext(item);
if (!WIP.compareAndSet(target, 1, 0)) {
Throwable ex = ExceptionHelper.terminate(target, ERRORS);
if (ex == null) {
actual.onComplete();
} else {
actual.onError(ex);
}
return false;
}
return b;
}
return false;
}
示例2: push
import java.lang.invoke.VarHandle; //导入依赖的package包/类
/**
* Pushes a task. Call only by owner in unshared queues.
*
* @param task the task. Caller must ensure non-null.
* @throws RejectedExecutionException if array cannot be resized
*/
final void push(ForkJoinTask<?> task) {
int s = top; ForkJoinTask<?>[] a; int al, d;
if ((a = array) != null && (al = a.length) > 0) {
int index = (al - 1) & s;
ForkJoinPool p = pool;
top = s + 1;
QA.setRelease(a, index, task);
if ((d = base - s) == 0 && p != null) {
VarHandle.fullFence();
p.signalWork();
}
else if (d + al == 1)
growArray();
}
}
示例3: growArray
import java.lang.invoke.VarHandle; //导入依赖的package包/类
/**
* Initializes or doubles the capacity of array. Call either
* by owner or with lock held -- it is OK for base, but not
* top, to move while resizings are in progress.
*/
final ForkJoinTask<?>[] growArray() {
ForkJoinTask<?>[] oldA = array;
int oldSize = oldA != null ? oldA.length : 0;
int size = oldSize > 0 ? oldSize << 1 : INITIAL_QUEUE_CAPACITY;
if (size < INITIAL_QUEUE_CAPACITY || size > MAXIMUM_QUEUE_CAPACITY)
throw new RejectedExecutionException("Queue capacity exceeded");
int oldMask, t, b;
ForkJoinTask<?>[] a = array = new ForkJoinTask<?>[size];
if (oldA != null && (oldMask = oldSize - 1) > 0 &&
(t = top) - (b = base) > 0) {
int mask = size - 1;
do { // emulate poll from old array, push to new array
int index = b & oldMask;
ForkJoinTask<?> x = (ForkJoinTask<?>)
QA.getAcquire(oldA, index);
if (x != null &&
QA.compareAndSet(oldA, index, x, null))
a[b & mask] = x;
} while (++b != t);
VarHandle.releaseFence();
}
return a;
}
示例4: pop
import java.lang.invoke.VarHandle; //导入依赖的package包/类
/**
* Takes next task, if one exists, in LIFO order. Call only
* by owner in unshared queues.
*/
final ForkJoinTask<?> pop() {
int b = base, s = top, al, i; ForkJoinTask<?>[] a;
if ((a = array) != null && b != s && (al = a.length) > 0) {
int index = (al - 1) & --s;
ForkJoinTask<?> t = (ForkJoinTask<?>)
QA.get(a, index);
if (t != null &&
QA.compareAndSet(a, index, t, null)) {
top = s;
VarHandle.releaseFence();
return t;
}
}
return null;
}
示例5: tryConvertToWriteLock
import java.lang.invoke.VarHandle; //导入依赖的package包/类
/**
* If the lock state matches the given stamp, atomically performs one of
* the following actions. If the stamp represents holding a write
* lock, returns it. Or, if a read lock, if the write lock is
* available, releases the read lock and returns a write stamp.
* Or, if an optimistic read, returns a write stamp only if
* immediately available. This method returns zero in all other
* cases.
*
* @param stamp a stamp
* @return a valid write stamp, or zero on failure
*/
public long tryConvertToWriteLock(long stamp) {
long a = stamp & ABITS, m, s, next;
while (((s = state) & SBITS) == (stamp & SBITS)) {
if ((m = s & ABITS) == 0L) {
if (a != 0L)
break;
if ((next = tryWriteLock(s)) != 0L)
return next;
}
else if (m == WBIT) {
if (a != m)
break;
return stamp;
}
else if (m == RUNIT && a != 0L) {
if (casState(s, next = s - RUNIT + WBIT)) {
VarHandle.storeStoreFence();
return next;
}
}
else
break;
}
return 0L;
}
示例6: testInstanceFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
checkUOE(() -> {
vh.set(recv, 0xCAFEBABECAFEBABEL);
});
checkUOE(() -> {
vh.setVolatile(recv, 0xCAFEBABECAFEBABEL);
});
checkUOE(() -> {
vh.setRelease(recv, 0xCAFEBABECAFEBABEL);
});
checkUOE(() -> {
vh.setOpaque(recv, 0xCAFEBABECAFEBABEL);
});
}
示例7: testStaticFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
vh.set(0xCAFEBABECAFEBABEL);
});
checkUOE(() -> {
vh.setVolatile(0xCAFEBABECAFEBABEL);
});
checkUOE(() -> {
vh.setRelease(0xCAFEBABECAFEBABEL);
});
checkUOE(() -> {
vh.setOpaque(0xCAFEBABECAFEBABEL);
});
}
示例8: testInstanceFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
checkUOE(() -> {
vh.set(recv, '\u4567');
});
checkUOE(() -> {
vh.setVolatile(recv, '\u4567');
});
checkUOE(() -> {
vh.setRelease(recv, '\u4567');
});
checkUOE(() -> {
vh.setOpaque(recv, '\u4567');
});
}
示例9: testStaticFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
vh.set('\u4567');
});
checkUOE(() -> {
vh.setVolatile('\u4567');
});
checkUOE(() -> {
vh.setRelease('\u4567');
});
checkUOE(() -> {
vh.setOpaque('\u4567');
});
}
示例10: testStaticFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
vh.set((short)0x4567);
});
checkUOE(() -> {
vh.setVolatile((short)0x4567);
});
checkUOE(() -> {
vh.setRelease((short)0x4567);
});
checkUOE(() -> {
vh.setOpaque((short)0x4567);
});
}
示例11: testStaticFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
vh.set(0x89ABCDEF);
});
checkUOE(() -> {
vh.setVolatile(0x89ABCDEF);
});
checkUOE(() -> {
vh.setRelease(0x89ABCDEF);
});
checkUOE(() -> {
vh.setOpaque(0x89ABCDEF);
});
}
示例12: testInstanceFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
checkUOE(() -> {
vh.set(recv, (byte)0x23);
});
checkUOE(() -> {
vh.setVolatile(recv, (byte)0x23);
});
checkUOE(() -> {
vh.setRelease(recv, (byte)0x23);
});
checkUOE(() -> {
vh.setOpaque(recv, (byte)0x23);
});
}
示例13: testStaticFinalFieldUnsupported
import java.lang.invoke.VarHandle; //导入依赖的package包/类
static void testStaticFinalFieldUnsupported(VarHandle vh) {
checkUOE(() -> {
vh.set((byte)0x23);
});
checkUOE(() -> {
vh.setVolatile((byte)0x23);
});
checkUOE(() -> {
vh.setRelease((byte)0x23);
});
checkUOE(() -> {
vh.setOpaque((byte)0x23);
});
}
示例14: addThrowable
import java.lang.invoke.VarHandle; //导入依赖的package包/类
public static boolean addThrowable(Object target, VarHandle ERRORS, Throwable t) {
for (;;) {
Throwable a = (Throwable) ERRORS.getAcquire(target);
if (a == TERMINATED) {
return false;
}
Throwable b = CompositeThrowable.combine(a, t);
if (ERRORS.compareAndSet(target, a, b)) {
return true;
}
}
}
示例15: testTypes
import java.lang.invoke.VarHandle; //导入依赖的package包/类
@Test(dataProvider = "typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), short.class);
assertEquals(vh.coordinateTypes(), pts);
testTypes(vh);
}