java.lang.invoke.VarHandle Java Examples
The following examples show how to use
java.lang.invoke.VarHandle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForkJoinPool.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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(); } }
Example #2
Source File: ForkJoinPool.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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) { ForkJoinTask<?>[] a; int s = top, d = s - base, cap, m; ForkJoinPool p = pool; if ((a = array) != null && (cap = a.length) > 0) { QA.setRelease(a, (m = cap - 1) & s, task); top = s + 1; if (d == m) growArray(false); else if (QA.getAcquire(a, m & (s - 1)) == null && p != null) { VarHandle.fullFence(); // was empty p.signalWork(null); } } }
Example #3
Source File: VarHandleTestAccessInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void testStaticFinalFieldUnsupported(VarHandle vh) { checkUOE(() -> { vh.set(0x89ABCDEF); }); checkUOE(() -> { vh.setVolatile(0x89ABCDEF); }); checkUOE(() -> { vh.setRelease(0x89ABCDEF); }); checkUOE(() -> { vh.setOpaque(0x89ABCDEF); }); }
Example #4
Source File: VarHandleTestAccessChar.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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'); }); }
Example #5
Source File: VarHandleTestAccessLong.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void testStaticFinalFieldUnsupported(VarHandle vh) { checkUOE(() -> { vh.set(0xCAFEBABECAFEBABEL); }); checkUOE(() -> { vh.setVolatile(0xCAFEBABECAFEBABEL); }); checkUOE(() -> { vh.setRelease(0xCAFEBABECAFEBABEL); }); checkUOE(() -> { vh.setOpaque(0xCAFEBABECAFEBABEL); }); }
Example #6
Source File: VarHandleTestAccessChar.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void testStaticFinalFieldUnsupported(VarHandle vh) { checkUOE(() -> { vh.set('\u4567'); }); checkUOE(() -> { vh.setVolatile('\u4567'); }); checkUOE(() -> { vh.setRelease('\u4567'); }); checkUOE(() -> { vh.setOpaque('\u4567'); }); }
Example #7
Source File: VarHandleTestAccessInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) { checkUOE(() -> { vh.set(recv, 0x89ABCDEF); }); checkUOE(() -> { vh.setVolatile(recv, 0x89ABCDEF); }); checkUOE(() -> { vh.setRelease(recv, 0x89ABCDEF); }); checkUOE(() -> { vh.setOpaque(recv, 0x89ABCDEF); }); }
Example #8
Source File: VarHandleTestAccessShort.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessShort recv, VarHandle vh) { checkUOE(() -> { vh.set(recv, (short)0x4567); }); checkUOE(() -> { vh.setVolatile(recv, (short)0x4567); }); checkUOE(() -> { vh.setRelease(recv, (short)0x4567); }); checkUOE(() -> { vh.setOpaque(recv, (short)0x4567); }); }
Example #9
Source File: VarHandleTestAccessLong.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); }); }
Example #10
Source File: VariableHandlesUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenVariableHandleForArrayVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { VarHandle arrayVarHandle = MethodHandles .arrayElementVarHandle(int[].class); assertEquals(2, arrayVarHandle.coordinateTypes().size()); assertEquals(int[].class, arrayVarHandle.coordinateTypes().get(0)); }
Example #11
Source File: VarHandleBaseTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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())); } }
Example #12
Source File: VariableHandlesUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle VARIABLE_TO_COMPARE_AND_SET = MethodHandles .lookup() .in(VariableHandlesUnitTest.class) .findVarHandle(VariableHandlesUnitTest.class, "variableToCompareAndSet", int.class); VARIABLE_TO_COMPARE_AND_SET.compareAndSet(this, 1, 100); assertEquals(100, (int) VARIABLE_TO_COMPARE_AND_SET.get(this)); }
Example #13
Source File: VarHandleTestAccessFloat.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); }
Example #14
Source File: ForkJoinPool.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #15
Source File: VarHandleTestByteArrayAsDouble.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); }
Example #16
Source File: VarHandleTestAccessFloat.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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); }
Example #17
Source File: VarHandleTestByteArrayAsDouble.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "typesProvider") public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) { assertEquals(vh.varType(), double.class); assertEquals(vh.coordinateTypes(), pts); testTypes(vh); }
Example #18
Source File: VarHandleTestByteArrayAsFloat.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "typesProvider") public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) { assertEquals(vh.varType(), float.class); assertEquals(vh.coordinateTypes(), pts); testTypes(vh); }
Example #19
Source File: VarHandleTestAccessLong.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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); }
Example #20
Source File: ConcurrentSkipListMap.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Removes all of the mappings from this map. */ public void clear() { Index<K,V> h, r, d; Node<K,V> b; VarHandle.acquireFence(); while ((h = head) != null) { if ((r = h.right) != null) // remove indices RIGHT.compareAndSet(h, r, null); else if ((d = h.down) != null) // remove levels HEAD.compareAndSet(this, h, d); else { long count = 0L; if ((b = h.node) != null) { // remove nodes Node<K,V> n; V v; while ((n = b.next) != null) { if ((v = n.val) != null && VAL.compareAndSet(n, v, null)) { --count; v = null; } if (v == null) unlinkNode(b, n); } } if (count != 0L) addCount(count); else break; } } }
Example #21
Source File: VarHandleTestByteArrayAsLong.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); 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)); }
Example #22
Source File: VarHandleTestAccessLong.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); }
Example #23
Source File: VarHandleTestAccessBoolean.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); 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)); 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)); }
Example #24
Source File: VarHandleTestAccessChar.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); }
Example #25
Source File: ForkJoinPool.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns an estimate of the number of tasks submitted to this * pool that have not yet begun executing. This method may take * time proportional to the number of submissions. * * @return the number of queued submissions */ public int getQueuedSubmissionCount() { WorkQueue[] ws; WorkQueue w; VarHandle.acquireFence(); int count = 0; if ((ws = workQueues) != null) { for (int i = 0; i < ws.length; i += 2) { if ((w = ws[i]) != null) count += w.queueSize(); } } return count; }
Example #26
Source File: VarHandleTestAccessString.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "typesProvider") public void testTypes(VarHandle vh, List<Class<?>> pts) { assertEquals(vh.varType(), String.class); assertEquals(vh.coordinateTypes(), pts); testTypes(vh); }
Example #27
Source File: ForkJoinPool.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns an estimate of the number of worker threads that are * not blocked waiting to join tasks or for other managed * synchronization. This method may overestimate the * number of running threads. * * @return the number of worker threads */ public int getRunningThreadCount() { WorkQueue[] ws; WorkQueue w; VarHandle.acquireFence(); int rc = 0; if ((ws = workQueues) != null) { for (int i = 1; i < ws.length; i += 2) { if ((w = ws[i]) != null && w.isApparentlyUnblocked()) ++rc; } } return rc; }
Example #28
Source File: ForkJoinPool.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * If present, removes task from queue and executes it. */ final void tryRemoveAndExec(ForkJoinTask<?> task) { ForkJoinTask<?>[] a; int s, cap; if ((a = array) != null && (cap = a.length) > 0 && (s = top) - base > 0) { // traverse from top for (int m = cap - 1, ns = s - 1, i = ns; ; --i) { int index = i & m; ForkJoinTask<?> t = (ForkJoinTask<?>)QA.get(a, index); if (t == null) break; else if (t == task) { if (QA.compareAndSet(a, 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(a, pindex); QA.setVolatile(a, pindex, null); int jindex = j & m; QA.setRelease(a, jindex, f); } VarHandle.releaseFence(); t.doExec(); } break; } } } }
Example #29
Source File: VarHandleTestByteArrayAsChar.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "typesProvider") public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) { assertEquals(vh.varType(), char.class); assertEquals(vh.coordinateTypes(), pts); testTypes(vh); }
Example #30
Source File: VarHandleTestReflection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "accessModesProvider", expectedExceptions = UnsupportedOperationException.class) public void methodHandleInvoke(VarHandle.AccessMode accessMode) throws Throwable { VarHandle v = handle(); // Try a reflective invoke using a MethodHandle MethodHandle mh = MethodHandles.lookup().unreflect( VarHandle.class.getMethod(accessMode.methodName(), Object[].class)); // Use invoke to avoid WrongMethodTypeException for // non-signature-polymorphic return types Object o = (Object) mh.invoke(v, new Object[]{}); }