Java 类java.lang.invoke.VarHandle 实例源码

项目:Reactive4JavaFlow    文件:HalfSerializer.java   
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;
}
项目:openjdk-jdk10    文件:ForkJoinPool.java   
/**
 * 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();
    }
}
项目:openjdk-jdk10    文件:ForkJoinPool.java   
/**
 * 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;
}
项目:openjdk-jdk10    文件:ForkJoinPool.java   
/**
 * 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;
}
项目:openjdk-jdk10    文件:StampedLock.java   
/**
 * 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;
}
项目:openjdk-jdk10    文件:VarHandleTestAccessLong.java   
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);
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessLong.java   
static void testStaticFinalFieldUnsupported(VarHandle vh) {
    checkUOE(() -> {
        vh.set(0xCAFEBABECAFEBABEL);
    });

    checkUOE(() -> {
        vh.setVolatile(0xCAFEBABECAFEBABEL);
    });

    checkUOE(() -> {
        vh.setRelease(0xCAFEBABECAFEBABEL);
    });

    checkUOE(() -> {
        vh.setOpaque(0xCAFEBABECAFEBABEL);
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessChar.java   
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');
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessChar.java   
static void testStaticFinalFieldUnsupported(VarHandle vh) {
    checkUOE(() -> {
        vh.set('\u4567');
    });

    checkUOE(() -> {
        vh.setVolatile('\u4567');
    });

    checkUOE(() -> {
        vh.setRelease('\u4567');
    });

    checkUOE(() -> {
        vh.setOpaque('\u4567');
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessShort.java   
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);
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessInt.java   
static void testStaticFinalFieldUnsupported(VarHandle vh) {
    checkUOE(() -> {
        vh.set(0x89ABCDEF);
    });

    checkUOE(() -> {
        vh.setVolatile(0x89ABCDEF);
    });

    checkUOE(() -> {
        vh.setRelease(0x89ABCDEF);
    });

    checkUOE(() -> {
        vh.setOpaque(0x89ABCDEF);
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessByte.java   
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);
    });



}
项目:openjdk-jdk10    文件:VarHandleTestAccessByte.java   
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);
    });



}
项目:Reactive4JavaFlow    文件:ExceptionHelper.java   
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;
        }
    }
}
项目:openjdk-jdk10    文件:VarHandleTestByteArrayAsShort.java   
@Test(dataProvider = "typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
    assertEquals(vh.varType(), short.class);

    assertEquals(vh.coordinateTypes(), pts);

    testTypes(vh);
}
项目:Reactive4JavaFlow    文件:HalfSerializer.java   
public static <T> void onNext(Flow.Subscriber<T> actual, Object target, VarHandle WIP, VarHandle ERRORS, T item) {
    if ((int)WIP.getAcquire(target) == 0 && WIP.compareAndSet(target, 0, 1)) {
        actual.onNext(item);
        if (!WIP.compareAndSet(target, 1, 0)) {
            Throwable ex = ExceptionHelper.terminate(target, ERRORS);
            if (ex == null) {
                actual.onComplete();
            } else {
                actual.onError(ex);
            }
        }
    }
}
项目:Reactive4JavaFlow    文件:HalfSerializer.java   
public static void onError(Flow.Subscriber<?> actual, Object target, VarHandle WIP, VarHandle ERRORS, Throwable t) {
    if (ExceptionHelper.addThrowable(target, ERRORS, t)) {
        if ((int) WIP.getAndAdd(target, 1) == 0) {
            Throwable ex = ExceptionHelper.terminate(target, ERRORS);
            actual.onError(ex);
            return;
        }
    }
    FolyamPlugins.onError(t);
}
项目:Java-9-Concurrency-Cookbook-Second-Edition    文件:Incrementer.java   
@Override
public void run() {
    VarHandle handler;
    try {
        handler = MethodHandles.lookup().in(Account.class).findVarHandle(Account.class, "amount", double.class);
        for (int i = 0; i < 10000; i++) {
            handler.getAndAdd(account, 100);
            account.unsafeAmount += 100;
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }

}
项目:Java-9-Concurrency-Cookbook-Second-Edition    文件:Decrementer.java   
@Override
public void run() {
    VarHandle handler;
    try {
        handler = MethodHandles.lookup().in(Account.class).findVarHandle(Account.class, "amount", double.class);
        for (int i = 0; i < 10000; i++) {
            handler.getAndAdd(account, -100);
            account.unsafeAmount -= 100;
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
项目:openjdk-jdk10    文件:ForkJoinPool.java   
/**
 * Pops the given task only if it is at the current top.
 */
final boolean tryUnpush(ForkJoinTask<?> task) {
    int b = base, s = top, al; ForkJoinTask<?>[] a;
    if ((a = array) != null && b != s && (al = a.length) > 0) {
        int index = (al - 1) & --s;
        if (QA.compareAndSet(a, index, task, null)) {
            top = s;
            VarHandle.releaseFence();
            return true;
        }
    }
    return false;
}
项目:openjdk-jdk10    文件:VarHandleTestByteArrayAsChar.java   
@Test(dataProvider = "typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
    assertEquals(vh.varType(), char.class);

    assertEquals(vh.coordinateTypes(), pts);

    testTypes(vh);
}
项目:openjdk-jdk10    文件:ForkJoinPool.java   
/**
 * If present, removes task from queue and executes it.
 */
final void tryRemoveAndExec(ForkJoinTask<?> task) {
    ForkJoinTask<?>[] wa; int s, wal;
    if (base - (s = top) < 0 && // traverse from top
        (wa = array) != null && (wal = wa.length) > 0) {
        for (int m = wal - 1, ns = s - 1, i = ns; ; --i) {
            int index = i & m;
            ForkJoinTask<?> t = (ForkJoinTask<?>)
                QA.get(wa, index);
            if (t == null)
                break;
            else if (t == task) {
                if (QA.compareAndSet(wa, index, t, null)) {
                    top = ns;   // safely shift down
                    for (int j = i; j != ns; ++j) {
                        ForkJoinTask<?> f;
                        int pindex = (j + 1) & m;
                        f = (ForkJoinTask<?>)QA.get(wa, pindex);
                        QA.setVolatile(wa, pindex, null);
                        int jindex = j & m;
                        QA.setRelease(wa, jindex, f);
                    }
                    VarHandle.releaseFence();
                    t.doExec();
                }
                break;
            }
        }
    }
}
项目:openjdk-jdk10    文件:ForkJoinPool.java   
/**
 * Tries to steal and run tasks within the target's
 * computation until done, not found, or limit exceeded.
 *
 * @param task root of CountedCompleter computation
 * @param limit max runs, or zero for no limit
 * @return task status on exit
 */
final int localHelpCC(CountedCompleter<?> task, int limit) {
    int status = 0;
    if (task != null && (status = task.status) >= 0) {
        for (;;) {
            boolean help = false;
            int b = base, s = top, al; ForkJoinTask<?>[] a;
            if ((a = array) != null && b != s && (al = a.length) > 0) {
                int index = (al - 1) & (s - 1);
                ForkJoinTask<?> o = (ForkJoinTask<?>)
                    QA.get(a, index);
                if (o instanceof CountedCompleter) {
                    CountedCompleter<?> t = (CountedCompleter<?>)o;
                    for (CountedCompleter<?> f = t;;) {
                        if (f != task) {
                            if ((f = f.completer) == null) // try parent
                                break;
                        }
                        else {
                            if (QA.compareAndSet(a, index, t, null)) {
                                top = s - 1;
                                VarHandle.releaseFence();
                                t.doExec();
                                help = true;
                            }
                            break;
                        }
                    }
                }
            }
            if ((status = task.status) < 0 || !help ||
                (limit != 0 && --limit == 0))
                break;
        }
    }
    return status;
}
项目:openjdk-jdk10    文件:StampedLock.java   
private long tryWriteLock(long s) {
    // assert (s & ABITS) == 0L;
    long next;
    if (casState(s, next = s | WBIT)) {
        VarHandle.storeStoreFence();
        return next;
    }
    return 0L;
}
项目:openjdk-jdk10    文件:StampedLock.java   
/**
 * If the lock state matches the given stamp then, atomically, if the stamp
 * represents holding a lock, releases it and returns an
 * observation stamp.  Or, if an optimistic read, returns it if
 * validated. This method returns zero in all other cases, and so
 * may be useful as a form of "tryUnlock".
 *
 * @param stamp a stamp
 * @return a valid optimistic read stamp, or zero on failure
 */
public long tryConvertToOptimisticRead(long stamp) {
    long a, m, s, next; WNode h;
    VarHandle.acquireFence();
    while (((s = state) & SBITS) == (stamp & SBITS)) {
        if ((a = stamp & ABITS) >= WBIT) {
            // write stamp
            if (s != stamp)
                break;
            return unlockWriteInternal(s);
        }
        else if (a == 0L)
            // already an optimistic read stamp
            return stamp;
        else if ((m = s & ABITS) == 0L) // invalid read stamp
            break;
        else if (m < RFULL) {
            if (casState(s, next = s - RUNIT)) {
                if (m == RUNIT && (h = whead) != null && h.status != 0)
                    release(h);
                return next & SBITS;
            }
        }
        else if ((next = tryDecReaderOverflow(s)) != 0L)
            return next & SBITS;
    }
    return 0L;
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
TestAccessMode(TestAccessType at) {
    this.at = at;

    try {
        VarHandle.AccessMode vh_am = toAccessMode();
        Method m = VarHandle.class.getMethod(vh_am.methodName(), Object[].class);
        this.returnType = m.getReturnType();
        isPolyMorphicInReturnType = returnType != Object.class;
    }
    catch (Exception e) {
        throw new Error(e);
    }
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
static List<VarHandle.AccessMode> accessModesOfType(TestAccessType... ats) {
    Stream<TestAccessMode> s = Stream.of(TestAccessMode.values());
    for (TestAccessType at : ats) {
        s = s.filter(e -> e.isOfType(at));
    }
    return s.map(TestAccessMode::toAccessMode).collect(toList());
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
static MethodHandle findVirtual(VarHandle vh, TestAccessMode tam, MethodType mt) {
    MethodHandle mh;
    try {
        mh = MethodHandles.publicLookup().
                findVirtual(VarHandle.class,
                            tam.toAccessMode().methodName(),
                            mt);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return bind(vh, mh, mt);
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
static MethodHandle varHandleInvoker(VarHandle vh, TestAccessMode tam, MethodType mt) {
    MethodHandle mh = MethodHandles.varHandleInvoker(
            tam.toAccessMode(),
            mt);

    return bind(vh, mh, mt);
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
static MethodHandle varHandleExactInvoker(VarHandle vh, TestAccessMode tam, MethodType mt) {
    MethodHandle mh = MethodHandles.varHandleExactInvoker(
            tam.toAccessMode(),
            mt);

    return bind(vh, mh, mt);
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
private static MethodHandle bind(VarHandle vh, MethodHandle mh, MethodType emt) {
    assertEquals(mh.type(), emt.insertParameterTypes(0, VarHandle.class),
                 "MethodHandle type differs from access mode type");

    MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
    assertEquals(info.getMethodType(), emt,
                 "MethodHandleInfo method type differs from access mode type");

    return mh.bindTo(vh);
}
项目:openjdk-jdk10    文件:VarHandleBaseTest.java   
Handles(VarHandle vh, VarHandleToMethodHandle f) throws Exception {
    this.vh = vh;
    this.f = f;
    this.amToHandle = new HashMap<>();

    amToType = new EnumMap<>(TestAccessMode.class);
    for (TestAccessMode am : testAccessModes()) {
        amToType.put(am, vh.accessModeType(am.toAccessMode()));
    }
}
项目:openjdk-jdk10    文件:VarHandleTestByteArrayAsChar.java   
@Test(dataProvider = "varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
    VarHandle vh = vhs.s;

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));

    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));

    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));

    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
项目:openjdk-jdk10    文件:VarHandleTestAccessLong.java   
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
    List<VarHandle> vhs = new ArrayList<>();
    vhs.add(vhField);
    vhs.add(vhStaticField);
    vhs.add(vhArray);

    return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
}
项目:openjdk-jdk10    文件:VarHandleTestAccessLong.java   
@Test(dataProvider = "varHandlesProvider")
public void testIsAccessModeSupported(VarHandle vh) {
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
项目:openjdk-jdk10    文件:VarHandleTestAccessLong.java   
@Test(dataProvider = "typesProvider")
public void testTypes(VarHandle vh, List<Class<?>> pts) {
    assertEquals(vh.varType(), long.class);

    assertEquals(vh.coordinateTypes(), pts);

    testTypes(vh);
}
项目:openjdk-jdk10    文件:VarHandleTestByteArrayAsDouble.java   
@Test(dataProvider = "varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
    VarHandle vh = vhs.s;

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));

    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));

    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
项目:openjdk-jdk10    文件:VarHandleTestByteArrayAsDouble.java   
@Test(dataProvider = "typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
    assertEquals(vh.varType(), double.class);

    assertEquals(vh.coordinateTypes(), pts);

    testTypes(vh);
}
项目:openjdk-jdk10    文件:VarHandleTestAccessDouble.java   
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
    List<VarHandle> vhs = new ArrayList<>();
    vhs.add(vhField);
    vhs.add(vhStaticField);
    vhs.add(vhArray);

    return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
}
项目:openjdk-jdk10    文件:VarHandleTestAccessDouble.java   
@Test(dataProvider = "varHandlesProvider")
public void testIsAccessModeSupported(VarHandle vh) {
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));

    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
    assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));

    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
    assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}