8373935: Migrate java/lang/invoke tests away from TestNG

Reviewed-by: jvernee, alanb
This commit is contained in:
Chen Liang 2026-01-23 17:32:53 +00:00
parent 3fb118a29e
commit 40f7a18b2d
129 changed files with 5276 additions and 5487 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,17 +23,18 @@
/* @test
* @bug 8147078
* @run testng/othervm -ea -esa Test8147078
* @run junit/othervm -ea -esa Test8147078
*/
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class Test8147078 {
@ -65,16 +66,10 @@ public class Test8147078 {
@Test
public void testNoExceptionType() {
boolean caught = false;
try {
var cce = assertThrows(ClassCastException.class, () -> {
MethodHandle eek = (MethodHandle) MH_catchException.invoke(MH_target, String.class, MH_handler);
} catch (ClassCastException cce) {
assertEquals("java.lang.String", cce.getMessage());
caught = true;
} catch (Throwable t) {
fail("unexpected exception caught: " + t);
}
assertTrue(caught);
});
assertEquals("java.lang.String", cce.getMessage());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,17 +23,16 @@
/* @test
* @bug 8177146
* @run testng/othervm TestMethodHandleBind
* @run junit/othervm TestMethodHandleBind
*/
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodHandles.lookup;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class TestMethodHandleBind extends pkg.A {
static class B extends TestMethodHandleBind {}
@ -42,7 +41,7 @@ public class TestMethodHandleBind extends pkg.A {
public void testInstanceOfCallerClass() throws Throwable {
MethodHandle bound = lookup().bind(new TestMethodHandleBind() , "m1", MethodType.methodType(String.class));
String x = (String)bound.invoke();
assertEquals(x, this.getClass().getSimpleName());
assertEquals(this.getClass().getSimpleName(), x);
}
@Test
@ -50,47 +49,37 @@ public class TestMethodHandleBind extends pkg.A {
MethodHandle bound = lookup().bind(new B() , "m1", MethodType.methodType(String.class));
// MethodHandle bound = lookup().findVirtual(B.class, "m1", MethodType.methodType(String.class)).bindTo(new B());
String x = (String)bound.invoke();
assertEquals(x, "B");
assertEquals("B", x);
}
@Test
public void testInstanceOfReceiverClass() throws Throwable {
try {
MethodHandle bound = lookup().bind(new pkg.A() , "m1", MethodType.methodType(String.class));
bound.invoke();
fail("IllegalAccessException expected");
} catch (IllegalAccessException e) {
}
assertThrows(IllegalAccessException.class, () -> lookup().bind(new pkg.A() , "m1", MethodType.methodType(String.class)));
}
@Test
public void testPublicMethod() throws Throwable {
MethodHandle bound = lookup().bind(new pkg.A() , "m2", MethodType.methodType(String.class));
String x = (String)bound.invoke();
assertEquals(x, "A");
assertEquals("A", x);
}
@Test
public void testPublicMethod2() throws Throwable {
MethodHandle bound = lookup().bind(new TestMethodHandleBind(), "m2", MethodType.methodType(String.class));
String x = (String)bound.invoke();
assertEquals(x, this.getClass().getSimpleName());
assertEquals(this.getClass().getSimpleName(), x);
}
@Test
public void testInstanceOfCallerClassVarargs() throws Throwable {
MethodHandle bound = lookup().bind(new TestMethodHandleBind() , "m3", MethodType.methodType(String.class, String[].class));
String x = (String)bound.invoke("a", "b", "c");
assertEquals(x, this.getClass().getSimpleName() + "abc");
assertEquals(this.getClass().getSimpleName() + "abc", x);
}
@Test
public void testInstanceOfReceiverClassVarargs() throws Throwable {
try {
MethodHandle bound = lookup().bind(new pkg.A(), "m3", MethodType.methodType(String.class, String[].class));
bound.invoke();
fail("IllegalAccessException expected");
} catch (IllegalAccessException e) {
}
assertThrows(IllegalAccessException.class, () -> lookup().bind(new pkg.A(), "m3", MethodType.methodType(String.class, String[].class)));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @summary test access checking by java.lang.invoke.MethodHandles.Lookup
* @compile AccessControlTest.java AccessControlTest_subpkg/Acquaintance_remote.java
* @run testng/othervm test.java.lang.invoke.AccessControlTest
* @run junit/othervm test.java.lang.invoke.AccessControlTest
*/
package test.java.lang.invoke;
@ -33,12 +33,13 @@ import java.lang.invoke.*;
import java.lang.reflect.*;
import java.lang.reflect.Modifier;
import java.util.*;
import org.testng.annotations.*;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodHandles.Lookup.*;
import static java.lang.invoke.MethodType.*;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import test.java.lang.invoke.AccessControlTest_subpkg.Acquaintance_remote;
@ -69,7 +70,7 @@ public class AccessControlTest {
this.prevLookupClass = lookup.previousLookupClass();
this.lookupModes = lookup.lookupModes();
assert(lookupString().equals(lookup.toString()));
assertEquals(lookupString(), lookup.toString());
numberOf(lookupClass().getClassLoader()); // assign CL#
}
public LookupCase(Class<?> lookupClass, Class<?> prevLookupClass, int lookupModes) {
@ -96,7 +97,7 @@ public class AccessControlTest {
int cmp = c1.getName().compareTo(c2.getName());
if (cmp != 0) return cmp;
cmp = numberOf(c1.getClassLoader()) - numberOf(c2.getClassLoader());
assert(cmp != 0);
assertNotEquals(0, cmp);
return cmp;
} else if (p1 != p2){
if (p1 == null)
@ -106,7 +107,7 @@ public class AccessControlTest {
int cmp = p1.getName().compareTo(p2.getName());
if (cmp != 0) return cmp;
cmp = numberOf(p1.getClassLoader()) - numberOf(p2.getClassLoader());
assert(cmp != 0);
assertNotEquals(0, cmp);
return cmp;
}
return -(this.lookupModes() - that.lookupModes());
@ -211,8 +212,8 @@ public class AccessControlTest {
c1.getPackageName().equals(c2.getPackageName()));
boolean sameTopLevel = (topLevelClass(c1) == topLevelClass(c2));
boolean sameClass = (c1 == c2);
assert(samePackage || !sameTopLevel);
assert(sameTopLevel || !sameClass);
assertTrue(samePackage || !sameTopLevel);
assertTrue(sameTopLevel || !sameClass);
boolean accessible = sameClass;
if ((modes1 & PACKAGE) != 0) accessible |= samePackage;
@ -251,17 +252,17 @@ public class AccessControlTest {
changed |= (PRIVATE|PROTECTED); // [A5]
}
if (sameClass) {
assert(changed == 0); // [A11] (no deprivation if same class)
assertEquals(0, changed); // [A11] (no deprivation if same class)
}
if (accessible) assert((changed & PUBLIC) == 0);
if (accessible) assertEquals(0, changed & PUBLIC);
int modes2 = modes1 & ~changed;
Class<?> plc = (m1 == m2) ? prevLookupClass() : c1; // [A9] [A10]
if ((modes1 & UNCONDITIONAL) != 0) plc = null; // [A8]
LookupCase l2 = new LookupCase(c2, plc, modes2);
assert(l2.lookupClass() == c2); // [A1]
assert((modes1 | modes2) == modes1); // [A1-a] (no elevation of access)
assert(l2.prevLookupClass() == null || (modes2 & MODULE) == 0);
assertSame(l2.lookupClass(), c2); // [A1]
assertEquals(modes1, modes1 | modes2); // [A1-a] (no elevation of access)
assertTrue(l2.prevLookupClass() == null || (modes2 & MODULE) == 0);
return l2;
}
@ -280,8 +281,8 @@ public class AccessControlTest {
}
if (newModes == oldModes) return this; // return self if no change
LookupCase l2 = new LookupCase(lookupClass(), prevLookupClass(), newModes);
assert((oldModes | newModes) == oldModes); // [A2] (no elevation of access)
assert(l2.prevLookupClass() == null || (newModes & MODULE) == 0);
assertEquals(oldModes, oldModes | newModes); // [A2] (no elevation of access)
assertTrue(l2.prevLookupClass() == null || (newModes & MODULE) == 0);
return l2;
}
@ -331,7 +332,7 @@ public class AccessControlTest {
&& Modifier.isPublic(m.getModifiers());
}
assert(m1 == m2 && prevLookupClass == null);
assertNull(prevLookupClass);
if (!willAccessClass(c2, false))
return false;
@ -380,7 +381,7 @@ public class AccessControlTest {
&& Modifier.isPublic(c2.getModifiers());
}
assert(m1 == m2 && prevLookupClass == null);
assertNull(prevLookupClass);
LookupCase lc = this.in(c2);
int modes1 = lc.lookupModes();
@ -409,8 +410,8 @@ public class AccessControlTest {
Class<?> c = cls;
for (Class<?> ec; (ec = c.getEnclosingClass()) != null; )
c = ec;
assert(c.getEnclosingClass() == null);
assert(c == cls || cls.getEnclosingClass() != null);
assertNull(c.getEnclosingClass());
assertTrue(c == cls || cls.getEnclosingClass() != null);
return c;
}
@ -443,14 +444,14 @@ public class AccessControlTest {
if (edges == null) CASE_EDGES.put(l2, edges = new TreeSet<>());
if (edges.add(l1)) {
Class<?> c1 = l1.lookupClass();
assert(l2.lookupClass() == c2); // [A1]
assertSame(l2.lookupClass(), c2); // [A1]
int m1 = l1.lookupModes();
int m2 = l2.lookupModes();
assert((m1 | m2) == m1); // [A2] (no elevation of access)
assertEquals(m1, (m1 | m2)); // [A2] (no elevation of access)
LookupCase expect = dropAccess == 0 ? l1.in(c2) : l1.in(c2).dropLookupMode(dropAccess);
if (!expect.equals(l2))
System.out.println("*** expect "+l1+" => "+expect+" but got "+l2);
assertEquals(l2, expect);
assertEquals(expect, l2);
}
}
@ -567,7 +568,7 @@ public class AccessControlTest {
if (willAccess != didAccess) {
System.out.println(sourceCase+" => "+targetClass.getSimpleName()+(isFindOrAccessClass?"":"."+methodName+methodType));
System.out.println("fail "+(isFindOrAccessClass?kind:"on "+method)+" ex="+accessError);
assertEquals(willAccess, didAccess);
assertEquals(didAccess, willAccess);
}
testCount++;
if (!didAccess) testCountFails++;
@ -579,10 +580,10 @@ public class AccessControlTest {
System.out.println(targetClass.getSimpleName()+"."+methodName+methodType);
try {
Method method = targetClass.getDeclaredMethod(methodName, methodType.parameterArray());
assertEquals(method.getReturnType(), methodType.returnType());
assertEquals(methodType.returnType(), method.getReturnType());
int haveMods = method.getModifiers();
assert(Modifier.isStatic(haveMods));
assert(targetAccess == fixMods(haveMods));
assertTrue(Modifier.isStatic(haveMods));
assertEquals(targetAccess, fixMods(haveMods));
return method;
} catch (NoSuchMethodException ex) {
throw new AssertionError(methodName, ex);
@ -604,7 +605,7 @@ public class AccessControlTest {
case PACKAGE: return "pkg_in_";
case PRIVATE: return "pri_in_";
}
assert(false);
fail();
return "?";
}
private static final int[] ACCESS_CASES = {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @bug 8155106
* @run testng/othervm -ea -esa test.java.lang.invoke.ArrayConstructorTest
* @run junit/othervm -ea -esa test.java.lang.invoke.ArrayConstructorTest
*/
package test.java.lang.invoke;
@ -32,30 +32,22 @@ import java.lang.invoke.MethodHandles;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;
public class ArrayConstructorTest {
static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
@Test
public static void testFindConstructorArray() {
boolean caught = false;
try {
MethodHandle h = LOOKUP.findConstructor(Object[].class, methodType(void.class));
} catch (NoSuchMethodException nsme) {
assertEquals("no constructor for array class: [Ljava.lang.Object;", nsme.getMessage());
caught = true;
} catch (Exception e) {
throw new AssertionError("unexpected exception: " + e);
}
assertTrue(caught);
public void testFindConstructorArray() {
var nsme = assertThrows(NoSuchMethodException.class, () -> LOOKUP.findConstructor(Object[].class, methodType(void.class)));
assertEquals("no constructor for array class: [Ljava.lang.Object;", nsme.getMessage());
}
@DataProvider
static Object[][] arrayConstructorNegative() {
return new Object[][]{
{String.class, IllegalArgumentException.class, "not an array class: java.lang.String"},
@ -63,34 +55,28 @@ public class ArrayConstructorTest {
};
}
@Test(dataProvider = "arrayConstructorNegative")
public static void testArrayConstructorNegative(Class<?> clazz, Class<?> exceptionClass, String message) {
boolean caught = false;
try {
MethodHandle h = MethodHandles.arrayConstructor(clazz);
} catch (Exception e) {
assertEquals(exceptionClass, e.getClass());
if (message != null) {
assertEquals(message, e.getMessage());
}
caught = true;
@ParameterizedTest
@MethodSource("arrayConstructorNegative")
public void testArrayConstructorNegative(Class<?> clazz, Class<? extends Exception> exceptionClass, String message) {
var e = assertThrowsExactly(exceptionClass, () -> MethodHandles.arrayConstructor(clazz));
if (message != null) {
assertEquals(message, e.getMessage());
}
assertTrue(caught);
}
@Test
public static void testArrayConstructor() throws Throwable {
public void testArrayConstructor() throws Throwable {
MethodHandle h = MethodHandles.arrayConstructor(String[].class);
assertEquals(methodType(String[].class, int.class), h.type());
String[] a = (String[]) h.invoke(17);
assertEquals(17, a.length);
}
@Test(expectedExceptions = {NegativeArraySizeException.class})
public static void testArrayConstructorNegativeIndex() throws Throwable {
@Test
public void testArrayConstructorNegativeIndex() throws Throwable {
MethodHandle h = MethodHandles.arrayConstructor(String[].class);
assertEquals(methodType(String[].class, int.class), h.type());
h.invoke(-1); // throws exception
assertThrows(NegativeArraySizeException.class, () -> h.invoke(-1));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,36 +22,39 @@
*/
/* @test
* @run testng/othervm -ea -esa test.java.lang.invoke.ArrayLengthTest
* @run junit/othervm -ea -esa test.java.lang.invoke.ArrayLengthTest
*/
package test.java.lang.invoke;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ArrayLengthTest {
@DataProvider
Object[][] arrayClasses() {
return new Object[][] {
{int[].class},
{long[].class},
{float[].class},
{double[].class},
{boolean[].class},
{byte[].class},
{short[].class},
{char[].class},
{Object[].class},
{StringBuffer[].class}
static Object[] arrayClasses() {
return new Object[] {
int[].class,
long[].class,
float[].class,
double[].class,
boolean[].class,
byte[].class,
short[].class,
char[].class,
Object[].class,
StringBuffer[].class
};
}
@Test(dataProvider = "arrayClasses")
@ParameterizedTest
@MethodSource("arrayClasses")
public void testArrayLength(Class<?> arrayClass) throws Throwable {
MethodHandle arrayLength = MethodHandles.arrayLength(arrayClass);
assertEquals(int.class, arrayLength.type().returnType());
@ -60,25 +63,28 @@ public class ArrayLengthTest {
assertEquals(10, arrayLength.invoke(array));
}
@Test(dataProvider = "arrayClasses", expectedExceptions = NullPointerException.class)
@ParameterizedTest
@MethodSource("arrayClasses")
public void testArrayLengthInvokeNPE(Class<?> arrayClass) throws Throwable {
MethodHandle arrayLength = MethodHandles.arrayLength(arrayClass);
arrayLength.invoke(null);
assertThrows(NullPointerException.class, () -> arrayLength.invoke(null));
}
@Test(expectedExceptions = IllegalArgumentException.class)
@Test
public void testArrayLengthNoArray() {
MethodHandles.arrayLength(String.class);
assertThrows(IllegalArgumentException.class, () -> MethodHandles.arrayLength(String.class));
}
@Test(expectedExceptions = NullPointerException.class)
@Test
public void testArrayLengthNPE() {
MethodHandles.arrayLength(null);
assertThrows(NullPointerException.class, () -> MethodHandles.arrayLength(null));
}
@Test(expectedExceptions = NullPointerException.class)
@Test
public void testNullReference() throws Throwable {
MethodHandle arrayLength = MethodHandles.arrayLength(String[].class);
int len = (int)arrayLength.invokeExact((String[])null);
assertThrows(NullPointerException.class, () -> {
int len = (int)arrayLength.invokeExact((String[])null);
});
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,20 +22,19 @@
*/
/* @test
* @run testng/othervm CallerSensitiveMethodHandle
* @run junit/othervm CallerSensitiveMethodHandle
* @summary Check Lookup findVirtual, findStatic and unreflect behavior with
* caller sensitive methods with focus on AccessibleObject.setAccessible
*/
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.Field;
import static java.lang.invoke.MethodType.*;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class CallerSensitiveMethodHandle {
private static int field = 0;
@ -46,7 +45,7 @@ public class CallerSensitiveMethodHandle {
MethodHandle mh = l.findVirtual(Field.class, "setInt", methodType(void.class, Object.class, int.class));
int newValue = 5;
mh.invokeExact(f, (Object) null, newValue);
assertTrue(field == newValue);
assertEquals(newValue, field);
}
@Test
@ -55,6 +54,6 @@ public class CallerSensitiveMethodHandle {
MethodHandle MH_lookup2 = lookup.findStatic(MethodHandles.class, "lookup", methodType(Lookup.class));
Lookup lookup2 = (Lookup) MH_lookup2.invokeExact();
System.out.println(lookup2 + " original lookup class " + lookup.lookupClass());
assertTrue(lookup2.lookupClass() == lookup.lookupClass());
assertSame(lookup.lookupClass(), lookup2.lookupClass());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,15 +24,13 @@
/* @test
* @summary Smoke-test class specializer, used to create BoundMethodHandle classes
* @compile/module=java.base java/lang/invoke/ClassSpecializerHelper.java
* @run testng/othervm/timeout=250 -ea -esa ClassSpecializerTest
* @run junit/othervm/timeout=250 -ea -esa ClassSpecializerTest
*/
// Useful diagnostics to try:
// -Djava.lang.invoke.MethodHandle.TRACE_RESOLVE=true
// -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true
import org.testng.annotations.*;
import java.lang.invoke.*;
import java.util.ArrayList;
import java.util.Arrays;
@ -40,6 +38,11 @@ import java.util.List;
import static java.lang.invoke.ClassSpecializerHelper.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
public class ClassSpecializerTest {
@Test
@ -58,12 +61,12 @@ public class ClassSpecializerTest {
}
args.set(0, key * 1000 + 42);
Frob f = (Frob) mh.invokeWithArguments(args.toArray());
assert(f.kind() == k);
assertSame(k, f.kind());
System.out.println("k.f(...) = " + f.toString());
List<Object> l = f.asList();
System.out.println("f.l = " + l);
args.subList(0,1).clear(); // drop label
assert(args.equals(l));
assertEquals(args, l);
}
}
private static Object coughUpA(Class<?> pt) throws Throwable {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,27 +26,19 @@
* @bug 8143232
* @summary Test verifies that LF bootstraps properly when run with COMPILE_THRESHOLD set
* @compile CompileThresholdBootstrapTest.java
* @run testng/othervm -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=30 test.java.lang.invoke.CompileThresholdBootstrapTest
* @run junit/othervm -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=30 test.java.lang.invoke.CompileThresholdBootstrapTest
*/
package test.java.lang.invoke;
import java.lang.invoke.MethodHandles;
import org.testng.*;
import org.testng.annotations.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public final class CompileThresholdBootstrapTest {
@Test
public void testBootstrap() throws Throwable {
Assert.assertEquals((int)MethodHandles.constant(int.class, (int)0).invokeExact(), 0);
}
public static void main(String ... args) {
try {
CompileThresholdBootstrapTest test = new CompileThresholdBootstrapTest();
test.testBootstrap();
} catch (Throwable t) {
t.printStackTrace();
}
assertEquals(0, (int)MethodHandles.constant(int.class, (int)0).invokeExact());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @summary unit tests for java.lang.invoke.MethodHandles
* @run testng/othervm -ea -esa test.java.lang.invoke.ConstantIdentityMHTest
* @run junit/othervm -ea -esa test.java.lang.invoke.ConstantIdentityMHTest
*/
package test.java.lang.invoke;
@ -31,13 +31,14 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
import static org.testng.Assert.*;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class ConstantIdentityMHTest {
@DataProvider(name = "testZeroData")
private Object[][] testZeroData() {
private static Object[][] testZeroData() {
return new Object[][] {
{void.class, "()void"},
{int.class, "()int"},
@ -52,26 +53,27 @@ public class ConstantIdentityMHTest {
};
}
@Test(dataProvider = "testZeroData")
@ParameterizedTest
@MethodSource("testZeroData")
public void testZero(Class<?> expectedtype, String expected) throws Throwable {
assertEquals(MethodHandles.zero(expectedtype).type().toString(), expected);
assertEquals(expected, MethodHandles.zero(expectedtype).type().toString());
}
@Test(expectedExceptions={ NullPointerException.class })
@Test
public void testZeroNPE() {
MethodHandle mh = MethodHandles.zero(null);
assertThrows(NullPointerException.class, () -> MethodHandles.zero(null));
}
@Test
void testEmpty() throws Throwable {
MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class));
assertEquals((String)cat.invoke("x","y"), "xy");
assertEquals("xy", (String)cat.invoke("x","y"));
MethodHandle mhEmpty = MethodHandles.empty(cat.type());
assertEquals((String)mhEmpty.invoke("x","y"), null);
assertNull((String) mhEmpty.invoke("x", "y"));
}
@Test(expectedExceptions = { NullPointerException.class })
@Test
void testEmptyNPE() {
MethodHandle lenEmptyMH = MethodHandles.empty(null);
assertThrows(NullPointerException.class, () -> MethodHandles.empty(null));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @modules java.base/java.lang:open
* @run testng/othervm test.DefineClassTest
* @run junit/othervm test.DefineClassTest
* @summary Basic test for java.lang.invoke.MethodHandles.Lookup.defineClass
*/
@ -38,7 +38,6 @@ import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.testng.annotations.Test;
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
import static java.lang.classfile.ClassFile.ACC_STATIC;
@ -48,7 +47,8 @@ import static java.lang.constant.ConstantDescs.INIT_NAME;
import static java.lang.constant.ConstantDescs.MTD_void;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodHandles.Lookup.*;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class DefineClassTest {
private static final String THIS_PACKAGE = DefineClassTest.class.getPackageName();
@ -60,9 +60,9 @@ public class DefineClassTest {
* protection domain, as a lookup class.
*/
void testSameAbode(Class<?> clazz, Class<?> lc) {
assertTrue(clazz.getClassLoader() == lc.getClassLoader());
assertEquals(clazz.getPackageName(), lc.getPackageName());
assertTrue(clazz.getProtectionDomain() == lc.getProtectionDomain());
assertSame(lc.getClassLoader(), clazz.getClassLoader());
assertEquals(lc.getPackageName(), clazz.getPackageName());
assertSame(lc.getProtectionDomain(), clazz.getProtectionDomain());
}
/**
@ -72,8 +72,8 @@ public class DefineClassTest {
void testDiscoverable(Class<?> clazz, Lookup lookup) throws Exception {
String cn = clazz.getName();
ClassLoader loader = clazz.getClassLoader();
assertTrue(Class.forName(cn, false, loader) == clazz);
assertTrue(lookup.findClass(cn) == clazz);
assertSame(clazz, Class.forName(cn, false, loader));
assertSame(clazz, lookup.findClass(cn));
}
/**
@ -86,7 +86,7 @@ public class DefineClassTest {
Class<?> clazz = lookup.defineClass(generateClass(CLASS_NAME));
// test name
assertEquals(clazz.getName(), CLASS_NAME);
assertEquals(CLASS_NAME, clazz.getName());
// test loader/package/protection-domain
testSameAbode(clazz, lookup.lookupClass());
@ -95,10 +95,8 @@ public class DefineClassTest {
testDiscoverable(clazz, lookup);
// attempt defineClass again
try {
lookup.defineClass(generateClass(CLASS_NAME));
assertTrue(false);
} catch (LinkageError expected) { }
var bytes = generateClass(CLASS_NAME);
assertThrows(LinkageError.class, () -> lookup.defineClass(bytes));
}
/**
@ -126,10 +124,7 @@ public class DefineClassTest {
classBytes = generateRunner(CLASS_NAME + nextNumber(), THIS_CLASS, "method4");
Class<?> clazz = lookup.defineClass(classBytes);
Runnable r = (Runnable) clazz.newInstance();
try {
r.run();
assertTrue(false);
} catch (IllegalAccessError expected) { }
assertThrows(IllegalAccessError.class, r::run);
}
public static void method1() { }
@ -154,12 +149,8 @@ public class DefineClassTest {
Class<?> clazz = lookup().defineClass(classBytes);
// trigger initializer to run
try {
clazz.newInstance();
assertTrue(false);
} catch (ExceptionInInitializerError e) {
assertTrue(e.getCause() instanceof IllegalCallerException);
}
var e = assertThrows(ExceptionInInitializerError.class, clazz::newInstance);
assertInstanceOf(IllegalCallerException.class, e.getCause());
}
static void fail() { throw new IllegalCallerException(); }
@ -189,9 +180,9 @@ public class DefineClassTest {
ClassLoader loader = new URLClassLoader(new URL[] { url1, url2 });
Class<?> target1 = Class.forName("p.C1", false, loader);
Class<?> target2 = Class.forName("p.C2", false, loader);
assertTrue(target1.getClassLoader() == loader);
assertTrue(target1.getClassLoader() == loader);
assertNotEquals(target1.getProtectionDomain(), target2.getProtectionDomain());
assertSame(loader, target1.getClassLoader());
assertSame(loader, target1.getClassLoader());
assertNotEquals(target2.getProtectionDomain(), target1.getProtectionDomain());
// protection domain 1
Lookup lookup1 = privateLookupIn(target1, lookup());
@ -214,43 +205,43 @@ public class DefineClassTest {
@Test
public void testBootLoader() throws Exception {
Lookup lookup = privateLookupIn(Thread.class, lookup());
assertTrue(lookup.getClass().getClassLoader() == null);
assertNull(lookup.getClass().getClassLoader());
Class<?> clazz = lookup.defineClass(generateClass("java.lang.Foo"));
assertEquals(clazz.getName(), "java.lang.Foo");
assertEquals("java.lang.Foo", clazz.getName());
testSameAbode(clazz, Thread.class);
testDiscoverable(clazz, lookup);
}
@Test(expectedExceptions = { IllegalArgumentException.class })
@Test
public void testWrongPackage() throws Exception {
lookup().defineClass(generateClass("other.C"));
assertThrows(IllegalArgumentException.class, () -> lookup().defineClass(generateClass("other.C")));
}
@Test(expectedExceptions = { IllegalAccessException.class })
@Test
public void testNoPackageAccess() throws Exception {
Lookup lookup = lookup().dropLookupMode(PACKAGE);
lookup.defineClass(generateClass(THIS_PACKAGE + ".C"));
assertThrows(IllegalAccessException.class, () -> lookup.defineClass(generateClass(THIS_PACKAGE + ".C")));
}
@Test(expectedExceptions = { ClassFormatError.class })
@Test
public void testTruncatedClassFile() throws Exception {
lookup().defineClass(new byte[0]);
assertThrows(ClassFormatError.class, () -> lookup().defineClass(new byte[0]));
}
@Test(expectedExceptions = { NullPointerException.class })
@Test
public void testNull() throws Exception {
lookup().defineClass(null);
assertThrows(NullPointerException.class, () -> lookup().defineClass(null));
}
@Test(expectedExceptions = { NoClassDefFoundError.class })
@Test
public void testLinking() throws Exception {
lookup().defineClass(generateNonLinkableClass(THIS_PACKAGE + ".NonLinkableClass"));
assertThrows(NoClassDefFoundError.class, () -> lookup().defineClass(generateNonLinkableClass(THIS_PACKAGE + ".NonLinkableClass")));
}
@Test(expectedExceptions = { IllegalArgumentException.class })
@Test
public void testModuleInfo() throws Exception {
lookup().defineClass(generateModuleInfo());
assertThrows(IllegalArgumentException.class, () -> lookup().defineClass(generateModuleInfo()));
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,19 +24,24 @@
/* @test
* @bug 8158169
* @summary unit tests for java.lang.invoke.MethodHandles
* @run testng test.java.lang.invoke.DropArgumentsTest
* @run junit test.java.lang.invoke.DropArgumentsTest
*/
package test.java.lang.invoke;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class DropArgumentsTest {
@ -53,8 +58,7 @@ public class DropArgumentsTest {
}
@DataProvider(name = "dropArgumentsToMatchNPEData")
private Object[][] dropArgumentsToMatchNPEData()
private static Object[][] dropArgumentsToMatchNPEData()
throws NoSuchMethodException, IllegalAccessException {
MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class));
return new Object[][] {
@ -63,13 +67,13 @@ public class DropArgumentsTest {
};
}
@Test(dataProvider = "dropArgumentsToMatchNPEData", expectedExceptions = { NullPointerException.class })
@ParameterizedTest
@MethodSource("dropArgumentsToMatchNPEData")
public void dropArgumentsToMatchNPE(MethodHandle target, int pos, List<Class<?>> valueType, int skip) {
MethodHandles.dropArgumentsToMatch(target, pos, valueType , skip);
assertThrows(NullPointerException.class, () -> MethodHandles.dropArgumentsToMatch(target, pos, valueType, skip));
}
@DataProvider(name = "dropArgumentsToMatchIAEData")
private Object[][] dropArgumentsToMatchIAEData()
private static Object[][] dropArgumentsToMatchIAEData()
throws NoSuchMethodException, IllegalAccessException {
MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class));
MethodType bigType = cat.type().insertParameterTypes(0, String.class, String.class, int.class);
@ -82,17 +86,20 @@ public class DropArgumentsTest {
};
}
@Test(dataProvider = "dropArgumentsToMatchIAEData", expectedExceptions = { IllegalArgumentException.class })
@ParameterizedTest
@MethodSource("dropArgumentsToMatchIAEData")
public void dropArgumentsToMatchIAE(MethodHandle target, int pos, List<Class<?>> valueType, int skip) {
MethodHandles.dropArgumentsToMatch(target, pos, valueType , skip);
assertThrows(IllegalArgumentException.class, () -> MethodHandles.dropArgumentsToMatch(target, pos, valueType, skip));
}
@Test(expectedExceptions = { IllegalArgumentException.class })
@Test
public void dropArgumentsToMatchTestWithVoid() throws Throwable {
MethodHandle cat = lookup().findVirtual(String.class, "concat",
MethodType.methodType(String.class, String.class));
MethodType bigTypewithVoid = cat.type().insertParameterTypes(0, void.class, String.class, int.class);
MethodHandle handle2 = MethodHandles.dropArgumentsToMatch(cat, 0, bigTypewithVoid.parameterList(), 1);
MethodType.methodType(String.class, String.class));
List<Class<?>> bigTypewithVoid = new ArrayList<>(cat.type().parameterList());
bigTypewithVoid.addAll(0, List.of(void.class, String.class, int.class));
assertThrows(IllegalArgumentException.class, () ->
MethodHandles.dropArgumentsToMatch(cat, 0, bigTypewithVoid, 1));
}
public static class MethodSet {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,9 +21,9 @@
* questions.
*/
/**
/*
* @test
* @run testng DropLookupModeTest
* @run junit DropLookupModeTest
* @summary Basic unit tests Lookup::dropLookupMode
*/
@ -31,83 +31,85 @@ import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import static java.lang.invoke.MethodHandles.Lookup.*;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
@Test
public class DropLookupModeTest {
/**
* Basic test of dropLookupMode
*/
@Test
public void testBasic() {
final Lookup fullPowerLookup = MethodHandles.lookup();
final Class<?> lc = fullPowerLookup.lookupClass();
assertTrue(fullPowerLookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PROTECTED|PRIVATE|ORIGINAL));
assertEquals(PUBLIC | MODULE | PACKAGE | PROTECTED | PRIVATE | ORIGINAL, fullPowerLookup.lookupModes());
Lookup lookup = fullPowerLookup.dropLookupMode(PRIVATE);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE | PACKAGE, lookup.lookupModes());
lookup = fullPowerLookup.dropLookupMode(PROTECTED);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PRIVATE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE | PACKAGE | PRIVATE, lookup.lookupModes());
lookup = fullPowerLookup.dropLookupMode(PACKAGE);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE, lookup.lookupModes());
lookup = fullPowerLookup.dropLookupMode(MODULE);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC, lookup.lookupModes());
lookup = fullPowerLookup.dropLookupMode(PUBLIC);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == 0);
assertSame(lc, lookup.lookupClass());
assertEquals(0, lookup.lookupModes());
lookup = fullPowerLookup.dropLookupMode(UNCONDITIONAL);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PRIVATE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE | PACKAGE | PRIVATE, lookup.lookupModes());
}
/**
* Starting with a full power Lookup, use dropLookupMode to create new Lookups
* with reduced access.
*/
@Test
public void testReducingAccess() {
Lookup lookup = MethodHandles.lookup();
final Class<?> lc = lookup.lookupClass();
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PROTECTED|PRIVATE|ORIGINAL));
assertEquals(PUBLIC | MODULE | PACKAGE | PROTECTED | PRIVATE | ORIGINAL, lookup.lookupModes());
lookup = lookup.dropLookupMode(PROTECTED);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PRIVATE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE | PACKAGE | PRIVATE, lookup.lookupModes());
lookup = lookup.dropLookupMode(PRIVATE);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE | PACKAGE, lookup.lookupModes());
lookup = lookup.dropLookupMode(PACKAGE);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == (PUBLIC|MODULE));
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC | MODULE, lookup.lookupModes());
lookup = lookup.dropLookupMode(MODULE);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == PUBLIC);
assertSame(lc, lookup.lookupClass());
assertEquals(PUBLIC, lookup.lookupModes());
lookup = lookup.dropLookupMode(PUBLIC);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == 0);
assertSame(lc, lookup.lookupClass());
assertEquals(0, lookup.lookupModes());
// repeat with lookup has no access
lookup = lookup.dropLookupMode(PUBLIC);
assertTrue(lookup.lookupClass() == lc);
assertTrue(lookup.lookupModes() == 0);
assertSame(lc, lookup.lookupClass());
assertEquals(0, lookup.lookupModes());
}
@DataProvider(name = "unconditionals")
public Object[][] unconditionals() {
public static Object[][] unconditionals() {
Lookup publicLookup = MethodHandles.publicLookup();
return new Object[][] {
{ publicLookup, Object.class },
@ -120,9 +122,10 @@ public class DropLookupModeTest {
* Test dropLookupMode on the lookup with public lookup
* and UNCONDITIONAL
*/
@Test(dataProvider = "unconditionals")
@ParameterizedTest
@MethodSource("unconditionals")
public void testUnconditionalLookup(Lookup unconditionalLookup, Class<?> expected) {
assertTrue(unconditionalLookup.lookupModes() == UNCONDITIONAL);
assertEquals(UNCONDITIONAL, unconditionalLookup.lookupModes());
assertPublicLookup(unconditionalLookup.dropLookupMode(PRIVATE), expected);
assertPublicLookup(unconditionalLookup.dropLookupMode(PROTECTED), expected);
@ -132,31 +135,27 @@ public class DropLookupModeTest {
// drop all access
Lookup lookup = unconditionalLookup.dropLookupMode(UNCONDITIONAL);
assertTrue(lookup.lookupClass() == expected);
assertTrue(lookup.lookupModes() == 0);
assertSame(expected, lookup.lookupClass());
assertEquals(0, lookup.lookupModes());
}
private void assertPublicLookup(Lookup lookup, Class<?> expected) {
assertTrue(lookup.lookupClass() == expected);
assertTrue(lookup.lookupModes() == UNCONDITIONAL);
}
@DataProvider(name = "badInput")
public Object[][] badInput() {
return new Object[][] {
{ 0, null },
{ (PACKAGE|PRIVATE), null }, // two modes
{ Integer.MAX_VALUE, null },
{ Integer.MIN_VALUE, null },
};
assertSame(expected, lookup.lookupClass());
assertEquals(UNCONDITIONAL, lookup.lookupModes());
}
/**
* Check that IllegalArgumentException is thrown for bad input
*/
@Test(dataProvider = "badInput", expectedExceptions = {IllegalArgumentException.class})
public void testBadInput(Integer modeToDrop, Object ignore) {
MethodHandles.lookup().dropLookupMode(modeToDrop);
@ParameterizedTest
@ValueSource(ints = {
0,
(PACKAGE|PRIVATE), // two modes
Integer.MAX_VALUE,
Integer.MIN_VALUE,
})
public void testBadInput(int modeToDrop) {
assertThrows(IllegalArgumentException.class, () -> MethodHandles.lookup().dropLookupMode(modeToDrop));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/*
* @test
* @bug 8194554
* @run testng/othervm test.java.lang.invoke.FilterArgumentsTest
* @run junit/othervm test.java.lang.invoke.FilterArgumentsTest
*/
package test.java.lang.invoke;
@ -37,40 +37,40 @@ import java.util.List;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.methodType;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class FilterArgumentsTest {
@Test
public static void testFilterA_B_C() throws Throwable {
public void testFilterA_B_C() throws Throwable {
FilterTest test = new FilterTest(
filterArguments(MH_TEST, 0, MH_FILTER_A, MH_FILTER_B, MH_FILTER_C));
test.run(List.of("A", "B", "C"));
}
@Test
public static void testFilterA_B() throws Throwable {
public void testFilterA_B() throws Throwable {
FilterTest test = new FilterTest(
filterArguments(MH_TEST, 0, MH_FILTER_A, MH_FILTER_B));
test.run(List.of("A", "B"));
}
@Test
public static void testFilterB_C() throws Throwable {
public void testFilterB_C() throws Throwable {
FilterTest test = new FilterTest(
filterArguments(MH_TEST, 1, MH_FILTER_B, MH_FILTER_C));
test.run(List.of("B", "C"));
}
@Test
public static void testFilterB() throws Throwable {
public void testFilterB() throws Throwable {
FilterTest test = new FilterTest(filterArguments(MH_TEST, 1, MH_FILTER_B));
test.run(List.of("B"));
}
@Test
public static void testFilterC() throws Throwable {
public void testFilterC() throws Throwable {
FilterTest test = new FilterTest(filterArguments(MH_TEST, 2, MH_FILTER_C));
test.run(List.of("C"));
}
@ -85,8 +85,8 @@ public class FilterArgumentsTest {
void run(List<String> expected) throws Throwable {
filters.clear();
assertEquals((String)mh.invokeExact("x", 0, 'z'), "x-0-z");
assertEquals(filters, expected);
assertEquals("x-0-z", (String)mh.invokeExact("x", 0, 'z'));
assertEquals(expected, filters);
}
static String filterA(String s) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @bug 8139885
* @run testng/othervm -ea -esa test.java.lang.invoke.FindAccessTest
* @run junit/othervm -ea -esa test.java.lang.invoke.FindAccessTest
*/
package test.java.lang.invoke;
@ -33,9 +33,10 @@ import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for Lookup.findClass/accessClass extensions added in JEP 274.
@ -45,7 +46,7 @@ public class FindAccessTest {
static final Lookup LOOKUP = MethodHandles.lookup();
@Test
public static void testFindSpecial() throws Throwable {
public void testFindSpecial() throws Throwable {
FindSpecial.C c = new FindSpecial.C();
assertEquals("I1.m", c.m());
MethodType t = MethodType.methodType(String.class);
@ -54,25 +55,18 @@ public class FindAccessTest {
}
@Test
public static void testFindSpecialAbstract() throws Throwable {
public void testFindSpecialAbstract() throws Throwable {
FindSpecial.C c = new FindSpecial.C();
assertEquals("q", c.q());
MethodType t = MethodType.methodType(String.class);
boolean caught = false;
try {
MethodHandle ci3q = LOOKUP.findSpecial(FindSpecial.I3.class, "q", t, FindSpecial.C.class);
} catch (Throwable thrown) {
if (!(thrown instanceof IllegalAccessException) || !FindSpecial.ABSTRACT_ERROR.equals(thrown.getMessage())) {
throw new AssertionError(thrown.getMessage(), thrown);
}
caught = true;
}
assertTrue(caught);
var thrown = assertThrows(IllegalAccessException.class,
() -> LOOKUP.findSpecial(FindSpecial.I3.class, "q", t, FindSpecial.C.class));
assertEquals(FindSpecial.ABSTRACT_ERROR, thrown.getMessage());
}
@Test(expectedExceptions = {ClassNotFoundException.class})
public static void testFindClassCNFE() throws ClassNotFoundException, IllegalAccessException {
LOOKUP.findClass("does.not.Exist");
@Test
public void testFindClassCNFE() throws ClassNotFoundException, IllegalAccessException {
assertThrows(ClassNotFoundException.class, () -> LOOKUP.findClass("does.not.Exist"));
}
static class FindSpecial {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @bug 8139885
* @run testng/othervm -ea -esa test.java.lang.invoke.FoldTest
* @run junit/othervm -ea -esa test.java.lang.invoke.FoldTest
*/
package test.java.lang.invoke;
@ -36,9 +36,9 @@ import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests for the new fold method handle combinator added in JEP 274.
@ -48,7 +48,7 @@ public class FoldTest {
static final Lookup LOOKUP = MethodHandles.lookup();
@Test
public static void testFold0a() throws Throwable {
public void testFold0a() throws Throwable {
// equivalence to foldArguments(MethodHandle,MethodHandle)
MethodHandle fold = MethodHandles.foldArguments(Fold.MH_multer, 0, Fold.MH_adder);
assertEquals(Fold.MT_folded1, fold.type());
@ -56,7 +56,7 @@ public class FoldTest {
}
@Test
public static void testFold1a() throws Throwable {
public void testFold1a() throws Throwable {
// test foldArguments for folding position 1
MethodHandle fold = MethodHandles.foldArguments(Fold.MH_multer, 1, Fold.MH_adder1);
assertEquals(Fold.MT_folded1, fold.type());
@ -64,7 +64,7 @@ public class FoldTest {
}
@Test
public static void testFold0b() throws Throwable {
public void testFold0b() throws Throwable {
// test foldArguments equivalence with multiple types
MethodHandle fold = MethodHandles.foldArguments(Fold.MH_str, 0, Fold.MH_comb);
assertEquals(Fold.MT_folded2, fold.type());
@ -72,7 +72,7 @@ public class FoldTest {
}
@Test
public static void testFold1b() throws Throwable {
public void testFold1b() throws Throwable {
// test folgArguments for folding position 1, with multiple types
MethodHandle fold = MethodHandles.foldArguments(Fold.MH_str, 1, Fold.MH_comb2);
assertEquals(Fold.MT_folded3, fold.type());
@ -81,7 +81,7 @@ public class FoldTest {
}
@Test
public static void testFoldArgumentsExample() throws Throwable {
public void testFoldArgumentsExample() throws Throwable {
// test the JavaDoc foldArguments-with-pos example
StringWriter swr = new StringWriter();
MethodHandle trace = LOOKUP.findVirtual(StringWriter.class, "write", methodType(void.class, String.class)).bindTo(swr);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @summary unit tests for java.lang.invoke.MethodHandle.invoke
* @compile InvokeGenericTest.java
* @run testng/othervm test.java.lang.invoke.InvokeGenericTest
* @run junit/othervm test.java.lang.invoke.InvokeGenericTest
*/
package test.java.lang.invoke;
@ -34,9 +34,13 @@ import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
import java.lang.reflect.*;
import java.util.*;
import org.testng.*;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
*
@ -68,7 +72,7 @@ public class InvokeGenericTest {
String testName;
static int allPosTests, allNegTests;
int posTests, negTests;
@AfterMethod
@AfterEach
public void printCounts() {
if (verbosity >= 2 && (posTests | negTests) != 0) {
System.out.println();
@ -92,14 +96,14 @@ public class InvokeGenericTest {
testName = name;
}
@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
calledLog.clear();
calledLog.add(null);
nextArgVal = INITIAL_ARG_VAL;
}
@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
int posTests = allPosTests, negTests = allNegTests;
if (verbosity >= 2 && (posTests | negTests) != 0) {
@ -127,7 +131,7 @@ public class InvokeGenericTest {
System.out.println("actual: "+actual);
System.out.println("ex. types: "+getClasses(expected));
System.out.println("act. types: "+getClasses(actual));
assertEquals("previous method call", expected, actual);
assertEquals(expected, actual, "previous method call");
}
static void printCalled(MethodHandle target, String name, Object... args) {
if (verbosity >= 3)
@ -389,8 +393,7 @@ public class InvokeGenericTest {
}
public void testWrongArgumentCount(List<Class<?>> expect, List<Class<?>> observe) throws Throwable {
countTest(false);
if (expect.equals(observe))
assert(false);
assertNotEquals(expect, observe);
MethodHandle target = callable(expect);
Object[] args = zeroArgs(observe);
Object junk;
@ -473,28 +476,25 @@ public class InvokeGenericTest {
mh = MethodHandles.filterReturnValue(mh, toString_MH);
mh = mh.asType(type);
Object res = null;
if (nargs == 2) {
res = mh.invoke((Object)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = mh.invoke((String)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = mh.invoke((Object)args[0], (String)args[1]);
assertEquals(expectString, res);
res = mh.invoke((String)args[0], (String)args[1]);
assertEquals(expectString, res);
res = mh.invoke((String)args[0], (CharSequence)args[1]);
assertEquals(expectString, res);
res = mh.invoke((CharSequence)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = (String) mh.invoke((Object)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = (String) mh.invoke((String)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = (CharSequence) mh.invoke((String)args[0], (Object)args[1]);
assertEquals(expectString, res);
} else {
assert(false); // write this code
}
assertEquals(2, nargs);
res = mh.invoke((Object)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = mh.invoke((String)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = mh.invoke((Object)args[0], (String)args[1]);
assertEquals(expectString, res);
res = mh.invoke((String)args[0], (String)args[1]);
assertEquals(expectString, res);
res = mh.invoke((String)args[0], (CharSequence)args[1]);
assertEquals(expectString, res);
res = mh.invoke((CharSequence)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = (String) mh.invoke((Object)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = (String) mh.invoke((String)args[0], (Object)args[1]);
assertEquals(expectString, res);
res = (CharSequence) mh.invoke((String)args[0], (Object)args[1]);
assertEquals(expectString, res);
//System.out.println(res);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @test
* @bug 8157246
* @summary Tests invocation of MethodHandle with invalid leading argument
* @run testng/othervm test.java.lang.invoke.InvokeMethodHandleWithBadArgument
* @run junit/othervm test.java.lang.invoke.InvokeMethodHandleWithBadArgument
*/
package test.java.lang.invoke;
@ -38,9 +38,9 @@ import java.lang.invoke.VarHandle;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests invocation of MethodHandle with invalid leading argument such as
@ -49,86 +49,100 @@ import org.testng.annotations.*;
public class InvokeMethodHandleWithBadArgument {
// ---- null array reference ----
@Test(expectedExceptions = {NullPointerException.class})
public static void testAsSpreaderPosInvokeWithNull() throws Throwable {
@Test
public void testAsSpreaderPosInvokeWithNull() throws Throwable {
MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 3);
spreader.invoke("A", null, "B");
assertThrows(NullPointerException.class, () -> spreader.invoke("A", null, "B"));
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testAsSpreaderInvokeWithNull() throws Throwable {
@Test
public void testAsSpreaderInvokeWithNull() throws Throwable {
MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 2);
assert ((boolean) spreader.invokeExact(new String[]{"me", "me"}));
boolean eq = (boolean) spreader.invokeExact((String[]) null);
assertTrue((boolean) spreader.invokeExact(new String[]{"me", "me"}));
assertThrows(NullPointerException.class, () -> {
boolean eq = (boolean) spreader.invokeExact((String[]) null);
});
}
// ---- incorrect array element count ----
@Test(expectedExceptions = {IllegalArgumentException.class})
public static void testAsSpreaderPosInvokeWithBadElementCount() throws Throwable {
@Test
public void testAsSpreaderPosInvokeWithBadElementCount() throws Throwable {
MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 3);
spreader.invoke("A", new int[]{1, 2}, "B");
assertThrows(IllegalArgumentException.class, () -> spreader.invoke("A", new int[]{1, 2}, "B"));
}
@Test(expectedExceptions = {IllegalArgumentException.class})
public static void testAsSpreaderInvokeWithBadElementCount() throws Throwable {
@Test
public void testAsSpreaderInvokeWithBadElementCount() throws Throwable {
MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 2);
assert (!(boolean) spreader.invokeExact(new String[]{"me", "thee"}));
boolean eq = (boolean) spreader.invokeExact(new String[0]);
assertFalse((boolean) spreader.invokeExact(new String[]{"me", "thee"}));
assertThrows(IllegalArgumentException.class, () -> {
boolean eq = (boolean) spreader.invokeExact(new String[0]);
});
}
// ---- spread no argument ----
@Test
public static void testAsSpreaderPosInvokeWithZeroLength() throws Throwable {
public void testAsSpreaderPosInvokeWithZeroLength() throws Throwable {
MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 0);
assert("A123B".equals(spreader.invoke("A", (int[])null, 1, 2, 3, "B")));
assertEquals("A123B", spreader.invoke("A", (int[]) null, 1, 2, 3, "B"));
}
@Test
public static void testAsSpreaderInvokeWithZeroLength() throws Throwable {
public void testAsSpreaderInvokeWithZeroLength() throws Throwable {
MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 0);
assert ((boolean) spreader.invokeExact("me", (Object)"me", new String[0]));
assertTrue((boolean) spreader.invokeExact("me", (Object)"me", new String[0]));
boolean eq = (boolean) spreader.invokeExact("me", (Object)"me", (String[]) null);
}
// ---- invokers with null method/var handle argument ----
@Test(expectedExceptions = {NullPointerException.class})
public static void testInvokerWithNull() throws Throwable {
@Test
public void testInvokerWithNull() throws Throwable {
MethodType type = methodType(int.class, int.class, int.class);
MethodHandle invoker = MethodHandles.invoker(type);
assert((int) invoker.invoke(MH_add, 1, 2) == 3);
int sum = (int)invoker.invoke((MethodHandle)null, 1, 2);
assertEquals(3, (int) invoker.invoke(MH_add, 1, 2));
assertThrows(NullPointerException.class, () -> {
int sum = (int)invoker.invoke((MethodHandle)null, 1, 2);
});
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testExactInvokerWithNull() throws Throwable {
@Test
public void testExactInvokerWithNull() throws Throwable {
MethodType type = methodType(int.class, int.class, int.class);
MethodHandle invoker = MethodHandles.exactInvoker(type);
assert((int) invoker.invoke(MH_add, 1, 2) == 3);
int sum = (int)invoker.invokeExact((MethodHandle)null, 1, 2);
assertEquals(3, (int) invoker.invoke(MH_add, 1, 2));
assertThrows(NullPointerException.class, () -> {
int sum = (int)invoker.invokeExact((MethodHandle)null, 1, 2);
});
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testSpreadInvokerWithNull() throws Throwable {
@Test
public void testSpreadInvokerWithNull() throws Throwable {
MethodType type = methodType(boolean.class, String.class, String.class);
MethodHandle invoker = MethodHandles.spreadInvoker(type, 0);
assert ((boolean) invoker.invoke(MH_String_equals, new String[]{"me", "me"}));
boolean eq = (boolean) invoker.invoke((MethodHandle)null, new String[]{"me", "me"});
assertTrue((boolean) invoker.invoke(MH_String_equals, new String[]{"me", "me"}));
assertThrows(NullPointerException.class, () -> {
boolean eq = (boolean) invoker.invoke((MethodHandle)null, new String[]{"me", "me"});
});
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testVarHandleInvokerWithNull() throws Throwable {
@Test
public void testVarHandleInvokerWithNull() throws Throwable {
VarHandle.AccessMode am = VarHandle.AccessMode.GET;
MethodHandle invoker = MethodHandles.varHandleInvoker(am, VH_array.accessModeType(am));
assert ((int) invoker.invoke(VH_array, array, 3) == 3);
int value = (int)invoker.invoke((VarHandle)null, array, 3);
assertEquals(3, (int) invoker.invoke(VH_array, array, 3));
assertThrows(NullPointerException.class, () -> {
int value = (int)invoker.invoke((VarHandle)null, array, 3);
});
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testVarHandleExactInvokerWithNull() throws Throwable {
@Test
public void testVarHandleExactInvokerWithNull() throws Throwable {
VarHandle.AccessMode am = VarHandle.AccessMode.GET;
MethodHandle invoker = MethodHandles.varHandleExactInvoker(am, VH_array.accessModeType(am));
assert ((int) invoker.invoke(VH_array, array, 3) == 3);
int value = (int)invoker.invokeExact((VarHandle)null, array, 3);
assertEquals(3, (int) invoker.invoke(VH_array, array, 3));
assertThrows(NullPointerException.class, () -> {
int value = (int)invoker.invokeExact((VarHandle)null, array, 3);
});
}
static final Lookup LOOKUP = MethodHandles.lookup();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,19 +23,19 @@
/* @test
* @summary basic tests for MethodHandle.invokeWithArguments
* @run testng test.java.lang.invoke.InvokeWithArgumentsTest
* @run junit test.java.lang.invoke.InvokeWithArgumentsTest
*/
package test.java.lang.invoke;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.WrongMethodTypeException;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class InvokeWithArgumentsTest {
static final MethodHandles.Lookup L = MethodHandles.lookup();
@ -49,10 +49,7 @@ public class InvokeWithArgumentsTest {
MethodHandle mh = L.findStatic(L.lookupClass(), "arity",
methodType(Object[].class, Object.class, Object.class, Object[].class));
try {
mh.invokeWithArguments("");
Assert.fail("WrongMethodTypeException expected");
} catch (WrongMethodTypeException e) {}
assertThrows(WrongMethodTypeException.class, () -> mh.invokeWithArguments(""));
}
static Object[] passThrough(String... a) {
@ -72,10 +69,10 @@ public class InvokeWithArgumentsTest {
// Note: the actual array is not preserved, the elements will be
// unpacked and then packed into a new array before invoking the method
String[] expected = (String[]) mh.invokeWithArguments(actual);
String[] result = (String[]) mh.invokeWithArguments(actual);
Assert.assertTrue(actual != expected, "Array should not pass through");
Assert.assertEquals(actual, expected, "Array contents should be equal");
assertNotSame(actual, result, "Array should not pass through");
assertArrayEquals(actual, result, "Array contents should be equal");
}
@Test
@ -89,8 +86,8 @@ public class InvokeWithArgumentsTest {
// will cast to Object become the single element of a new Object[] array
Object[] expected = (Object[]) mh.invokeWithArguments("", actual);
Assert.assertEquals(1, expected.length, "Array should contain just one element");
Assert.assertTrue(actual == expected[0], "Array should pass through");
assertEquals(1, expected.length, "Array should contain just one element");
assertSame(actual, expected[0], "Array should pass through");
}
static void intArray(int... a) {
@ -100,20 +97,14 @@ public class InvokeWithArgumentsTest {
public void testPrimitiveArrayWithNull() throws Throwable {
MethodHandle mh = L.findStatic(L.lookupClass(), "intArray",
methodType(void.class, int[].class));
try {
mh.invokeWithArguments(null, null);
Assert.fail("NullPointerException expected");
} catch (NullPointerException e) {}
assertThrows(NullPointerException.class, () -> mh.invokeWithArguments(null, null));
}
@Test
public void testPrimitiveArrayWithRef() throws Throwable {
MethodHandle mh = L.findStatic(L.lookupClass(), "intArray",
methodType(void.class, int[].class));
try {
mh.invokeWithArguments("A", "B");
Assert.fail("ClassCastException expected");
} catch (ClassCastException e) {}
assertThrows(ClassCastException.class, () -> mh.invokeWithArguments("A", "B"));
}
@ -127,9 +118,6 @@ public class InvokeWithArgumentsTest {
// All numbers, should not throw
mh.invokeWithArguments(1, 1.0, 1.0F, 1L);
try {
mh.invokeWithArguments("A");
Assert.fail("ClassCastException expected");
} catch (ClassCastException e) {}
assertThrows(ClassCastException.class, () -> mh.invokeWithArguments("A"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @summary example code used in javadoc for java.lang.invoke API
* @compile JavaDocExamplesTest.java
* @run testng/othervm test.java.lang.invoke.JavaDocExamplesTest
* @run junit/othervm test.java.lang.invoke.JavaDocExamplesTest
*/
package test.java.lang.invoke;
@ -36,8 +36,8 @@ import static java.lang.invoke.MethodType.*;
import java.util.*;
import org.testng.*;
import org.testng.annotations.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* @author jrose
@ -350,14 +350,14 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
static void assertEquals(Object exp, Object act) {
if (verbosity > 0)
System.out.println("result: "+act);
Assert.assertEquals(exp, act);
Assertions.assertEquals(exp, act);
}
static void assertTrue(boolean b) {
if (verbosity > 0) {
System.out.println("result: " + b);
}
Assert.assertTrue(b);
Assertions.assertTrue(b);
}
@Test public void testMethodHandlesSummary() throws Throwable {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,11 @@
* @summary Tests that Lookup can be produced from classes under java.util.concurrent
* @bug 8154447
* @compile/module=java.base java/util/concurrent/LookupTester.java
* @run testng/othervm JavaUtilConcurrentLookupTest
* @run junit/othervm JavaUtilConcurrentLookupTest
*/
import org.testng.annotations.Test;
import java.util.concurrent.LookupTester;
import org.junit.jupiter.api.Test;
public class JavaUtilConcurrentLookupTest {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,7 +32,7 @@
* @bug 8154751
* @bug 8154754
* @bug 8167974
* @run testng/othervm -ea -esa test.java.lang.invoke.LoopCombinatorTest
* @run junit/othervm -ea -esa test.java.lang.invoke.LoopCombinatorTest
*/
package test.java.lang.invoke;
@ -45,9 +45,12 @@ import java.util.*;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests for the loop combinators introduced in JEP 274.
@ -57,7 +60,7 @@ public class LoopCombinatorTest {
static final Lookup LOOKUP = MethodHandles.lookup();
@Test
public static void testLoopFac() throws Throwable {
public void testLoopFac() throws Throwable {
MethodHandle[] counterClause = new MethodHandle[]{Fac.MH_zero, Fac.MH_inc};
MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin};
MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause);
@ -66,7 +69,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopFacNullInit() throws Throwable {
public void testLoopFacNullInit() throws Throwable {
// null initializer for counter, should initialize to 0
MethodHandle[] counterClause = new MethodHandle[]{null, Fac.MH_inc};
MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin};
@ -76,7 +79,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopNullInit() throws Throwable {
public void testLoopNullInit() throws Throwable {
// null initializer for counter, should initialize to 0, one-clause loop
MethodHandle[] counterClause = new MethodHandle[]{null, Loop.MH_inc, Loop.MH_pred, Loop.MH_fin};
MethodHandle loop = MethodHandles.loop(counterClause);
@ -85,7 +88,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopVoid1() throws Throwable {
public void testLoopVoid1() throws Throwable {
// construct a post-checked loop that only does one iteration and has a void body and void local state
MethodHandle loop = MethodHandles.loop(new MethodHandle[]{Empty.MH_f, Empty.MH_f, Empty.MH_pred, null});
assertEquals(MethodType.methodType(void.class), loop.type());
@ -93,7 +96,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopVoid2() throws Throwable {
public void testLoopVoid2() throws Throwable {
// construct a post-checked loop that only does one iteration and has a void body and void local state,
// initialized implicitly from the step type
MethodHandle loop = MethodHandles.loop(new MethodHandle[]{null, Empty.MH_f, Empty.MH_pred, null});
@ -102,7 +105,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopVoid3() throws Throwable {
public void testLoopVoid3() throws Throwable {
// construct a post-checked loop that only does one iteration and has a void body and void local state,
// and that has a void finalizer
MethodHandle loop = MethodHandles.loop(new MethodHandle[]{null, Empty.MH_f, Empty.MH_pred, Empty.MH_f});
@ -111,7 +114,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopFacWithVoidState() throws Throwable {
public void testLoopFacWithVoidState() throws Throwable {
// like testLoopFac, but with additional void state that outputs a dot
MethodHandle[] counterClause = new MethodHandle[]{Fac.MH_zero, Fac.MH_inc};
MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin};
@ -122,7 +125,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopVoidInt() throws Throwable {
public void testLoopVoidInt() throws Throwable {
// construct a post-checked loop that only does one iteration and has a void body and void local state,
// and that returns a constant
MethodHandle loop = MethodHandles.loop(new MethodHandle[]{null, Empty.MH_f, Empty.MH_pred, Empty.MH_c});
@ -131,7 +134,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopWithVirtuals() throws Throwable {
public void testLoopWithVirtuals() throws Throwable {
// construct a loop (to calculate factorial) that uses a mix of static and virtual methods
MethodHandle[] counterClause = new MethodHandle[]{null, LoopWithVirtuals.permute(LoopWithVirtuals.MH_inc)};
MethodHandle[] accumulatorClause = new MethodHandle[]{
@ -147,7 +150,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testLoopOmitPred() throws Throwable {
public void testLoopOmitPred() throws Throwable {
// construct a loop to calculate factorial that omits a predicate
MethodHandle[] counterClause = new MethodHandle[]{null, Fac.MH_inc, null, Fac.MH_fin};
MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin};
@ -156,7 +159,6 @@ public class LoopCombinatorTest {
assertEquals(120, loop.invoke(5));
}
@DataProvider
static Object[][] negativeTestData() {
MethodHandle i0 = MethodHandles.constant(int.class, 0);
MethodHandle ii = MethodHandles.dropArguments(i0, 0, int.class, int.class);
@ -214,36 +216,36 @@ public class LoopCombinatorTest {
}
}
@Test(dataProvider = "negativeTestData")
public static void testLoopNegative(MethodHandle[][] clauses, String expectedMessage) throws Throwable {
boolean caught = false;
try {
MH_loop.invokeWithArguments((Object[]) clauses);
} catch (IllegalArgumentException iae) {
assertEquals(expectedMessage, iae.getMessage());
caught = true;
}
assertTrue(caught);
@ParameterizedTest
@MethodSource("negativeTestData")
public void testLoopNegative(MethodHandle[][] clauses, String expectedMessage) throws Throwable {
var iae = assertThrows(IllegalArgumentException.class, () -> MH_loop.invokeWithArguments((Object[]) clauses));
assertEquals(expectedMessage, iae.getMessage());
}
@Test(dataProvider = "whileLoopTestData")
public static void testWhileLoop(MethodHandle MH_zero,
MethodHandle MH_pred,
MethodHandle MH_step,
String messageOrNull) throws Throwable {
@ParameterizedTest
@MethodSource("whileLoopPassData")
public void testWhileLoop(MethodHandle MH_zero,
MethodHandle MH_pred,
MethodHandle MH_step) throws Throwable {
// int i = 0; while (i < limit) { ++i; } return i; => limit
try {
MethodHandle loop = MethodHandles.whileLoop(MH_zero, MH_pred, MH_step);
assert messageOrNull == null;
if (MH_step.type().equals(While.MH_step.type()))
assertEquals(While.MT_while, loop.type());
assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type());
while (loop.type().parameterCount() > 1) loop = snip(loop);
assertEquals(23, loop.invoke(23));
} catch (IllegalArgumentException iae) {
assert messageOrNull != null;
assertEqualsFIXME(messageOrNull, iae.getMessage());
}
MethodHandle loop = MethodHandles.whileLoop(MH_zero, MH_pred, MH_step);
if (MH_step.type().equals(While.MH_step.type()))
assertEquals(While.MT_while, loop.type());
assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type());
while (loop.type().parameterCount() > 1) loop = snip(loop);
assertEquals(23, loop.invoke(23));
}
@ParameterizedTest
@MethodSource("whileLoopFailData")
public void testWhileLoopFail(MethodHandle MH_zero,
MethodHandle MH_pred,
MethodHandle MH_step,
String message) throws Throwable {
// int i = 0; while (i < limit) { ++i; } return i; => limit
var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.whileLoop(MH_zero, MH_pred, MH_step));
assertEqualsFIXME(message, iae.getMessage());
}
static void assertEqualsFIXME(String expect, String actual) {
@ -253,8 +255,7 @@ public class LoopCombinatorTest {
}
}
@DataProvider
static Object[][] whileLoopTestData() {
static Object[][] whileLoopPassData() {
MethodHandle
zeroI = While.MH_zero,
zeroX = snip(zeroI),
@ -268,28 +269,44 @@ public class LoopCombinatorTest {
;
return new Object[][] {
// normal while loop clauses, perhaps with effectively-identical reductions
{zeroI, predII, stepII, null},
{zeroX, predII, stepII, null},
{null, predII, stepII, null},
{zeroI, predII, stepII},
{zeroX, predII, stepII},
{null, predII, stepII},
// expanded while loop clauses
{zeroIB, predIIB, stepIIB, null},
{zeroI, predIIB, stepIIB, null},
{null, predIIB, stepIIB, null},
{zeroIB, predII, stepIIB, null},
{zeroX, predII, stepIIB, null},
{null, predII, stepIIB, null},
// short step clauses cause errors
{zeroI, predII, stepIX, "loop predicate must match: (int,int)boolean != (int)boolean"},
{zeroIB, predIX, stepIX, "loop initializer must match: (int,byte)int != ()int"},
// bad body type
{zeroI, predII, tweak(stepII, -1, char.class), "body function must match: (int,int)char != (char,int,int)char"},
{zeroI, predII, tweak(stepII, 0, char.class), "body function must match: (char,int)int != (int,char,int)int"},
// bad pred type
{zeroI, tweak(predII, -1, char.class), stepII, "loop predicate must match: (int,int)char != (int,int)boolean"},
{zeroI, tweak(predII, 0, char.class), stepII, "loop predicate must match: (char,int)boolean != (int,int)boolean"},
// bad init type
{tweak(zeroI, -1, char.class), predII, stepII, "loop initializer must match: (int)char != (int)int"},
{tweak(zeroI, 0, char.class), predII, stepII, "loop initializer must match: (char)int != (int)int"},
{zeroIB, predIIB, stepIIB},
{zeroI, predIIB, stepIIB},
{null, predIIB, stepIIB},
{zeroIB, predII, stepIIB},
{zeroX, predII, stepIIB},
{null, predII, stepIIB},
};
}
static Object[][] whileLoopFailData() {
MethodHandle
zeroI = While.MH_zero,
zeroX = snip(zeroI),
zeroIB = slap(zeroI, byte.class),
predII = While.MH_pred,
predIX = snip(predII),
predIIB = slap(predII, byte.class),
stepII = While.MH_step,
stepIX = snip(stepII),
stepIIB = slap(stepII, byte.class)
;
return new Object[][] {
// short step clauses cause errors
{zeroI, predII, stepIX, "loop predicate must match: (int,int)boolean != (int)boolean"},
{zeroIB, predIX, stepIX, "loop initializer must match: (int,byte)int != ()int"},
// bad body type
{zeroI, predII, tweak(stepII, -1, char.class), "body function must match: (int,int)char != (char,int,int)char"},
{zeroI, predII, tweak(stepII, 0, char.class), "body function must match: (char,int)int != (int,char,int)int"},
// bad pred type
{zeroI, tweak(predII, -1, char.class), stepII, "loop predicate must match: (int,int)char != (int,int)boolean"},
{zeroI, tweak(predII, 0, char.class), stepII, "loop predicate must match: (char,int)boolean != (int,int)boolean"},
// bad init type
{tweak(zeroI, -1, char.class), predII, stepII, "loop initializer must match: (int)char != (int)int"},
{tweak(zeroI, 0, char.class), predII, stepII, "loop initializer must match: (char)int != (int)int"},
};
}
@ -323,53 +340,50 @@ public class LoopCombinatorTest {
}
@Test
public static void testWhileLoopNoIteration() throws Throwable {
public void testWhileLoopNoIteration() throws Throwable {
// a while loop that never executes its body because the predicate evaluates to false immediately
MethodHandle loop = MethodHandles.whileLoop(While.MH_initString, While.MH_predString, While.MH_stepString);
assertEquals(While.MT_string, loop.type());
assertEquals("a", loop.invoke());
}
@Test(dataProvider = "whileLoopTestData")
public static void testDoWhileLoop(MethodHandle MH_zero,
MethodHandle MH_pred,
MethodHandle MH_step,
String messageOrNull) throws Throwable {
@ParameterizedTest
@MethodSource("whileLoopPassData")
public void testDoWhileLoopPass(MethodHandle MH_zero,
MethodHandle MH_pred,
MethodHandle MH_step) throws Throwable {
// int i = 0; do { ++i; } while (i < limit); return i; => limit
try {
MethodHandle loop = MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred);
assert messageOrNull == null;
if (MH_step.type().equals(While.MH_step.type()))
assertEquals(While.MT_while, loop.type());
assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type());
while (loop.type().parameterCount() > 1) loop = snip(loop);
assertEquals(23, loop.invoke(23));
} catch (IllegalArgumentException iae) {
assert messageOrNull != null;
if (!messageOrNull.equals(iae.getMessage())) {
// just issue a warning
System.out.println("*** "+messageOrNull+"\n != "+iae.getMessage());
}
}
MethodHandle loop = MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred);
if (MH_step.type().equals(While.MH_step.type()))
assertEquals(While.MT_while, loop.type());
assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type());
while (loop.type().parameterCount() > 1) loop = snip(loop);
assertEquals(23, loop.invoke(23));
}
@ParameterizedTest
@MethodSource("whileLoopFailData")
public void testDoWhileLoopFail(MethodHandle MH_zero,
MethodHandle MH_pred,
MethodHandle MH_step,
String message) throws Throwable {
// int i = 0; do { ++i; } while (i < limit); return i; => limit
var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred));
assertEqualsFIXME(message, iae.getMessage());
}
@Test
public static void testDoWhileBadInit() throws Throwable {
boolean caught = false;
try {
While w = new While();
MethodHandle loop = MethodHandles.doWhileLoop(MethodHandles.empty(methodType(char.class)),
While.MH_voidBody.bindTo(w),
While.MH_voidPred.bindTo(w));
} catch (IllegalArgumentException iae) {
assertEquals("loop initializer must match: ()char != (int)void", iae.getMessage());
caught = true;
}
assertTrue(caught);
public void testDoWhileBadInit() throws Throwable {
While w = new While();
var iae = assertThrows(IllegalArgumentException.class, () ->
MethodHandles.doWhileLoop(MethodHandles.empty(methodType(char.class)),
While.MH_voidBody.bindTo(w),
While.MH_voidPred.bindTo(w)));
assertEquals("loop initializer must match: ()char != (int)void", iae.getMessage());
}
@Test
public static void testWhileZip() throws Throwable {
public void testWhileZip() throws Throwable {
MethodHandle loop = MethodHandles.doWhileLoop(While.MH_zipInitZip, While.MH_zipStep, While.MH_zipPred);
assertEquals(While.MT_zip, loop.type());
List<String> a = Arrays.asList("a", "b", "c", "d");
@ -379,22 +393,17 @@ public class LoopCombinatorTest {
}
@Test
public static void testWhileBadInit() throws Throwable {
boolean caught = false;
try {
While w = new While();
MethodHandle loop = MethodHandles.whileLoop(MethodHandles.empty(methodType(void.class, char.class)),
While.MH_voidPred.bindTo(w),
While.MH_voidBody.bindTo(w));
} catch (IllegalArgumentException iae) {
assertEquals("loop initializer must match: (char)void != (int)void", iae.getMessage());
caught = true;
}
assertTrue(caught);
public void testWhileBadInit() throws Throwable {
While w = new While();
var iae = assertThrows(IllegalArgumentException.class, () ->
MethodHandles.whileLoop(MethodHandles.empty(methodType(void.class, char.class)),
While.MH_voidPred.bindTo(w),
While.MH_voidBody.bindTo(w)));
assertEquals("loop initializer must match: (char)void != (int)void", iae.getMessage());
}
@Test
public static void testWhileVoidInit() throws Throwable {
public void testWhileVoidInit() throws Throwable {
While w = new While();
int v = 5;
MethodHandle loop = MethodHandles.whileLoop(While.MH_voidInit.bindTo(w), While.MH_voidPred.bindTo(w),
@ -405,7 +414,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testDoWhileVoidInit() throws Throwable {
public void testDoWhileVoidInit() throws Throwable {
While w = new While();
int v = 5;
MethodHandle loop = MethodHandles.doWhileLoop(While.MH_voidInit.bindTo(w), While.MH_voidBody.bindTo(w),
@ -415,24 +424,25 @@ public class LoopCombinatorTest {
assertEquals(v, w.i);
}
@DataProvider
static Object[][] nullArgs() {
MethodHandle c = MethodHandles.constant(int.class, 1);
return new Object[][]{{null, c}, {c, null}};
}
@Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class)
public static void testWhileNullArgs(MethodHandle pred, MethodHandle body) {
MethodHandles.whileLoop(null, pred, body);
@ParameterizedTest
@MethodSource("nullArgs")
public void testWhileNullArgs(MethodHandle pred, MethodHandle body) {
assertThrows(NullPointerException.class, () -> MethodHandles.whileLoop(null, pred, body));
}
@Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class)
public static void testDoWhileNullArgs(MethodHandle body, MethodHandle pred) {
MethodHandles.whileLoop(null, body, pred);
@ParameterizedTest
@MethodSource("nullArgs")
public void testDoWhileNullArgs(MethodHandle body, MethodHandle pred) {
assertThrows(NullPointerException.class, () -> MethodHandles.whileLoop(null, body, pred));
}
@Test
public static void testCountedLoop() throws Throwable {
public void testCountedLoop() throws Throwable {
// String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s; => a variation on a well known theme
MethodHandle fit13 = MethodHandles.dropArguments(MethodHandles.constant(int.class, 13), 0, String.class);
MethodHandle loop = MethodHandles.countedLoop(fit13, Counted.MH_start, Counted.MH_step);
@ -441,7 +451,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedLoopVoidInit() throws Throwable {
public void testCountedLoopVoidInit() throws Throwable {
MethodHandle fit5 = MethodHandles.constant(int.class, 5);
for (int i = 0; i < 8; i++) {
MethodHandle zero = MethodHandles.zero(void.class);
@ -465,7 +475,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedArrayLoop() throws Throwable {
public void testCountedArrayLoop() throws Throwable {
// int[] a = new int[]{0}; for (int i = 0; i < 13; ++i) { ++a[0]; } => a[0] == 13
MethodHandle fit13 = MethodHandles.dropArguments(MethodHandles.constant(int.class, 13), 0, int[].class);
MethodHandle loop = MethodHandles.countedLoop(fit13, null, Counted.MH_stepUpdateArray);
@ -476,37 +486,30 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedPrintingLoop() throws Throwable {
public void testCountedPrintingLoop() throws Throwable {
MethodHandle fit5 = MethodHandles.constant(int.class, 5);
MethodHandle loop = MethodHandles.countedLoop(fit5, null, Counted.MH_printHello);
assertEquals(Counted.MT_countedPrinting, loop.type());
loop.invoke();
}
@Test(expectedExceptions = NullPointerException.class)
public static void testCountedLoopNullBody() throws Throwable {
@Test
public void testCountedLoopNullBody() throws Throwable {
MethodHandle h5 = MethodHandles.constant(int.class, 5);
MethodHandle h13 = MethodHandles.constant(int.class, 13);
MethodHandle loop = MethodHandles.countedLoop(h5, h13, null);
assertEquals(methodType(int.class), loop.type());
assertEquals(13, loop.invoke());
assertThrows(NullPointerException.class, () -> MethodHandles.countedLoop(h5, h13, null));
}
@Test(expectedExceptions = NullPointerException.class)
public static void testCountedLoopNullIterations() throws Throwable {
MethodHandle loop = MethodHandles.countedLoop(null, null, null);
assertEquals(methodType(void.class), loop.type());
loop.invoke();
@Test
public void testCountedLoopNullIterations() throws Throwable {
assertThrows(NullPointerException.class, () -> MethodHandles.countedLoop(null, null, null));
}
@Test(expectedExceptions = NullPointerException.class)
public static void testCountedLoopNullInitAndBody() throws Throwable {
MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, null);
assertEquals(methodType(void.class), loop.type());
loop.invoke();
@Test
public void testCountedLoopNullInitAndBody() throws Throwable {
assertThrows(NullPointerException.class, () -> MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, null));
}
@DataProvider
static Object[][] countedLoopBodyParameters() {
Class<?> V = String.class, I = int.class, A = List.class;
// return types are of these forms:
@ -531,8 +534,9 @@ public class LoopCombinatorTest {
};
}
@Test(dataProvider = "countedLoopBodyParameters")
public static void testCountedLoopBodyParameters(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
@ParameterizedTest
@MethodSource("countedLoopBodyParameters")
public void testCountedLoopBodyParameters(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
MethodHandle loop = MethodHandles.countedLoop(
MethodHandles.empty(countType),
initType == null ? null : MethodHandles.empty(initType),
@ -546,13 +550,14 @@ public class LoopCombinatorTest {
assertEquals(expectType, loop.type());
}
@Test(dataProvider = "countedLoopBodyParameters")
public static void testCountedLoopBodyParametersNullInit(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
@ParameterizedTest
@MethodSource("countedLoopBodyParameters")
public void testCountedLoopBodyParametersNullInit(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
testCountedLoopBodyParameters(countType, null, bodyType);
}
@Test
public static void testCountedLoopStateInitializedToNull() throws Throwable {
public void testCountedLoopStateInitializedToNull() throws Throwable {
MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5),
MethodHandles.empty(methodType(String.class)), Counted.MH_stateBody);
assertEquals(Counted.MT_bodyDeterminesState, loop.type());
@ -560,7 +565,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedLoopArgsDefinedByIterations() throws Throwable {
public void testCountedLoopArgsDefinedByIterations() throws Throwable {
MethodHandle iterations =
MethodHandles.dropArguments(MethodHandles.constant(int.class, 3), 0, String.class);
MethodHandle loop = MethodHandles.countedLoop(iterations,
@ -570,7 +575,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedRangeLoop() throws Throwable {
public void testCountedRangeLoop() throws Throwable {
// String s = "Lambdaman!"; for (int i = -5; i < 8; ++i) { s = "na " + s; } return s; => a well known theme
MethodHandle fitm5 = MethodHandles.dropArguments(Counted.MH_m5, 0, String.class);
MethodHandle fit8 = MethodHandles.dropArguments(Counted.MH_8, 0, String.class);
@ -580,7 +585,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedLoopCounterInit() throws Throwable {
public void testCountedLoopCounterInit() throws Throwable {
// int x = 0; for (int i = 0; i < 5; ++i) { x += i; } return x; => 10
// (only if counter's first value in body is 0)
MethodHandle iter = MethodHandles.constant(int.class, 5);
@ -592,7 +597,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedLoopEmpty() throws Throwable {
public void testCountedLoopEmpty() throws Throwable {
// for (int i = 0; i < 5; ++i) { /* empty */ }
MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null,
MethodHandles.empty(methodType(void.class, int.class)));
@ -601,7 +606,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testCountedRangeLoopEmpty() throws Throwable {
public void testCountedRangeLoopEmpty() throws Throwable {
// for (int i = -5; i < 5; ++i) { /* empty */ }
MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, -5),
MethodHandles.constant(int.class, 5), null, MethodHandles.empty(methodType(void.class, int.class)));
@ -609,7 +614,6 @@ public class LoopCombinatorTest {
loop.invoke();
}
@DataProvider
static Object[][] countedLoopNegativeData() {
MethodHandle dummy = MethodHandles.zero(void.class);
MethodHandle one = MethodHandles.constant(int.class, 1);
@ -629,35 +633,30 @@ public class LoopCombinatorTest {
};
}
@Test(dataProvider = "countedLoopNegativeData")
public static void testCountedLoopNegative(MethodHandle start, MethodHandle end, MethodHandle init,
@ParameterizedTest
@MethodSource("countedLoopNegativeData")
@Disabled //%%%FIXME%%%%
public void testCountedLoopNegative(MethodHandle start, MethodHandle end, MethodHandle init,
MethodHandle body, String msg) {
if (true) return; //%%%FIXME%%%%
boolean caught = false;
try {
MethodHandles.countedLoop(start, end, init, body);
} catch (IllegalArgumentException iae) {
assertEquals(msg, iae.getMessage());
caught = true;
}
assertTrue(caught);
var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.countedLoop(start, end, init, body));
assertEquals(msg, iae.getMessage());
}
@Test
public static void testIterateSum() throws Throwable {
public void testIterateSum() throws Throwable {
// Integer[] a = new Integer[]{1,2,3,4,5,6}; int sum = 0; for (int e : a) { sum += e; } return sum; => 21
MethodHandle loop = MethodHandles.iteratedLoop(Iterate.MH_sumIterator, Iterate.MH_sumInit, Iterate.MH_sumStep);
assertEquals(Iterate.MT_sum, loop.type());
assertEquals(21, loop.invoke(new Integer[]{1, 2, 3, 4, 5, 6}));
}
@DataProvider
static Object[][] iteratorInits() {
return new Object[][]{{Iterate.MH_iteratorFromList}, {Iterate.MH_iteratorFromIterable}, {null}};
}
@Test(dataProvider = "iteratorInits")
public static void testIterateReverse(MethodHandle iterator) throws Throwable {
@ParameterizedTest
@MethodSource("iteratorInits")
public void testIterateReverse(MethodHandle iterator) throws Throwable {
// this test uses List as its loop state type; don't try to change that
if (iterator != null)
iterator = iterator.asType(iterator.type().changeParameterType(0, List.class));
@ -685,8 +684,9 @@ public class LoopCombinatorTest {
}
}
@Test(dataProvider = "iteratorInits")
public static void testIterateLength(MethodHandle iterator) throws Throwable {
@ParameterizedTest
@MethodSource("iteratorInits")
public void testIterateLength(MethodHandle iterator) throws Throwable {
MethodHandle body = Iterate.MH_lengthStep;
MethodHandle init = Iterate.MH_lengthInit;
MethodType expectedType = Iterate.MT_length;
@ -708,8 +708,9 @@ public class LoopCombinatorTest {
}
}
@Test(dataProvider = "iteratorInits")
public static void testIterateMap(MethodHandle iterator) throws Throwable {
@ParameterizedTest
@MethodSource("iteratorInits")
public void testIterateMap(MethodHandle iterator) throws Throwable {
MethodHandle body = Iterate.MH_mapStep;
MethodHandle init = Iterate.MH_mapInit;
MethodType expectedType = Iterate.MT_map;
@ -731,8 +732,9 @@ public class LoopCombinatorTest {
}
}
@Test(dataProvider = "iteratorInits")
public static void testIteratePrint(MethodHandle iterator) throws Throwable {
@ParameterizedTest
@MethodSource("iteratorInits")
public void testIteratePrint(MethodHandle iterator) throws Throwable {
MethodHandle body = Iterate.MH_printStep;
MethodType expectedType = Iterate.MT_print;
int barity = body.type().parameterCount();
@ -747,32 +749,28 @@ public class LoopCombinatorTest {
loop.invoke(Arrays.asList("hello", "world"));
}
@Test(expectedExceptions = NullPointerException.class)
public static void testIterateNullBody() {
MethodHandles.iteratedLoop(MethodHandles.empty(methodType(Iterator.class, int.class)),
MethodHandles.identity(int.class), null);
@Test
public void testIterateNullBody() {
assertThrows(NullPointerException.class, () ->
MethodHandles.iteratedLoop(MethodHandles.empty(methodType(Iterator.class, int.class)),
MethodHandles.identity(int.class), null));
}
@DataProvider
static Object[][] wrongIteratorTypes() {
return new Object[][]{{void.class}, {Object.class}, {Iterable.class}};
}
@Test(dataProvider = "wrongIteratorTypes")
public static void testIterateVoidIterator(Class<?> it) {
boolean caught = false;
@ParameterizedTest
@MethodSource("wrongIteratorTypes")
public void testIterateVoidIterator(Class<?> it) {
MethodType v = methodType(it);
try {
MethodHandles.iteratedLoop(MethodHandles.empty(v), null, MethodHandles.empty(v));
} catch(IllegalArgumentException iae) {
assertEqualsFIXME("iteratedLoop first argument must have Iterator return type", iae.getMessage());
caught = true;
}
assertTrue(caught);
var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.iteratedLoop(MethodHandles.empty(v), null, MethodHandles.empty(v)));
assertEqualsFIXME("iteratedLoop first argument must have Iterator return type", iae.getMessage());
}
@Test(dataProvider = "iteratorInits")
public static void testIterateVoidInit(MethodHandle iterator) throws Throwable {
@ParameterizedTest
@MethodSource("iteratorInits")
public void testIterateVoidInit(MethodHandle iterator) throws Throwable {
// this test uses List as its loop state type; don't try to change that
if (iterator != null)
iterator = iterator.asType(iterator.type().changeParameterType(0, List.class));
@ -781,7 +779,6 @@ public class LoopCombinatorTest {
loop.invoke(Arrays.asList("hello", "world"));
}
@DataProvider
static Object[][] iterateParameters() {
MethodType i = methodType(int.class);
MethodType sil_v = methodType(void.class, String.class, int.class, List.class);
@ -811,8 +808,9 @@ public class LoopCombinatorTest {
};
}
@Test(dataProvider = "iterateParameters")
public static void testIterateParameters(MethodType it, MethodType in, MethodType bo, String msg) {
@ParameterizedTest
@MethodSource("iterateParameters")
public void testIterateParameters(MethodType it, MethodType in, MethodType bo, String msg) {
boolean negative = !msg.isEmpty();
MethodHandle iterator = it == null ? null : MethodHandles.empty(it);
MethodHandle init = in == null ? null : MethodHandles.empty(in);
@ -855,7 +853,7 @@ public class LoopCombinatorTest {
}
@Test
public static void testIteratorSubclass() throws Throwable {
public void testIteratorSubclass() throws Throwable {
MethodHandle loop = MethodHandles.iteratedLoop(MethodHandles.empty(methodType(BogusIterator.class, List.class)),
null, MethodHandles.empty(methodType(void.class, String.class, List.class)));
assertEquals(methodType(void.class, List.class), loop.type());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,20 +24,18 @@
/* @test
* @summary Test MethodHandle::invokeExact and MethodHandle::invoke throws
* UnsupportedOperationException when called via Method::invoke
* @run testng test.java.lang.invoke.MethodHandleInvokeUOE
* @run junit test.java.lang.invoke.MethodHandleInvokeUOE
*/
package test.java.lang.invoke;
import org.testng.*;
import org.testng.annotations.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.Test;
public class MethodHandleInvokeUOE {
@Test

View File

@ -25,8 +25,8 @@
* @test
* @bug 8280377
* @build m1/* m2/* Unnamed
* @run testng/othervm m1/p1.Main
* @run main/othervm Unnamed
* @run junit/othervm m1/p1.Main
* @run junit/othervm Unnamed
* @summary Test MethodHandleProxies::asInterfaceInstance with a default
* method with varargs
*/

View File

@ -26,13 +26,16 @@ import java.lang.invoke.MethodHandleProxies;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import static org.testng.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/*
* Test MethodHandleProxies::asInterfaceInstance with an inaccessible interface
*/
public class Unnamed {
public static void main(String... args) throws Throwable {
@Test
void testInaccessible() throws Throwable {
MethodHandle target = MethodHandles.constant(String.class, "test");
Class<?> intf = Class.forName("p2.TestIntf");
Object t = MethodHandleProxies.asInterfaceInstance(intf, target);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,6 +22,6 @@
*/
module m1 {
requires m2;
requires org.testng;
requires org.junit.platform.console.standalone;
exports p1;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,9 +32,8 @@ import java.util.stream.Collectors;
import p2.TestIntf;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class Main {
public interface A {
@ -57,24 +56,24 @@ public class Main {
* Test the invocation of default methods with varargs
*/
@Test
public static void testVarargsMethods() throws Throwable {
public void testVarargsMethods() throws Throwable {
MethodHandle target = MethodHandles.lookup().findStatic(Main.class,
"concat", MethodType.methodType(String.class, Object[].class));
C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);
assertEquals(proxy.c("a", "b", "c"), "abc");
assertEquals(proxy.aConcat("a", "b", "c"), "[a, b, c]");
assertEquals(proxy.aConcat(new Object[] { "a", "b", "c" }), "[a, b, c]");
assertEquals(proxy.bConcat(new Object[] { "a", "b", "c" }), "[a, b, c]");
assertEquals("abc", proxy.c("a", "b", "c"));
assertEquals("[a, b, c]", proxy.aConcat("a", "b", "c"));
assertEquals("[a, b, c]", proxy.aConcat(new Object[] { "a", "b", "c" }));
assertEquals("[a, b, c]", proxy.bConcat(new Object[] { "a", "b", "c" }));
}
/*
* Test the invocation of a default method of an accessible interface
*/
@Test
public static void modulePrivateInterface() {
public void modulePrivateInterface() {
MethodHandle target = MethodHandles.constant(String.class, "test");
TestIntf t = MethodHandleProxies.asInterfaceInstance(TestIntf.class, target);
assertEquals(t.test(), "test");
assertEquals("test", t.test());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,33 +24,33 @@
/*
* @test
* @bug 8255398
* @run testng TestDropReturn
* @run junit TestDropReturn
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class TestDropReturn {
@Test(dataProvider = "dropReturnCases")
@ParameterizedTest
@MethodSource("dropReturnCases")
public void testDropReturn(Class<?> cls, Object testValue) throws Throwable {
MethodHandle mh = MethodHandles.identity(cls);
assertEquals(mh.type(), methodType(cls, cls));
assertEquals(methodType(cls, cls), mh.type());
Object x = mh.invoke(testValue);
assertEquals(x, testValue);
assertEquals(testValue, x);
mh = MethodHandles.dropReturn(mh);
assertEquals(mh.type(), methodType(void.class, cls));
assertEquals(methodType(void.class, cls), mh.type());
mh.invoke(testValue); // should at least work
}
@DataProvider
public static Object[][] dropReturnCases() {
return new Object[][]{
{ boolean.class, true },

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,13 +23,9 @@
/*
* @test
* @run testng/othervm -Xverify:all TestTableSwitch
* @run junit/othervm -Xverify:all TestTableSwitch
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import javax.management.ObjectName;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@ -38,7 +34,11 @@ import java.util.List;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;
import static org.testng.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.*;
public class TestTableSwitch {
@ -111,7 +111,6 @@ public class TestTableSwitch {
return args;
}
@DataProvider
public static Object[][] nonVoidCases() {
List<Object[]> tests = new ArrayList<>();
@ -126,10 +125,11 @@ public class TestTableSwitch {
}
private static void check(List<Object> testValues, Object[] collectedValues) {
assertEquals(collectedValues, testValues.toArray());
assertArrayEquals(testValues.toArray(), collectedValues);
}
@Test(dataProvider = "nonVoidCases")
@ParameterizedTest
@MethodSource("nonVoidCases")
public void testNonVoidHandles(Class<?> type, int numCases, List<Class<?>> additionalTypes) throws Throwable {
MethodHandle collector = MH_check;
List<Object> testArguments = new ArrayList<>();
@ -158,19 +158,19 @@ public class TestTableSwitch {
testArguments.add(testValue(additionalType));
}
assertEquals(mhSwitch.invokeWithArguments(testArguments(-1, testArguments)), defaultReturnValue);
assertEquals(defaultReturnValue, mhSwitch.invokeWithArguments(testArguments(-1, testArguments)));
for (int i = 0; i < numCases; i++) {
assertEquals(mhSwitch.invokeWithArguments(testArguments(i, testArguments)), returnValues[i]);
assertEquals(returnValues[i], mhSwitch.invokeWithArguments(testArguments(i, testArguments)));
}
assertEquals(mhSwitch.invokeWithArguments(testArguments(numCases, testArguments)), defaultReturnValue);
assertEquals(defaultReturnValue, mhSwitch.invokeWithArguments(testArguments(numCases, testArguments)));
}
@Test
public void testVoidHandles() throws Throwable {
IntFunction<MethodHandle> makeTestCase = expectedIndex -> {
IntConsumer test = actualIndex -> assertEquals(actualIndex, expectedIndex);
IntConsumer test = actualIndex -> assertEquals(expectedIndex, actualIndex);
return MH_IntConsumer_accept.bindTo(test);
};
@ -187,48 +187,48 @@ public class TestTableSwitch {
mhSwitch.invokeExact((int) 2);
}
@Test(expectedExceptions = NullPointerException.class)
@Test
public void testNullDefaultHandle() {
MethodHandles.tableSwitch(null, simpleTestCase("test"));
assertThrows(NullPointerException.class, () -> MethodHandles.tableSwitch(null, simpleTestCase("test")));
}
@Test(expectedExceptions = NullPointerException.class)
@Test
public void testNullCases() {
MethodHandle[] cases = null;
MethodHandles.tableSwitch(simpleTestCase("default"), cases);
assertThrows(NullPointerException.class, () ->
MethodHandles.tableSwitch(simpleTestCase("default"), cases));
}
@Test(expectedExceptions = NullPointerException.class)
@Test
public void testNullCase() {
MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), null);
assertThrows(NullPointerException.class, () -> MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), null));
}
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = ".*Not enough cases.*")
@Test
public void testNotEnoughCases() {
MethodHandles.tableSwitch(simpleTestCase("default"));
assertThrows(IllegalArgumentException.class, () -> MethodHandles.tableSwitch(simpleTestCase("default")));
}
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = ".*Case actions must have int as leading parameter.*")
@Test
public void testNotEnoughParameters() {
MethodHandle empty = MethodHandles.empty(MethodType.methodType(void.class));
MethodHandles.tableSwitch(empty, empty, empty);
assertThrows(IllegalArgumentException.class, () ->
MethodHandles.tableSwitch(empty, empty, empty));
}
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = ".*Case actions must have int as leading parameter.*")
@Test
public void testNoLeadingIntParameter() {
MethodHandle empty = MethodHandles.empty(MethodType.methodType(void.class, double.class));
MethodHandles.tableSwitch(empty, empty, empty);
assertThrows(IllegalArgumentException.class, () ->
MethodHandles.tableSwitch(empty, empty, empty));
}
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = ".*Case actions must have the same type.*")
@Test
public void testWrongCaseType() {
// doesn't return a String
MethodHandle wrongType = MethodHandles.empty(MethodType.methodType(void.class, int.class));
MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), wrongType);
assertThrows(IllegalArgumentException.class, () ->
MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), wrongType));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @test
* @bug 8230501
* @library /test/lib
* @run testng/othervm ClassDataTest
* @run junit/othervm ClassDataTest
*/
import java.io.IOException;
@ -54,13 +54,14 @@ import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.lang.classfile.ClassFile.*;
import static java.lang.constant.ConstantDescs.*;
import static java.lang.invoke.MethodHandles.Lookup.*;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class ClassDataTest {
private static final Lookup LOOKUP = MethodHandles.lookup();
@ -72,10 +73,10 @@ public class ClassDataTest {
assertTrue(lookup.hasFullPrivilegeAccess());
int value = MethodHandles.classData(lookup, "_", int.class);
assertEquals(value, 20);
assertEquals(20, value);
Integer i = MethodHandles.classData(lookup, "_", Integer.class);
assertEquals(i.intValue(), 20);
assertEquals(20, i.intValue());
}
/*
@ -86,8 +87,7 @@ public class ClassDataTest {
assertNull(MethodHandles.classData(LOOKUP, "_", Object.class));
}
@DataProvider(name = "teleportedLookup")
private Object[][] teleportedLookup() throws ReflectiveOperationException {
private static Object[][] teleportedLookup() throws ReflectiveOperationException {
Lookup lookup = hiddenClass(30);
Class<?> hc = lookup.lookupClass();
assertClassData(lookup, 30);
@ -100,32 +100,33 @@ public class ClassDataTest {
};
}
@Test(dataProvider = "teleportedLookup", expectedExceptions = { IllegalAccessException.class })
@ParameterizedTest
@MethodSource("teleportedLookup")
public void illegalAccess(Lookup lookup, int access) throws IllegalAccessException {
int lookupModes = lookup.lookupModes();
assertTrue((lookupModes & ORIGINAL) == 0);
assertEquals(lookupModes, access);
MethodHandles.classData(lookup, "_", int.class);
assertEquals(0, lookupModes & ORIGINAL);
assertEquals(access, lookupModes);
assertThrows(IllegalAccessException.class, () -> MethodHandles.classData(lookup, "_", int.class));
}
@Test(expectedExceptions = { ClassCastException.class })
@Test
public void incorrectType() throws IllegalAccessException {
Lookup lookup = hiddenClass(20);
MethodHandles.classData(lookup, "_", Long.class);
assertThrows(ClassCastException.class, () -> MethodHandles.classData(lookup, "_", Long.class));
}
@Test(expectedExceptions = { IndexOutOfBoundsException.class })
@Test
public void invalidIndex() throws IllegalAccessException {
Lookup lookup = hiddenClass(List.of());
MethodHandles.classDataAt(lookup, "_", Object.class, 0);
assertThrows(IndexOutOfBoundsException.class, () -> MethodHandles.classDataAt(lookup, "_", Object.class, 0));
}
@Test(expectedExceptions = { NullPointerException.class })
@Test
public void unboxNull() throws IllegalAccessException {
List<Integer> list = new ArrayList<>();
list.add(null);
Lookup lookup = hiddenClass(list);
MethodHandles.classDataAt(lookup, "_", int.class, 0);
assertThrows(NullPointerException.class, () -> MethodHandles.classDataAt(lookup, "_", int.class, 0));
}
@Test
@ -133,7 +134,7 @@ public class ClassDataTest {
List<Object> list = new ArrayList<>();
list.add(null);
Lookup lookup = hiddenClass(list);
assertTrue(MethodHandles.classDataAt(lookup, "_", Object.class, 0) == null);
assertNull(MethodHandles.classDataAt(lookup, "_", Object.class, 0));
}
@Test
@ -142,7 +143,7 @@ public class ClassDataTest {
byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, int.class).build();
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, 100, true);
int value = MethodHandles.classData(lookup, "_", int.class);
assertEquals(value, 100);
assertEquals(100, value);
// call through condy
assertClassData(lookup, 100);
}
@ -153,7 +154,7 @@ public class ClassDataTest {
byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, float.class).build();
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, 0.1234f, true);
float value = MethodHandles.classData(lookup, "_", float.class);
assertEquals(value, 0.1234f);
assertEquals(0.1234f, value);
// call through condy
assertClassData(lookup, 0.1234f);
}
@ -165,7 +166,7 @@ public class ClassDataTest {
byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, Class.class).build();
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, hc, true);
Class<?> value = MethodHandles.classData(lookup, "_", Class.class);
assertEquals(value, hc);
assertEquals(hc, value);
// call through condy
assertClassData(lookup, hc);
}
@ -181,7 +182,7 @@ public class ClassDataTest {
colors[0] = "black";
// it will get back the modified class data
String[] value = MethodHandles.classData(lookup, "_", String[].class);
assertEquals(value, colors);
assertArrayEquals(colors, value);
// even call through condy as it's not a constant
assertClassData(lookup, colors);
}
@ -194,7 +195,7 @@ public class ClassDataTest {
int expected = 102; // element at index=2
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, cd, true);
int value = MethodHandles.classDataAt(lookup, "_", int.class, 2);
assertEquals(value, expected);
assertEquals(expected, value);
// call through condy
assertClassData(lookup, expected);
}
@ -208,7 +209,7 @@ public class ClassDataTest {
int expected = 101; // element at index=1
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, cd, true);
int value = MethodHandles.classDataAt(lookup, "_", int.class, 1);
assertEquals(value, expected);
assertEquals(expected, value);
// call through condy
assertClassData(lookup, expected);
}
@ -216,20 +217,12 @@ public class ClassDataTest {
private static Lookup hiddenClass(int value) {
ClassByteBuilder builder = new ClassByteBuilder("HC");
byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, int.class).build();
try {
return LOOKUP.defineHiddenClassWithClassData(bytes, value, true);
} catch (Throwable e) {
throw new RuntimeException(e);
}
return assertDoesNotThrow(() -> LOOKUP.defineHiddenClassWithClassData(bytes, value, true));
}
private static Lookup hiddenClass(List<?> list) {
ClassByteBuilder builder = new ClassByteBuilder("HC");
byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, List.class).build();
try {
return LOOKUP.defineHiddenClassWithClassData(bytes, list, true);
} catch (Throwable e) {
throw new RuntimeException(e);
}
return assertDoesNotThrow(() -> LOOKUP.defineHiddenClassWithClassData(bytes, list, true));
}
@Test
@ -242,7 +235,7 @@ public class ClassDataTest {
Class<?> hc = hcLookup.lookupClass();
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, hc, true);
Class<?> value = MethodHandles.classData(lookup, "_", Class.class);
assertEquals(value, hc);
assertEquals(hc, value);
// call through condy
Class<?> c = lookup.lookupClass();
assertClassData(lookup, c.newInstance(), hc);
@ -257,7 +250,7 @@ public class ClassDataTest {
int expected = 102; // element at index=2
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, cd, true);
int value = MethodHandles.classDataAt(lookup, "_", int.class, 2);
assertEquals(value, expected);
assertEquals(expected, value);
// call through condy
Class<?> c = lookup.lookupClass();
assertClassData(lookup, c.newInstance() ,expected);
@ -285,13 +278,13 @@ public class ClassDataTest {
Class<?> c = lookup.lookupClass();
assertClassData(lookup, c.newInstance(), mtype);
// modify the class data
assertTrue(cd.remove(0) == mtype);
assertSame(mtype, cd.remove(0));
cd.add(0, MethodType.methodType(void.class));
MethodType newMType = cd.get(0);
// loading the element using condy returns the original value
assertClassData(lookup, c.newInstance(), mtype);
// direct invocation of MethodHandles.classDataAt returns the modified value
assertEquals(MethodHandles.classDataAt(lookup, "_", MethodType.class, 0), newMType);
assertEquals(newMType, MethodHandles.classDataAt(lookup, "_", MethodType.class, 0));
}
// helper method to extract from a class data map
@ -334,7 +327,7 @@ public class ClassDataTest {
assertEquals(mh, v1);
}
@Test(expectedExceptions = { IllegalArgumentException.class })
@Test
public void nonDefaultName() throws ReflectiveOperationException {
ClassByteBuilder builder = new ClassByteBuilder("nonDefaultName");
byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, Class.class)
@ -342,7 +335,7 @@ public class ClassDataTest {
Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, ClassDataTest.class, true);
assertClassData(lookup, ClassDataTest.class);
// throw IAE
MethodHandles.classData(lookup, "non_default_name", Class.class);
assertThrows(IllegalArgumentException.class, () -> MethodHandles.classData(lookup, "non_default_name", Class.class));
}
static class ClassByteBuilder {
@ -428,7 +421,7 @@ public class ClassDataTest {
* Load an int constant from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, int value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, int value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
int v = (int) m.invoke(null);
@ -439,7 +432,7 @@ public class ClassDataTest {
* Load an int constant from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, Object o, int value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, Object o, int value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
int v = (int) m.invoke(o);
@ -450,7 +443,7 @@ public class ClassDataTest {
* Load a float constant from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, float value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, float value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
float v = (float) m.invoke(null);
@ -461,7 +454,7 @@ public class ClassDataTest {
* Load a Class constant from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, Class<?> value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, Class<?> value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
Class<?> v = (Class<?>)m.invoke(null);
@ -472,7 +465,7 @@ public class ClassDataTest {
* Load a Class from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, Object o, Class<?> value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, Object o, Class<?> value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
Object v = m.invoke(o);
@ -483,18 +476,29 @@ public class ClassDataTest {
* Load an Object from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, Object value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, Object value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
Object v = m.invoke(null);
assertEquals(value, v);
}
/*
* Load an Object array from class data via condy and
* verify it matches the given value in content.
*/
private static void assertClassData(Lookup lookup, Object[] value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
Object v = m.invoke(null);
assertArrayEquals(value, (Object[]) v);
}
/*
* Load an Object from class data via condy and
* verify it matches the given value.
*/
private void assertClassData(Lookup lookup, Object o, Object value) throws ReflectiveOperationException {
private static void assertClassData(Lookup lookup, Object o, Object value) throws ReflectiveOperationException {
Class<?> c = lookup.lookupClass();
Method m = c.getMethod("classData");
Object v = m.invoke(o);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,16 +24,15 @@
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/**
* @test
* @bug 8235521
* @summary Tests for Lookup::ensureClassInitialized
* @build java.base/* m1/* m2/* Main
* @run testng/othervm --add-modules m1 Main
* @run junit/othervm --add-modules m1 Main
*/
public class Main {
@ -48,20 +47,20 @@ public class Main {
}
// access denied to package-private java.lang class
@Test(expectedExceptions = { IllegalAccessException.class })
@Test
public void testPackagePrivate() throws Exception {
Class<?> c = Class.forName("java.lang.DefaultInit", false, null);
assertFalse(Helper.isInitialized(c));
// access denied
MethodHandles.lookup().ensureInitialized(c);
assertThrows(IllegalAccessException.class, () -> MethodHandles.lookup().ensureInitialized(c));
}
// access denied to public class in a non-exported package
@Test(expectedExceptions = { IllegalAccessException.class })
@Test
public void testNonExportedPackage() throws Exception {
Class<?> c = Class.forName("jdk.internal.misc.VM", false, null);
// access denied
MethodHandles.lookup().ensureInitialized(c);
assertThrows(IllegalAccessException.class, () -> MethodHandles.lookup().ensureInitialized(c));
}
// invoke p1.Test::test to test module boundary access
@ -72,9 +71,9 @@ public class Main {
m.invoke(null);
}
@Test(expectedExceptions = { IllegalArgumentException.class })
@Test
public void testArrayType() throws Exception {
Class<?> arrayType = PublicInit.class.arrayType();
MethodHandles.lookup().ensureInitialized(arrayType);
assertThrows(IllegalArgumentException.class, () -> MethodHandles.lookup().ensureInitialized(arrayType));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,6 @@
/**
* @test
* @build test/* m1/* m2/* m3/* Unnamed
* @run testng/othervm test/p.PrivateLookupInTests
* @run junit/othervm test/p.PrivateLookupInTests
* @summary Unit tests for MethodHandles.privateLookupIn
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,6 +22,6 @@
*/
module test {
requires org.testng;
exports p to org.testng; // TestNG invokes the public methods
requires org.junit.platform.console.standalone;
exports p to org.junit.platform.console.standalone; // JUnit invokes the public methods in PrivateLookupInTests
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,15 +29,14 @@ import java.lang.reflect.Modifier;
import static java.lang.invoke.MethodHandles.Lookup.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
/**
* Unit tests for MethodHandles.privateLookupIn
*/
@Test
public class PrivateLookupInTests {
/**
* A public and non-public types in the test module but in a different
@ -52,24 +51,25 @@ public class PrivateLookupInTests {
* private static final Object obj = ...
* }
*/
private Class<?> publicType;
private Class<?> nonPublicType;
private static Class<?> publicType;
private static Class<?> nonPublicType;
// initialize and sanity check publicType/nonPublicType
@BeforeTest
public void init() throws Exception {
@BeforeAll
public static void init() throws Exception {
publicType = Class.forName("p.internal.PublicType");
assertTrue(this.getClass().getModule() == publicType.getModule());
assertNotEquals(this.getClass().getPackageName(), publicType.getPackageName());
assertSame(PrivateLookupInTests.class.getModule(), publicType.getModule());
assertNotEquals(publicType.getPackageName(), PrivateLookupInTests.class.getPackageName());
assertTrue(Modifier.isPublic(publicType.getModifiers()));
nonPublicType = Class.forName("p.internal.NonPublicType");
assertTrue(this.getClass().getModule() == nonPublicType.getModule());
assertNotEquals(this.getClass().getPackageName(), nonPublicType.getPackageName());
assertSame(PrivateLookupInTests.class.getModule(), nonPublicType.getModule());
assertNotEquals(nonPublicType.getPackageName(), PrivateLookupInTests.class.getPackageName());
assertFalse(Modifier.isPublic(nonPublicType.getModifiers()));
}
// Invoke MethodHandles.privateLookupIn with a full-power caller
@Test
public void testAllAccessCallerSameModule() throws Throwable {
Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, MethodHandles.lookup());
assertTrue(lookup.lookupClass() == nonPublicType);
@ -82,29 +82,31 @@ public class PrivateLookupInTests {
}
// Invoke MethodHandles.privateLookupIn with a reduced-power caller
@Test(expectedExceptions = {IllegalAccessException.class})
@Test
public void testReducedAccessCallerSameModule() throws Throwable {
Lookup caller = MethodHandles.lookup().dropLookupMode(PACKAGE);
assertTrue((caller.lookupModes() & PRIVATE) == 0);
assertTrue((caller.lookupModes() & PACKAGE) == 0);
assertTrue((caller.lookupModes() & MODULE) != 0);
assertTrue((caller.lookupModes() & ORIGINAL) == 0);
Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, caller);
assertEquals(0, caller.lookupModes() & PRIVATE);
assertEquals(0, caller.lookupModes() & PACKAGE);
assertNotEquals(0, caller.lookupModes() & MODULE);
assertEquals(0, caller.lookupModes() & ORIGINAL);
assertThrows(IllegalAccessException.class, () ->
MethodHandles.privateLookupIn(nonPublicType, caller));
}
// Invoke MethodHandles.privateLookupIn with the public lookup as caller
@Test(expectedExceptions = {IllegalAccessException.class})
@Test
public void testPublicLookupSameModule() throws Exception {
Lookup caller = MethodHandles.publicLookup();
Lookup lookup = MethodHandles.privateLookupIn(publicType, caller);
assertThrows(IllegalAccessException.class, () ->
MethodHandles.privateLookupIn(publicType, caller));
}
// test reads m1, open module m1 containing p1
@Test
public void testTargetClassInOpenModule() throws Throwable {
// m1/p1.Type
Class<?> clazz = Class.forName("p1.Type");
assertEquals(clazz.getModule().getName(), "m1");
assertEquals("m1", clazz.getModule().getName());
// ensure that this module reads m1
Module thisModule = getClass().getModule();
@ -113,9 +115,9 @@ public class PrivateLookupInTests {
assertTrue(m1.isOpen("p1", thisModule));
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
assertTrue(lookup.lookupClass() == clazz);
assertTrue((lookup.lookupModes() & PRIVATE) == PRIVATE);
assertTrue((lookup.lookupModes() & MODULE) == 0);
assertSame(clazz, lookup.lookupClass());
assertEquals(PRIVATE, lookup.lookupModes() & PRIVATE);
assertEquals(0, lookup.lookupModes() & MODULE);
// get obj field
MethodHandle mh = lookup.findStaticGetter(clazz, "obj", Object.class);
@ -123,6 +125,7 @@ public class PrivateLookupInTests {
}
// test target class in unnamed module
@Test
public void testTargetClassInUnnamedModule() throws Throwable {
Class<?> clazz = Class.forName("Unnamed");
assertFalse(clazz.getModule().isNamed());
@ -130,76 +133,72 @@ public class PrivateLookupInTests {
// thisModule does not read the unnamed module
Module thisModule = getClass().getModule();
assertFalse(thisModule.canRead(clazz.getModule()));
try {
MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
assertTrue(false);
} catch (IllegalAccessException expected) { }
var baseLookup = MethodHandles.lookup();
assertThrows(IllegalAccessException.class, () -> MethodHandles.privateLookupIn(clazz, baseLookup));
// thisModule reads the unnamed module
thisModule.addReads(clazz.getModule());
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
assertTrue(lookup.lookupClass() == clazz);
assertTrue((lookup.lookupModes() & PRIVATE) == PRIVATE);
assertTrue((lookup.lookupModes() & MODULE) == 0);
Lookup lookup = MethodHandles.privateLookupIn(clazz, baseLookup);
assertSame(clazz, lookup.lookupClass());
assertEquals(PRIVATE, (lookup.lookupModes() & PRIVATE));
assertEquals(0, (lookup.lookupModes() & MODULE));
}
// test does not read m2, m2 opens p2 to test
@Test(expectedExceptions = {IllegalAccessException.class})
@Test
public void testCallerDoesNotRead() throws Throwable {
// m2/p2.Type
Class<?> clazz = Class.forName("p2.Type");
assertEquals(clazz.getModule().getName(), "m2");
assertEquals("m2", clazz.getModule().getName());
Module thisModule = getClass().getModule();
Module m2 = clazz.getModule();
assertFalse(thisModule.canRead(m2));
assertTrue(m2.isOpen("p2", thisModule));
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
assertThrows(IllegalAccessException.class, () ->
MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()));
}
// test reads m3, m3 does not open p3 to test
@Test(expectedExceptions = {IllegalAccessException.class})
@Test
public void testNotOpenToCaller() throws Throwable {
// m3/p2.Type
Class<?> clazz = Class.forName("p3.Type");
assertEquals(clazz.getModule().getName(), "m3");
assertEquals("m3", clazz.getModule().getName());
Module thisModule = getClass().getModule();
Module m3 = clazz.getModule();
thisModule.addReads(clazz.getModule());
assertFalse(m3.isOpen("p3", thisModule));
Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
assertThrows(IllegalAccessException.class, () ->
MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()));
}
// Invoke MethodHandles.privateLookupIn with a primitive class
@Test(expectedExceptions = {IllegalArgumentException.class})
@Test
public void testPrimitiveClassAsTargetClass() throws Exception {
MethodHandles.privateLookupIn(int.class, MethodHandles.lookup());
assertThrows(IllegalArgumentException.class, () -> MethodHandles.privateLookupIn(int.class, MethodHandles.lookup()));
}
// Invoke MethodHandles.privateLookupIn with an array class
@Test(expectedExceptions = {IllegalArgumentException.class})
@Test
public void testArrayClassAsTargetClass() throws Exception {
MethodHandles.privateLookupIn(PrivateLookupInTests[].class, MethodHandles.lookup());
assertThrows(IllegalArgumentException.class, () -> MethodHandles.privateLookupIn(PrivateLookupInTests[].class, MethodHandles.lookup()));
}
// Invoke MethodHandles.privateLookupIn with a primitive array class
@Test(expectedExceptions = {IllegalArgumentException.class})
@Test
public void testPrimitiveArrayClassAsTargetClass() throws Exception {
MethodHandles.privateLookupIn(int[].class, MethodHandles.lookup());
assertThrows(IllegalArgumentException.class, () -> MethodHandles.privateLookupIn(int[].class, MethodHandles.lookup()));
}
// Invoke MethodHandles.privateLookupIn with null
@Test(expectedExceptions = {NullPointerException.class})
@Test
public void testNullTargetClass() throws Exception {
MethodHandles.privateLookupIn(null, MethodHandles.lookup());
assertThrows(NullPointerException.class, () -> MethodHandles.privateLookupIn(null, MethodHandles.lookup()));
}
// Invoke MethodHandles.privateLookupIn with null
@Test(expectedExceptions = {NullPointerException.class})
@Test
public void testNullCaller() throws Exception {
MethodHandles.privateLookupIn(getClass(), null);
assertThrows(NullPointerException.class, () -> MethodHandles.privateLookupIn(getClass(), null));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,18 +23,17 @@
/* @test
* @bug 8259922
* @run testng/othervm MethodHandlesCollectArgsTest
* @run junit/othervm MethodHandlesCollectArgsTest
*/
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class MethodHandlesCollectArgsTest {
@ -43,7 +42,6 @@ public class MethodHandlesCollectArgsTest {
private static final MethodHandle FILTER_INT = MethodHandles.empty(methodType(int.class, String.class));
private static final MethodHandle FILTER_VOID = MethodHandles.empty(methodType(void.class, String.class));
@DataProvider(name = "illegalPos")
public static Object[][] illegalPos() {
return new Object[][] {
{TARGET_II_I, 2, FILTER_INT},
@ -57,7 +55,6 @@ public class MethodHandlesCollectArgsTest {
};
}
@DataProvider(name = "validPos")
public static Object[][] validPos() {
return new Object[][] {
{TARGET_II_I, 0, FILTER_INT, methodType(int.class, String.class, int.class)},
@ -69,14 +66,16 @@ public class MethodHandlesCollectArgsTest {
};
}
@Test(dataProvider="illegalPos", expectedExceptions = {IllegalArgumentException.class})
@ParameterizedTest
@MethodSource("illegalPos")
public void illegalPosition(MethodHandle target, int position, MethodHandle filter) {
MethodHandles.collectArguments(target, position, filter);
assertThrows(IllegalArgumentException.class, () -> MethodHandles.collectArguments(target, position, filter));
}
@Test(dataProvider="validPos")
@ParameterizedTest
@MethodSource("validPos")
public void legalPosition(MethodHandle target, int position, MethodHandle filter, MethodType expectedType) {
MethodHandle result = MethodHandles.collectArguments(target, position, filter);
assertEquals(result.type(), expectedType);
assertEquals(expectedType, result.type());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -60,6 +60,7 @@ import java.util.Map;
import static java.lang.invoke.MethodType.methodType;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
public class MethodHandlesGeneralTest extends MethodHandlesTest {
@ -398,7 +399,7 @@ public class MethodHandlesGeneralTest extends MethodHandlesTest {
Object obj = target.invokeWithArguments(args);
if (!(defc == Example.class && params.length < 2))
assertCalled(defc.getSimpleName()+".<init>", args);
assertTrue("instance of "+defc.getName(), defc.isInstance(obj));
assertInstanceOf(defc, obj);
}
@Test
@ -971,8 +972,7 @@ public class MethodHandlesGeneralTest extends MethodHandlesTest {
arrayToMH = new SubIntExample[length];
else
return; // can't make an ArrayStoreException test
assert(arrayType.isInstance(arrayToMH))
: Arrays.asList(arrayType, arrayToMH.getClass(), testSetter, negTest);
assertInstanceOf(arrayType, arrayToMH, () -> Arrays.asList(testSetter, negTest).toString());
break;
}
countTest(positive);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @bug 8366028
* @summary unit tests for java.lang.invoke.MethodType
* @compile MethodTypeTest.java
* @run testng/othervm test.java.lang.invoke.MethodTypeTest
* @run junit/othervm test.java.lang.invoke.MethodTypeTest
*/
package test.java.lang.invoke;
@ -35,11 +35,13 @@ import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.*;
import org.testng.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.testng.Assert.assertThrows;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
/**
*
@ -57,7 +59,7 @@ public class MethodTypeTest {
private MethodType[] GALLERY;
private Method compareTo;
@BeforeMethod
@BeforeEach
public void setUp() throws Exception {
rtype = void.class;
ptypes = new Class<?>[] { int.class, String.class };
@ -98,7 +100,7 @@ public class MethodTypeTest {
};
}
@AfterMethod
@AfterEach
public void tearDown() throws Exception {
}
@ -107,7 +109,7 @@ public class MethodTypeTest {
public void testDistinct() {
List<MethodType> gallery2 = new ArrayList<>();
for (MethodType mt : GALLERY) {
assertFalse(mt.toString(), gallery2.contains(mt));
assertFalse(gallery2.contains(mt), mt.toString());
gallery2.add(mt);
}
// check self-equality also:
@ -198,9 +200,9 @@ public class MethodTypeTest {
for (int i = 0; i < instances.length; i++) {
MethodType instance = instances[i];
String result = instance.toMethodDescriptorString();
assertEquals("#"+i, expResults[i], result);
assertEquals(expResults[i], result, "#"+i);
MethodType parsed = MethodType.fromMethodDescriptorString(result, loader);
assertSame("--#"+i, instance, parsed);
assertSame(instance, parsed, "--#"+i);
}
}
private static String concat(Object... parts) {
@ -221,8 +223,7 @@ public class MethodTypeTest {
return sb.toString().replace('.', '/');
}
@DataProvider(name = "badMethodDescriptorStrings")
public String[] badMethodDescriptorStrings() {
public static String[] badMethodDescriptorStrings() {
return new String[] {
"(I)",
"(V)V",
@ -239,9 +240,12 @@ public class MethodTypeTest {
}
// JDK-8366028
@Test(dataProvider = "badMethodDescriptorStrings", expectedExceptions = IllegalArgumentException.class)
@ParameterizedTest
@MethodSource("badMethodDescriptorStrings")
public void testFromMethodDescriptorStringNegatives(String desc) {
MethodType.fromMethodDescriptorString(desc, null);
assertThrows(IllegalArgumentException.class, () -> {
MethodType.fromMethodDescriptorString(desc, null);
});
}
@Test
@ -251,7 +255,7 @@ public class MethodTypeTest {
boolean[] expResults = {true, false, true, false, true, true, false, true};
for (int i = 0; i < instances.length; i++) {
boolean result = instances[i].hasPrimitives();
assertEquals("#"+i, expResults[i], result);
assertEquals(expResults[i], result, "#"+i);
}
}
@ -263,7 +267,7 @@ public class MethodTypeTest {
for (int i = 0; i < instances.length; i++) {
System.out.println(" hasWrappers "+instances[i]);
boolean result = instances[i].hasWrappers();
assertEquals("#"+i, expResults[i], result);
assertEquals(expResults[i], result, "#"+i);
}
}
@ -274,7 +278,7 @@ public class MethodTypeTest {
MethodType[] expResults = {mt_viO, mt_OO2, mt_vv, mt_Ov, mt_iO2, mt_OOi, mt_OO2, mt_iOi};
for (int i = 0; i < instances.length; i++) {
MethodType result = instances[i].erase();
assertSame("#"+i, expResults[i], result);
assertSame(expResults[i], result, "#"+i);
}
}
@ -285,7 +289,7 @@ public class MethodTypeTest {
MethodType[] expResults = {mt_OO2, mt_OO2, mt_Ov, mt_Ov, mt_OO2, mt_OO2, mt_OO2, mt_OO2};
for (int i = 0; i < instances.length; i++) {
MethodType result = instances[i].generic();
assertSame("#"+i, expResults[i], result);
assertSame(expResults[i], result, "#"+i);
}
}
@ -296,7 +300,7 @@ public class MethodTypeTest {
MethodType[] expResults = {mt_VIS, mt_OO2, mt_Vv, mt_Ov, mt_ISI, mt_ISI, mt_ISI, mt_ISI};
for (int i = 0; i < instances.length; i++) {
MethodType result = instances[i].wrap();
assertSame("#"+i, expResults[i], result);
assertSame(expResults[i], result, "#"+i);
}
}
@ -307,7 +311,7 @@ public class MethodTypeTest {
MethodType[] expResults = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSi, mt_iSi, mt_iSi, mt_iSi};
for (int i = 0; i < instances.length; i++) {
MethodType result = instances[i].unwrap();
assertSame("#"+i, expResults[i], result);
assertSame(expResults[i], result, "#"+i);
}
}
@ -436,7 +440,7 @@ public class MethodTypeTest {
MethodType instance = instances[i];
String result = instance.toString();
System.out.println("#"+i+":"+result);
assertEquals("#"+i, expResults[i], result);
assertEquals(expResults[i], result, "#"+i);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,21 +24,21 @@
/* @test
* @bug 8184119
* @summary test permutation when return value is directly derived from an argument
* @run testng/othervm test.java.lang.invoke.PermuteArgsReturnVoidTest
* @run junit/othervm test.java.lang.invoke.PermuteArgsReturnVoidTest
*/
package test.java.lang.invoke;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodHandles.dropArguments;
import static java.lang.invoke.MethodHandles.identity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PermuteArgsReturnVoidTest {
@ -65,8 +65,8 @@ public class PermuteArgsReturnVoidTest {
MethodHandle p = MethodHandles.permuteArguments(f, MethodType.methodType(String.class, String.class, int.class, int.class), 0, 2, 1);
String s = (String) p.invoke("IN", 0, 0);
Assert.assertEquals(s.getClass(), String.class);
Assert.assertEquals(s, "IN");
assertEquals(String.class, s.getClass());
assertEquals("IN", s);
}
@Test
@ -84,7 +84,7 @@ public class PermuteArgsReturnVoidTest {
MethodHandle p = MethodHandles.permuteArguments(f, MethodType.methodType(String.class, String.class, int.class, int.class), 0, 2, 1);
String s = (String) p.invoke("IN", 0, 0);
Assert.assertEquals(s.getClass(), String.class);
Assert.assertEquals(s, "IN");
assertEquals(String.class, s.getClass());
assertEquals("IN", s);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @summary unit tests for method handles which permute their arguments
* @library /test/lib /java/lang/invoke/common
* @run testng/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -ea -esa -DPermuteArgsTest.MAX_ARITY=8 test.java.lang.invoke.PermuteArgsTest
* @run junit/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -ea -esa -DPermuteArgsTest.MAX_ARITY=8 test.java.lang.invoke.PermuteArgsTest
*/
/* Examples of manual runs:
@ -35,7 +35,6 @@
package test.java.lang.invoke;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
import java.lang.invoke.MethodHandle;
@ -52,6 +51,10 @@ import static java.lang.invoke.MethodHandles.Lookup;
import static java.lang.invoke.MethodHandles.lookup;
import static java.lang.invoke.MethodHandles.permuteArguments;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PermuteArgsTest {
private static final Class<?> CLASS = PermuteArgsTest.class;
@ -259,11 +262,11 @@ public class PermuteArgsTest {
reverse(perm, 0, perm.length);
}
switch (perm.length) {
case 2: assert(testCases - testCases0 == 2); break;
case 3: assert(testCases - testCases0 == 6); break;
case 4: assert(testCases - testCases0 == 24); break;
case 5: assert(testCases - testCases0 == 120); break;
case 6: assert(testCases - testCases0 > 720/3); break;
case 2 -> assertEquals(2, testCases - testCases0);
case 3 -> assertEquals(6, testCases - testCases0);
case 4 -> assertEquals(24, testCases - testCases0);
case 5 -> assertEquals(120, testCases - testCases0);
case 6 -> assertTrue(testCases - testCases0 > 720/3);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @bug 8139885
* @bug 8143798
* @run testng/othervm -ea -esa test.java.lang.invoke.SpreadCollectTest
* @run junit/othervm -ea -esa test.java.lang.invoke.SpreadCollectTest
*/
package test.java.lang.invoke;
@ -39,9 +39,11 @@ import java.util.*;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests for the new asSpreader/asCollector API added in JEP 274.
@ -51,14 +53,14 @@ public class SpreadCollectTest {
static final Lookup LOOKUP = MethodHandles.lookup();
@Test
public static void testAsSpreader() throws Throwable {
public void testAsSpreader() throws Throwable {
MethodHandle spreader = SpreadCollect.MH_forSpreading.asSpreader(1, int[].class, 3);
assertEquals(SpreadCollect.MT_spreader, spreader.type());
assertEquals("A456B", (String) spreader.invoke("A", new int[]{4, 5, 6}, "B"));
}
@Test
public static void testAsSpreaderExample() throws Throwable {
public void testAsSpreaderExample() throws Throwable {
// test the JavaDoc asSpreader-with-pos example
MethodHandle compare = LOOKUP.findStatic(Objects.class, "compare", methodType(int.class, Object.class, Object.class, Comparator.class));
MethodHandle compare2FromArray = compare.asSpreader(0, Object[].class, 2);
@ -66,49 +68,43 @@ public class SpreadCollectTest {
Comparator<Integer> cmp = (a, b) -> a - b;
assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 0, 2), cmp) < 0);
assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 1, 3), cmp) > 0);
assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 2, 4), cmp) == 0);
assertEquals(0, (int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 2, 4), cmp));
}
@DataProvider
static Object[][] asSpreaderIllegalPositions() {
return new Object[][]{{-7}, {3}, {19}};
}
@Test(dataProvider = "asSpreaderIllegalPositions")
public static void testAsSpreaderIllegalPos(int p) throws Throwable {
boolean caught = false;
try {
SpreadCollect.MH_forSpreading.asSpreader(p, Object[].class, 3);
} catch (IllegalArgumentException iae) {
assertEquals("bad spread position", iae.getMessage());
caught = true;
}
assertTrue(caught);
}
@Test(expectedExceptions = {WrongMethodTypeException.class})
public static void testAsSpreaderIllegalMethodType() {
MethodHandle h = MethodHandles.dropArguments(MethodHandles.constant(String.class, ""), 0, int.class, int.class);
MethodHandle s = h.asSpreader(String[].class, 1);
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testAsSpreaderNullArrayType() {
SpreadCollect.MH_forSpreading.asSpreader(null, 0);
}
@Test(expectedExceptions = {NullPointerException.class})
public static void testAsSpreaderNullArrayNonZeroLength() {
SpreadCollect.MH_forSpreading.asSpreader(null, 1);
}
@Test(expectedExceptions = {IllegalArgumentException.class})
public static void testAsSpreaderTooManyParams() throws Throwable {
SpreadCollect.MH_forSpreading.asSpreader(1, int[].class, 6);
@ParameterizedTest
@MethodSource("asSpreaderIllegalPositions")
public void testAsSpreaderIllegalPos(int p) throws Throwable {
var iae = assertThrows(IllegalArgumentException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(p, Object[].class, 3));
assertEquals("bad spread position", iae.getMessage());
}
@Test
public static void testAsCollector() throws Throwable {
public void testAsSpreaderIllegalMethodType() {
MethodHandle h = MethodHandles.dropArguments(MethodHandles.constant(String.class, ""), 0, int.class, int.class);
assertThrows(WrongMethodTypeException.class, () -> h.asSpreader(String[].class, 1));
}
@Test
public void testAsSpreaderNullArrayType() {
assertThrows(NullPointerException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(null, 0));
}
@Test
public void testAsSpreaderNullArrayNonZeroLength() {
assertThrows(NullPointerException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(null, 1));
}
@Test
public void testAsSpreaderTooManyParams() throws Throwable {
assertThrows(IllegalArgumentException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(1, int[].class, 6));
}
@Test
public void testAsCollector() throws Throwable {
MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 1);
assertEquals(SpreadCollect.MT_collector1, collector.type());
assertEquals("A4B", (String) collector.invoke("A", 4, "B"));
@ -121,7 +117,7 @@ public class SpreadCollectTest {
}
@Test
public static void testAsCollectorInvokeWithArguments() throws Throwable {
public void testAsCollectorInvokeWithArguments() throws Throwable {
MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 1);
assertEquals(SpreadCollect.MT_collector1, collector.type());
assertEquals("A4B", (String) collector.invokeWithArguments("A", 4, "B"));
@ -134,7 +130,7 @@ public class SpreadCollectTest {
}
@Test
public static void testAsCollectorLeading() throws Throwable {
public void testAsCollectorLeading() throws Throwable {
MethodHandle collector = SpreadCollect.MH_forCollectingLeading.asCollector(0, int[].class, 1);
assertEquals(SpreadCollect.MT_collectorLeading1, collector.type());
assertEquals("7Q", (String) collector.invoke(7, "Q"));
@ -147,7 +143,7 @@ public class SpreadCollectTest {
}
@Test
public static void testAsCollectorLeadingInvokeWithArguments() throws Throwable {
public void testAsCollectorLeadingInvokeWithArguments() throws Throwable {
MethodHandle collector = SpreadCollect.MH_forCollectingLeading.asCollector(0, int[].class, 1);
assertEquals(SpreadCollect.MT_collectorLeading1, collector.type());
assertEquals("7Q", (String) collector.invokeWithArguments(7, "Q"));
@ -160,31 +156,25 @@ public class SpreadCollectTest {
}
@Test
public static void testAsCollectorNone() throws Throwable {
public void testAsCollectorNone() throws Throwable {
MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 0);
assertEquals(SpreadCollect.MT_collector0, collector.type());
assertEquals("AB", (String) collector.invoke("A", "B"));
}
@DataProvider
static Object[][] asCollectorIllegalPositions() {
return new Object[][]{{-1}, {17}};
}
@Test(dataProvider = "asCollectorIllegalPositions")
public static void testAsCollectorIllegalPos(int p) {
boolean caught = false;
try {
SpreadCollect.MH_forCollecting.asCollector(p, int[].class, 0);
} catch (IllegalArgumentException iae) {
assertEquals("bad collect position", iae.getMessage());
caught = true;
}
assertTrue(caught);
@ParameterizedTest
@MethodSource("asCollectorIllegalPositions")
public void testAsCollectorIllegalPos(int p) {
var iae = assertThrows(IllegalArgumentException.class, () -> SpreadCollect.MH_forCollecting.asCollector(p, int[].class, 0));
assertEquals("bad collect position", iae.getMessage());
}
@Test
public static void testAsCollectorExample() throws Throwable {
public void testAsCollectorExample() throws Throwable {
// test the JavaDoc asCollector-with-pos example
StringWriter swr = new StringWriter();
MethodHandle swWrite = LOOKUP.

View File

@ -23,12 +23,9 @@
/* @test
* @bug 8265079
* @run testng/othervm -Xverify:all TestVHInvokerCaching
* @run junit/othervm -Xverify:all TestVHInvokerCaching
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@ -37,12 +34,16 @@ import java.util.ArrayList;
import java.util.List;
import static java.lang.invoke.MethodHandles.lookup;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class TestVHInvokerCaching {
@Test(dataProvider = "testHandles")
public static void testVHIInvokerCaching(VarHandle testHandle) throws Throwable {
@ParameterizedTest
@MethodSource("testHandles")
public void testVHIInvokerCaching(VarHandle testHandle) throws Throwable {
for (VarHandle.AccessMode mode : VarHandle.AccessMode.values()) {
MethodHandle handle1 = MethodHandles.varHandleInvoker(mode, testHandle.accessModeType(mode));
MethodHandle handle2 = MethodHandles.varHandleInvoker(mode, testHandle.accessModeType(mode));
@ -56,7 +57,6 @@ public class TestVHInvokerCaching {
}
}
@DataProvider
public static Object[][] testHandles() throws NoSuchFieldException, IllegalAccessException {
List<VarHandle> testHandles = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,14 +23,11 @@
/* @test
* @summary unit tests for method handles which permute their arguments
* @run testng test.java.lang.invoke.ThrowExceptionsTest
* @run junit test.java.lang.invoke.ThrowExceptionsTest
*/
package test.java.lang.invoke;
import org.testng.*;
import org.testng.annotations.*;
import java.util.*;
import java.lang.reflect.*;
@ -38,6 +35,10 @@ import java.lang.invoke.*;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ThrowExceptionsTest {
private static final Class<?> CLASS = ThrowExceptionsTest.class;
private static final Lookup LOOKUP = lookup();
@ -51,7 +52,7 @@ public class ThrowExceptionsTest {
// mostly call testWMTCallee, but sometimes call its void-returning variant
MethodHandle mh = testWMTCallee();
MethodHandle mh1 = mh.asType(mh.type().changeReturnType(void.class));
assert(mh1 != mh);
assertNotSame(mh, mh1);
testWMT(mh, mh1, 1000);
}
@ -108,7 +109,7 @@ public class ThrowExceptionsTest {
MethodHandle[] cell = { null }; // recursion point
MethodHandle getCell = insertArguments(arrayElementGetter(cell.getClass()), 0, cell, 0);
MethodHandle invokeCell = foldArguments(exactInvoker(cellType), getCell);
assert(invokeCell.type() == cellType);
assertSame(cellType, invokeCell.type());
cell[0] = invokeCell;
// make it conformable to any type:
invokeCell = dropArguments(invokeCell, 0, Object[].class).asVarargsCollector(Object[].class);
@ -189,7 +190,6 @@ public class ThrowExceptionsTest {
try {
// FIXME: should not have to retype this
n = (int) mh.invokeExact((Object)this, "x");
assertEquals(n, i - catches);
// Using the exact type for this causes endless deopt due to
// 'non_cached_result' in SystemDictionary::find_method_handle_invoke.
// The problem is that the compiler thread needs to access a cached
@ -198,7 +198,9 @@ public class ThrowExceptionsTest {
} catch (Exception ex) {
savedEx = ex;
catches++;
continue;
}
assertEquals(i - catches, n);
}
//VERBOSE: System.out.println("reps="+reps+" catches="+catches);
return savedEx;
@ -220,9 +222,4 @@ public class ThrowExceptionsTest {
}
return savedEx;
}
private static void assertEquals(Object x, Object y) {
if (x == y || x != null && x.equals(y)) return;
throw new RuntimeException(x+" != "+y);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @bug 8139885 8150824 8150825 8194238 8233920
* @run testng/othervm -ea -esa -Xverify:all test.java.lang.invoke.TryFinallyTest
* @run junit/othervm -ea -esa -Xverify:all test.java.lang.invoke.TryFinallyTest
*/
package test.java.lang.invoke;
@ -35,9 +35,12 @@ import java.lang.invoke.MethodType;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for the tryFinally method handle combinator introduced in JEP 274.
@ -47,13 +50,12 @@ public class TryFinallyTest {
static final Lookup LOOKUP = MethodHandles.lookup();
@Test
public static void testTryFinally() throws Throwable {
public void testTryFinally() throws Throwable {
MethodHandle hello = MethodHandles.tryFinally(TryFinally.MH_greet, TryFinally.MH_exclaim);
assertEquals(TryFinally.MT_hello, hello.type());
assertEquals("Hello, world!", hello.invoke("world"));
}
@DataProvider
static Object[][] tryFinallyArgs() {
return new Object[][] {
{ boolean.class, true },
@ -68,8 +70,9 @@ public class TryFinallyTest {
};
}
@Test(dataProvider = "tryFinallyArgs")
public static void testTryFinally(Class<?> argType, Object arg) throws Throwable {
@ParameterizedTest
@MethodSource("tryFinallyArgs")
public void testTryFinally(Class<?> argType, Object arg) throws Throwable {
MethodHandle identity = MethodHandles.identity(argType);
MethodHandle tryFinally = MethodHandles.tryFinally(
identity,
@ -78,31 +81,31 @@ public class TryFinallyTest {
assertEquals(arg, tryFinally.invoke(arg));
}
@Test(dataProvider = "tryFinallyArgs", expectedExceptions = TryFinally.T1.class)
public static void testTryFinallyException(Class<?> argType, Object arg) throws Throwable {
@ParameterizedTest
@MethodSource("tryFinallyArgs")
public void testTryFinallyException(Class<?> argType, Object arg) throws Throwable {
MethodHandle identity = TryFinally.MH_throwingTargetIdentity.asType(methodType(argType, argType));
MethodHandle tryFinally = MethodHandles.tryFinally(
identity,
MethodHandles.dropArguments(identity, 0, TryFinally.T1.class));
assertEquals(methodType(argType, argType), tryFinally.type());
tryFinally.invoke(arg); // should throw
assertThrows(TryFinally.T1.class, () -> tryFinally.invoke(arg));
}
@Test
public static void testTryFinallyVoid() throws Throwable {
public void testTryFinallyVoid() throws Throwable {
MethodHandle tfVoid = MethodHandles.tryFinally(TryFinally.MH_print, TryFinally.MH_printMore);
assertEquals(TryFinally.MT_printHello, tfVoid.type());
tfVoid.invoke("world");
}
@Test
public static void testTryFinallySublist() throws Throwable {
public void testTryFinallySublist() throws Throwable {
MethodHandle helloMore = MethodHandles.tryFinally(TryFinally.MH_greetMore, TryFinally.MH_exclaimMore);
assertEquals(TryFinally.MT_moreHello, helloMore.type());
assertEquals("Hello, world and universe (but world first)!", helloMore.invoke("world", "universe"));
}
@DataProvider
static Object[][] omitTrailingArguments() {
MethodHandle c = TryFinally.MH_voidCleanup;
return new Object[][]{
@ -114,13 +117,13 @@ public class TryFinallyTest {
};
}
@Test(dataProvider = "omitTrailingArguments")
public static void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable {
@ParameterizedTest
@MethodSource("omitTrailingArguments")
public void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable {
MethodHandle tf = MethodHandles.tryFinally(TryFinally.MH_dummyTarget, cleanup);
tf.invoke(1, 2L, "a", 23, 42L, "b");
}
@DataProvider
static Object[][] negativeTestData() {
MethodHandle intid = MethodHandles.identity(int.class);
MethodHandle intco = MethodHandles.constant(int.class, 0);
@ -145,29 +148,18 @@ public class TryFinallyTest {
};
}
@Test(dataProvider = "negativeTestData")
public static void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) {
boolean caught = false;
try {
MethodHandles.tryFinally(target, cleanup);
} catch (IllegalArgumentException iae) {
assertEquals(expectedMessage, iae.getMessage());
caught = true;
}
assertTrue(caught);
@ParameterizedTest
@MethodSource("negativeTestData")
public void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) {
var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.tryFinally(target, cleanup));
assertEquals(expectedMessage, iae.getMessage());
}
@Test
public static void testTryFinallyThrowableCheck() {
public void testTryFinallyThrowableCheck() {
MethodHandle mh = MethodHandles.tryFinally(TryFinally.MH_throwingTarget,
TryFinally.MH_catchingCleanup);
try {
mh.invoke();
fail("ClassCastException expected");
} catch (Throwable t) {
assertTrue("Throwable not assignable to ClassCastException: " + t,
ClassCastException.class.isAssignableFrom(t.getClass()));
}
assertThrows(ClassCastException.class, mh::invoke);
}
static class TryFinally {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,19 +23,18 @@
/* @test
* @summary unit tests for java.lang.invoke.MethodHandles
* @run testng/othervm -ea -esa test.java.lang.invoke.VarArgsTest
* @run junit/othervm -ea -esa test.java.lang.invoke.VarArgsTest
*/
package test.java.lang.invoke;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.Arrays;
import java.util.List;
import static java.lang.invoke.MethodHandles.*;
import static java.lang.invoke.MethodType.*;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class VarArgsTest {
@ -61,17 +60,17 @@ public class VarArgsTest {
MethodHandle asList = publicLookup()
.findStatic(Arrays.class, "asList", methodType(List.class, Object[].class));
MethodHandle asListWithVarargs = asList.withVarargs(asList.isVarargsCollector());
assert(asListWithVarargs.isVarargsCollector());
assertTrue(asListWithVarargs.isVarargsCollector());
assertEquals("[]", asListWithVarargs.invoke().toString());
assertEquals("[1]", asListWithVarargs.invoke(1).toString());
assertEquals("[two, too]", asListWithVarargs.invoke("two", "too").toString());
}
@Test(expectedExceptions = { IllegalArgumentException.class })
@Test
public void testWithVarargsIAE() throws Throwable {
MethodHandle lenMH = publicLookup()
.findVirtual(String.class, "length", methodType(int.class));
MethodHandle lenMHWithVarargs = lenMH.withVarargs(true);
.findVirtual(String.class, "length", methodType(int.class));
assertThrows(IllegalArgumentException.class, () -> lenMH.withVarargs(true));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,9 +21,6 @@
* questions.
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -32,6 +29,7 @@ import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.api.BeforeAll;
public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest {
@ -338,7 +336,7 @@ public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest {
bavss.add(dbb_offset_unaligned_ro);
}
@BeforeClass
@BeforeAll
public void setup() {
setupByteSources();
vhss = setupVarHandleSources(true);
@ -346,13 +344,10 @@ public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest {
abstract List<VarHandleSource> setupVarHandleSources(boolean same);
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
return vhss.stream().map(cvh -> new Object[]{cvh}).toArray(Object[][]::new);
}
@DataProvider
public Object[][] typesProvider() throws Exception {
List<java.lang.Class<?>> aepts = Arrays.asList(byte[].class, int.class);
List<java.lang.Class<?>> bbpts = Arrays.asList(ByteBuffer.class, int.class);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@ import java.util.Map;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
abstract class VarHandleBaseTest {
static final int ITERS = Integer.getInteger("iters", 1);
@ -136,18 +136,7 @@ abstract class VarHandleBaseTest {
static void checkWithThrowable(Class<? extends Throwable> re,
Object message,
ThrowingRunnable r) {
Throwable _e = null;
try {
r.run();
}
catch (Throwable e) {
_e = e;
}
message = message == null ? "" : message + ". ";
assertNotNull(_e, String.format("%sNo throwable thrown. Expected %s", message, re));
if (!re.isInstance(_e)) {
fail(String.format("%sIncorrect throwable thrown, %s. Expected %s", message, _e, re), _e);
}
assertThrows(re, r::run, message == null ? null : message.toString());
}
@ -277,11 +266,11 @@ abstract class VarHandleBaseTest {
}
private static MethodHandle bind(VarHandle vh, MethodHandle mh, MethodType emt) {
assertEquals(mh.type(), emt.insertParameterTypes(0, VarHandle.class),
assertEquals(emt.insertParameterTypes(0, VarHandle.class), mh.type(),
"MethodHandle type differs from access mode type");
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
assertEquals(info.getMethodType(), emt,
assertEquals(emt, info.getMethodType(),
"MethodHandleInfo method type differs from access mode type");
return mh.bindTo(vh);
@ -472,39 +461,39 @@ abstract class VarHandleBaseTest {
for (TestAccessMode accessMode : testAccessModes()) {
MethodType amt = vh.accessModeType(accessMode.toAccessMode());
assertEquals(amt.parameterList().subList(0, pts.size()), pts);
assertEquals(pts, amt.parameterList().subList(0, pts.size()));
}
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET)) {
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
assertEquals(mt.returnType(), vh.varType());
assertEquals(mt.parameterList(), pts);
assertEquals(vh.varType(), mt.returnType());
assertEquals(pts, mt.parameterList());
}
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.SET)) {
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
assertEquals(mt.returnType(), void.class);
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
assertEquals(void.class, mt.returnType());
assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1));
}
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
assertEquals(mt.returnType(), boolean.class);
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType());
assertEquals(boolean.class, mt.returnType());
assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1));
assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 2));
}
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
assertEquals(mt.returnType(), vh.varType());
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType());
assertEquals(vh.varType(), mt.returnType());
assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1));
assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 2));
}
for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET_AND_SET, TestAccessType.GET_AND_ADD)) {
MethodType mt = vh.accessModeType(testAccessMode.toAccessMode());
assertEquals(mt.returnType(), vh.varType());
assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType());
assertEquals(vh.varType(), mt.returnType());
assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,12 @@
* @test
* @bug 8195650
* @summary Test linking of method references to VarHandle access methods.
* @run testng VarHandleMethodReferenceTest
* @run junit VarHandleMethodReferenceTest
*/
import org.testng.annotations.Test;
import java.lang.invoke.*;
import org.junit.jupiter.api.Test;
public class VarHandleMethodReferenceTest {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,28 +23,30 @@
/*
* @test
* @run testng/othervm -Diters=10 -Xint VarHandleTestAccessDouble
* @run junit/othervm -Diters=10 -Xint VarHandleTestAccessDouble
*
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
*
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessDouble
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessDouble
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessDouble
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessDouble
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessDouble
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessDouble
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestAccessDouble extends VarHandleBaseTest {
static final double static_final_v = 1.0d;
@ -108,7 +110,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
return vhs.toArray(new VarHandle[0]);
}
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestAccessDouble.class, "final_v", double.class);
@ -125,8 +127,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(double[].class);
}
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
List<VarHandle> vhs = new ArrayList<>();
vhs.add(vhField);
@ -156,7 +156,8 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("varHandlesProvider")
public void testIsAccessModeSupported(VarHandle vh) {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
@ -194,8 +195,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@DataProvider
public Object[][] typesProvider() throws Exception {
List<Object[]> types = new ArrayList<>();
types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessDouble.class)});
@ -205,16 +204,16 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
return types.stream().toArray(Object[][]::new);
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<Class<?>> pts) {
assertEquals(vh.varType(), double.class);
assertEquals(double.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@Test
public void testLookupInstanceToStatic() {
checkIAE("Lookup of static final field to instance final field", () -> {
@ -241,8 +240,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
});
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -284,7 +281,8 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -297,26 +295,26 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
// Plain
{
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "get double value");
assertEquals(1.0d, x, "get double value");
}
// Volatile
{
double x = (double) vh.getVolatile(recv);
assertEquals(x, 1.0d, "getVolatile double value");
assertEquals(1.0d, x, "getVolatile double value");
}
// Lazy
{
double x = (double) vh.getAcquire(recv);
assertEquals(x, 1.0d, "getRelease double value");
assertEquals(1.0d, x, "getRelease double value");
}
// Opaque
{
double x = (double) vh.getOpaque(recv);
assertEquals(x, 1.0d, "getOpaque double value");
assertEquals(1.0d, x, "getOpaque double value");
}
}
@ -381,26 +379,26 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
// Plain
{
double x = (double) vh.get();
assertEquals(x, 1.0d, "get double value");
assertEquals(1.0d, x, "get double value");
}
// Volatile
{
double x = (double) vh.getVolatile();
assertEquals(x, 1.0d, "getVolatile double value");
assertEquals(1.0d, x, "getVolatile double value");
}
// Lazy
{
double x = (double) vh.getAcquire();
assertEquals(x, 1.0d, "getRelease double value");
assertEquals(1.0d, x, "getRelease double value");
}
// Opaque
{
double x = (double) vh.getOpaque();
assertEquals(x, 1.0d, "getOpaque double value");
assertEquals(1.0d, x, "getOpaque double value");
}
}
@ -466,7 +464,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
{
vh.set(recv, 1.0d);
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "set double value");
assertEquals(1.0d, x, "set double value");
}
@ -474,21 +472,21 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
{
vh.setVolatile(recv, 2.0d);
double x = (double) vh.getVolatile(recv);
assertEquals(x, 2.0d, "setVolatile double value");
assertEquals(2.0d, x, "setVolatile double value");
}
// Lazy
{
vh.setRelease(recv, 1.0d);
double x = (double) vh.getAcquire(recv);
assertEquals(x, 1.0d, "setRelease double value");
assertEquals(1.0d, x, "setRelease double value");
}
// Opaque
{
vh.setOpaque(recv, 2.0d);
double x = (double) vh.getOpaque(recv);
assertEquals(x, 2.0d, "setOpaque double value");
assertEquals(2.0d, x, "setOpaque double value");
}
vh.set(recv, 1.0d);
@ -498,56 +496,56 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
boolean r = vh.compareAndSet(recv, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "success compareAndSet double value");
assertEquals(2.0d, x, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(recv, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "failing compareAndSet double value");
assertEquals(2.0d, x, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success compareAndExchange double value");
assertEquals(1.0d, x, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
assertEquals(1.0d, x, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
assertEquals(1.0d, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
assertEquals(1.0d, x, "failing compareAndExchangeRelease double value");
}
{
@ -558,14 +556,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = vh.weakCompareAndSetPlain(recv, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value");
}
{
@ -576,14 +574,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
assertEquals(1.0d, x, "success weakCompareAndSetAcquire double");
}
{
boolean success = vh.weakCompareAndSetAcquire(recv, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -594,14 +592,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
assertEquals(2.0d, x, "success weakCompareAndSetRelease double");
}
{
boolean success = vh.weakCompareAndSetRelease(recv, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value");
assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value");
}
{
@ -612,14 +610,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "success weakCompareAndSet double value");
assertEquals(1.0d, x, "success weakCompareAndSet double value");
}
{
boolean success = vh.weakCompareAndSet(recv, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 1.0d, "failing weakCompareAndSet double value");
assertEquals(1.0d, x, "failing weakCompareAndSet double value");
}
// Compare set and get
@ -627,27 +625,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.set(recv, 1.0d);
double o = (double) vh.getAndSet(recv, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
assertEquals(1.0d, o, "getAndSet double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "getAndSet double value");
assertEquals(2.0d, x, "getAndSet double value");
}
{
vh.set(recv, 1.0d);
double o = (double) vh.getAndSetAcquire(recv, 2.0d);
assertEquals(o, 1.0d, "getAndSetAcquire double");
assertEquals(1.0d, o, "getAndSetAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "getAndSetAcquire double value");
assertEquals(2.0d, x, "getAndSetAcquire double value");
}
{
vh.set(recv, 1.0d);
double o = (double) vh.getAndSetRelease(recv, 2.0d);
assertEquals(o, 1.0d, "getAndSetRelease double");
assertEquals(1.0d, o, "getAndSetRelease double");
double x = (double) vh.get(recv);
assertEquals(x, 2.0d, "getAndSetRelease double value");
assertEquals(2.0d, x, "getAndSetRelease double value");
}
// get and add, add and get
@ -655,27 +653,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.set(recv, 1.0d);
double o = (double) vh.getAndAdd(recv, 2.0d);
assertEquals(o, 1.0d, "getAndAdd double");
assertEquals(1.0d, o, "getAndAdd double");
double x = (double) vh.get(recv);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value");
}
{
vh.set(recv, 1.0d);
double o = (double) vh.getAndAddAcquire(recv, 2.0d);
assertEquals(o, 1.0d, "getAndAddAcquire double");
assertEquals(1.0d, o, "getAndAddAcquire double");
double x = (double) vh.get(recv);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value");
}
{
vh.set(recv, 1.0d);
double o = (double) vh.getAndAddRelease(recv, 2.0d);
assertEquals(o, 1.0d, "getAndAddReleasedouble");
assertEquals(1.0d, o, "getAndAddReleasedouble");
double x = (double) vh.get(recv);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value");
}
}
@ -726,7 +724,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
{
vh.set(1.0d);
double x = (double) vh.get();
assertEquals(x, 1.0d, "set double value");
assertEquals(1.0d, x, "set double value");
}
@ -734,21 +732,21 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
{
vh.setVolatile(2.0d);
double x = (double) vh.getVolatile();
assertEquals(x, 2.0d, "setVolatile double value");
assertEquals(2.0d, x, "setVolatile double value");
}
// Lazy
{
vh.setRelease(1.0d);
double x = (double) vh.getAcquire();
assertEquals(x, 1.0d, "setRelease double value");
assertEquals(1.0d, x, "setRelease double value");
}
// Opaque
{
vh.setOpaque(2.0d);
double x = (double) vh.getOpaque();
assertEquals(x, 2.0d, "setOpaque double value");
assertEquals(2.0d, x, "setOpaque double value");
}
vh.set(1.0d);
@ -758,56 +756,56 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
boolean r = vh.compareAndSet(1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "success compareAndSet double value");
assertEquals(2.0d, x, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "failing compareAndSet double value");
assertEquals(2.0d, x, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success compareAndExchange double value");
assertEquals(1.0d, x, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing compareAndExchange double value");
assertEquals(1.0d, x, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
assertEquals(1.0d, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
assertEquals(1.0d, x, "failing compareAndExchangeRelease double value");
}
{
@ -818,14 +816,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = vh.weakCompareAndSetPlain(1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value");
}
{
@ -836,14 +834,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
assertEquals(1.0d, x, "success weakCompareAndSetAcquire double");
}
{
boolean success = vh.weakCompareAndSetAcquire(2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -854,14 +852,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
assertEquals(2.0d, x, "success weakCompareAndSetRelease double");
}
{
boolean success = vh.weakCompareAndSetRelease(1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value");
assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value");
}
{
@ -872,14 +870,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "success weakCompareAndSet double");
assertEquals(1.0d, x, "success weakCompareAndSet double");
}
{
boolean success = vh.weakCompareAndSet(2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) vh.get();
assertEquals(x, 1.0d, "failing weakCompareAndSet double value");
assertEquals(1.0d, x, "failing weakCompareAndSet double value");
}
// Compare set and get
@ -887,27 +885,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.set(1.0d);
double o = (double) vh.getAndSet(2.0d);
assertEquals(o, 1.0d, "getAndSet double");
assertEquals(1.0d, o, "getAndSet double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "getAndSet double value");
assertEquals(2.0d, x, "getAndSet double value");
}
{
vh.set(1.0d);
double o = (double) vh.getAndSetAcquire(2.0d);
assertEquals(o, 1.0d, "getAndSetAcquire double");
assertEquals(1.0d, o, "getAndSetAcquire double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "getAndSetAcquire double value");
assertEquals(2.0d, x, "getAndSetAcquire double value");
}
{
vh.set(1.0d);
double o = (double) vh.getAndSetRelease(2.0d);
assertEquals(o, 1.0d, "getAndSetRelease double");
assertEquals(1.0d, o, "getAndSetRelease double");
double x = (double) vh.get();
assertEquals(x, 2.0d, "getAndSetRelease double value");
assertEquals(2.0d, x, "getAndSetRelease double value");
}
// get and add, add and get
@ -915,27 +913,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.set(1.0d);
double o = (double) vh.getAndAdd(2.0d);
assertEquals(o, 1.0d, "getAndAdd double");
assertEquals(1.0d, o, "getAndAdd double");
double x = (double) vh.get();
assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value");
}
{
vh.set(1.0d);
double o = (double) vh.getAndAddAcquire(2.0d);
assertEquals(o, 1.0d, "getAndAddAcquire double");
assertEquals(1.0d, o, "getAndAddAcquire double");
double x = (double) vh.get();
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value");
}
{
vh.set(1.0d);
double o = (double) vh.getAndAddRelease(2.0d);
assertEquals(o, 1.0d, "getAndAddReleasedouble");
assertEquals(1.0d, o, "getAndAddReleasedouble");
double x = (double) vh.get();
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value");
}
}
@ -989,7 +987,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
{
vh.set(array, i, 1.0d);
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "get double value");
assertEquals(1.0d, x, "get double value");
}
@ -997,21 +995,21 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
{
vh.setVolatile(array, i, 2.0d);
double x = (double) vh.getVolatile(array, i);
assertEquals(x, 2.0d, "setVolatile double value");
assertEquals(2.0d, x, "setVolatile double value");
}
// Lazy
{
vh.setRelease(array, i, 1.0d);
double x = (double) vh.getAcquire(array, i);
assertEquals(x, 1.0d, "setRelease double value");
assertEquals(1.0d, x, "setRelease double value");
}
// Opaque
{
vh.setOpaque(array, i, 2.0d);
double x = (double) vh.getOpaque(array, i);
assertEquals(x, 2.0d, "setOpaque double value");
assertEquals(2.0d, x, "setOpaque double value");
}
vh.set(array, i, 1.0d);
@ -1021,56 +1019,56 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "success compareAndSet double value");
assertEquals(2.0d, x, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(array, i, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "failing compareAndSet double value");
assertEquals(2.0d, x, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success compareAndExchange double value");
assertEquals(1.0d, x, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
assertEquals(1.0d, x, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
assertEquals(1.0d, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
assertEquals(1.0d, x, "failing compareAndExchangeRelease double value");
}
{
@ -1081,14 +1079,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value");
}
{
@ -1099,14 +1097,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
assertEquals(1.0d, x, "success weakCompareAndSetAcquire double");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -1117,14 +1115,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
assertEquals(2.0d, x, "success weakCompareAndSetRelease double");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value");
assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value");
}
{
@ -1135,14 +1133,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "success weakCompareAndSet double");
assertEquals(1.0d, x, "success weakCompareAndSet double");
}
{
boolean success = vh.weakCompareAndSet(array, i, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 1.0d, "failing weakCompareAndSet double value");
assertEquals(1.0d, x, "failing weakCompareAndSet double value");
}
// Compare set and get
@ -1150,27 +1148,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.set(array, i, 1.0d);
double o = (double) vh.getAndSet(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
assertEquals(1.0d, o, "getAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "getAndSet double value");
assertEquals(2.0d, x, "getAndSet double value");
}
{
vh.set(array, i, 1.0d);
double o = (double) vh.getAndSetAcquire(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSetAcquire double");
assertEquals(1.0d, o, "getAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "getAndSetAcquire double value");
assertEquals(2.0d, x, "getAndSetAcquire double value");
}
{
vh.set(array, i, 1.0d);
double o = (double) vh.getAndSetRelease(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSetRelease double");
assertEquals(1.0d, o, "getAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, 2.0d, "getAndSetRelease double value");
assertEquals(2.0d, x, "getAndSetRelease double value");
}
// get and add, add and get
@ -1178,27 +1176,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest {
vh.set(array, i, 1.0d);
double o = (double) vh.getAndAdd(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndAdd double");
assertEquals(1.0d, o, "getAndAdd double");
double x = (double) vh.get(array, i);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value");
}
{
vh.set(array, i, 1.0d);
double o = (double) vh.getAndAddAcquire(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndAddAcquire double");
assertEquals(1.0d, o, "getAndAddAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value");
}
{
vh.set(array, i, 1.0d);
double o = (double) vh.getAndAddRelease(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndAddReleasedouble");
assertEquals(1.0d, o, "getAndAddReleasedouble");
double x = (double) vh.get(array, i);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,28 +23,30 @@
/*
* @test
* @run testng/othervm -Diters=10 -Xint VarHandleTestAccessFloat
* @run junit/othervm -Diters=10 -Xint VarHandleTestAccessFloat
*
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
*
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessFloat
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessFloat
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessFloat
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessFloat
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessFloat
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessFloat
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestAccessFloat extends VarHandleBaseTest {
static final float static_final_v = 1.0f;
@ -108,7 +110,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
return vhs.toArray(new VarHandle[0]);
}
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestAccessFloat.class, "final_v", float.class);
@ -125,8 +127,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(float[].class);
}
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
List<VarHandle> vhs = new ArrayList<>();
vhs.add(vhField);
@ -156,7 +156,8 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("varHandlesProvider")
public void testIsAccessModeSupported(VarHandle vh) {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
@ -194,8 +195,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@DataProvider
public Object[][] typesProvider() throws Exception {
List<Object[]> types = new ArrayList<>();
types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessFloat.class)});
@ -205,16 +204,16 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
return types.stream().toArray(Object[][]::new);
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<Class<?>> pts) {
assertEquals(vh.varType(), float.class);
assertEquals(float.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@Test
public void testLookupInstanceToStatic() {
checkIAE("Lookup of static final field to instance final field", () -> {
@ -241,8 +240,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
});
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -284,7 +281,8 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -297,26 +295,26 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
// Plain
{
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "get float value");
assertEquals(1.0f, x, "get float value");
}
// Volatile
{
float x = (float) vh.getVolatile(recv);
assertEquals(x, 1.0f, "getVolatile float value");
assertEquals(1.0f, x, "getVolatile float value");
}
// Lazy
{
float x = (float) vh.getAcquire(recv);
assertEquals(x, 1.0f, "getRelease float value");
assertEquals(1.0f, x, "getRelease float value");
}
// Opaque
{
float x = (float) vh.getOpaque(recv);
assertEquals(x, 1.0f, "getOpaque float value");
assertEquals(1.0f, x, "getOpaque float value");
}
}
@ -381,26 +379,26 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
// Plain
{
float x = (float) vh.get();
assertEquals(x, 1.0f, "get float value");
assertEquals(1.0f, x, "get float value");
}
// Volatile
{
float x = (float) vh.getVolatile();
assertEquals(x, 1.0f, "getVolatile float value");
assertEquals(1.0f, x, "getVolatile float value");
}
// Lazy
{
float x = (float) vh.getAcquire();
assertEquals(x, 1.0f, "getRelease float value");
assertEquals(1.0f, x, "getRelease float value");
}
// Opaque
{
float x = (float) vh.getOpaque();
assertEquals(x, 1.0f, "getOpaque float value");
assertEquals(1.0f, x, "getOpaque float value");
}
}
@ -466,7 +464,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
{
vh.set(recv, 1.0f);
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "set float value");
assertEquals(1.0f, x, "set float value");
}
@ -474,21 +472,21 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
{
vh.setVolatile(recv, 2.0f);
float x = (float) vh.getVolatile(recv);
assertEquals(x, 2.0f, "setVolatile float value");
assertEquals(2.0f, x, "setVolatile float value");
}
// Lazy
{
vh.setRelease(recv, 1.0f);
float x = (float) vh.getAcquire(recv);
assertEquals(x, 1.0f, "setRelease float value");
assertEquals(1.0f, x, "setRelease float value");
}
// Opaque
{
vh.setOpaque(recv, 2.0f);
float x = (float) vh.getOpaque(recv);
assertEquals(x, 2.0f, "setOpaque float value");
assertEquals(2.0f, x, "setOpaque float value");
}
vh.set(recv, 1.0f);
@ -498,56 +496,56 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "success compareAndSet float value");
assertEquals(2.0f, x, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(recv, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "failing compareAndSet float value");
assertEquals(2.0f, x, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success compareAndExchange float value");
assertEquals(1.0f, x, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
assertEquals(1.0f, x, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
assertEquals(1.0f, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
assertEquals(1.0f, x, "failing compareAndExchangeRelease float value");
}
{
@ -558,14 +556,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = vh.weakCompareAndSetPlain(recv, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value");
}
{
@ -576,14 +574,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
assertEquals(1.0f, x, "success weakCompareAndSetAcquire float");
}
{
boolean success = vh.weakCompareAndSetAcquire(recv, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -594,14 +592,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
assertEquals(2.0f, x, "success weakCompareAndSetRelease float");
}
{
boolean success = vh.weakCompareAndSetRelease(recv, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value");
}
{
@ -612,14 +610,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "success weakCompareAndSet float value");
assertEquals(1.0f, x, "success weakCompareAndSet float value");
}
{
boolean success = vh.weakCompareAndSet(recv, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
assertEquals(1.0f, x, "failing weakCompareAndSet float value");
}
// Compare set and get
@ -627,27 +625,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.set(recv, 1.0f);
float o = (float) vh.getAndSet(recv, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
assertEquals(1.0f, o, "getAndSet float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "getAndSet float value");
assertEquals(2.0f, x, "getAndSet float value");
}
{
vh.set(recv, 1.0f);
float o = (float) vh.getAndSetAcquire(recv, 2.0f);
assertEquals(o, 1.0f, "getAndSetAcquire float");
assertEquals(1.0f, o, "getAndSetAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "getAndSetAcquire float value");
assertEquals(2.0f, x, "getAndSetAcquire float value");
}
{
vh.set(recv, 1.0f);
float o = (float) vh.getAndSetRelease(recv, 2.0f);
assertEquals(o, 1.0f, "getAndSetRelease float");
assertEquals(1.0f, o, "getAndSetRelease float");
float x = (float) vh.get(recv);
assertEquals(x, 2.0f, "getAndSetRelease float value");
assertEquals(2.0f, x, "getAndSetRelease float value");
}
// get and add, add and get
@ -655,27 +653,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.set(recv, 1.0f);
float o = (float) vh.getAndAdd(recv, 2.0f);
assertEquals(o, 1.0f, "getAndAdd float");
assertEquals(1.0f, o, "getAndAdd float");
float x = (float) vh.get(recv);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value");
}
{
vh.set(recv, 1.0f);
float o = (float) vh.getAndAddAcquire(recv, 2.0f);
assertEquals(o, 1.0f, "getAndAddAcquire float");
assertEquals(1.0f, o, "getAndAddAcquire float");
float x = (float) vh.get(recv);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value");
}
{
vh.set(recv, 1.0f);
float o = (float) vh.getAndAddRelease(recv, 2.0f);
assertEquals(o, 1.0f, "getAndAddReleasefloat");
assertEquals(1.0f, o, "getAndAddReleasefloat");
float x = (float) vh.get(recv);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value");
}
}
@ -726,7 +724,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
{
vh.set(1.0f);
float x = (float) vh.get();
assertEquals(x, 1.0f, "set float value");
assertEquals(1.0f, x, "set float value");
}
@ -734,21 +732,21 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
{
vh.setVolatile(2.0f);
float x = (float) vh.getVolatile();
assertEquals(x, 2.0f, "setVolatile float value");
assertEquals(2.0f, x, "setVolatile float value");
}
// Lazy
{
vh.setRelease(1.0f);
float x = (float) vh.getAcquire();
assertEquals(x, 1.0f, "setRelease float value");
assertEquals(1.0f, x, "setRelease float value");
}
// Opaque
{
vh.setOpaque(2.0f);
float x = (float) vh.getOpaque();
assertEquals(x, 2.0f, "setOpaque float value");
assertEquals(2.0f, x, "setOpaque float value");
}
vh.set(1.0f);
@ -758,56 +756,56 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
boolean r = vh.compareAndSet(1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "success compareAndSet float value");
assertEquals(2.0f, x, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "failing compareAndSet float value");
assertEquals(2.0f, x, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success compareAndExchange float value");
assertEquals(1.0f, x, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing compareAndExchange float value");
assertEquals(1.0f, x, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
assertEquals(1.0f, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
assertEquals(1.0f, x, "failing compareAndExchangeRelease float value");
}
{
@ -818,14 +816,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = vh.weakCompareAndSetPlain(1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value");
}
{
@ -836,14 +834,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
assertEquals(1.0f, x, "success weakCompareAndSetAcquire float");
}
{
boolean success = vh.weakCompareAndSetAcquire(2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -854,14 +852,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
assertEquals(2.0f, x, "success weakCompareAndSetRelease float");
}
{
boolean success = vh.weakCompareAndSetRelease(1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetRelease float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value");
}
{
@ -872,14 +870,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "success weakCompareAndSet float");
assertEquals(1.0f, x, "success weakCompareAndSet float");
}
{
boolean success = vh.weakCompareAndSet(2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) vh.get();
assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
assertEquals(1.0f, x, "failing weakCompareAndSet float value");
}
// Compare set and get
@ -887,27 +885,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.set(1.0f);
float o = (float) vh.getAndSet(2.0f);
assertEquals(o, 1.0f, "getAndSet float");
assertEquals(1.0f, o, "getAndSet float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "getAndSet float value");
assertEquals(2.0f, x, "getAndSet float value");
}
{
vh.set(1.0f);
float o = (float) vh.getAndSetAcquire(2.0f);
assertEquals(o, 1.0f, "getAndSetAcquire float");
assertEquals(1.0f, o, "getAndSetAcquire float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "getAndSetAcquire float value");
assertEquals(2.0f, x, "getAndSetAcquire float value");
}
{
vh.set(1.0f);
float o = (float) vh.getAndSetRelease(2.0f);
assertEquals(o, 1.0f, "getAndSetRelease float");
assertEquals(1.0f, o, "getAndSetRelease float");
float x = (float) vh.get();
assertEquals(x, 2.0f, "getAndSetRelease float value");
assertEquals(2.0f, x, "getAndSetRelease float value");
}
// get and add, add and get
@ -915,27 +913,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.set(1.0f);
float o = (float) vh.getAndAdd(2.0f);
assertEquals(o, 1.0f, "getAndAdd float");
assertEquals(1.0f, o, "getAndAdd float");
float x = (float) vh.get();
assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value");
}
{
vh.set(1.0f);
float o = (float) vh.getAndAddAcquire(2.0f);
assertEquals(o, 1.0f, "getAndAddAcquire float");
assertEquals(1.0f, o, "getAndAddAcquire float");
float x = (float) vh.get();
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value");
}
{
vh.set(1.0f);
float o = (float) vh.getAndAddRelease(2.0f);
assertEquals(o, 1.0f, "getAndAddReleasefloat");
assertEquals(1.0f, o, "getAndAddReleasefloat");
float x = (float) vh.get();
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value");
}
}
@ -989,7 +987,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
{
vh.set(array, i, 1.0f);
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "get float value");
assertEquals(1.0f, x, "get float value");
}
@ -997,21 +995,21 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
{
vh.setVolatile(array, i, 2.0f);
float x = (float) vh.getVolatile(array, i);
assertEquals(x, 2.0f, "setVolatile float value");
assertEquals(2.0f, x, "setVolatile float value");
}
// Lazy
{
vh.setRelease(array, i, 1.0f);
float x = (float) vh.getAcquire(array, i);
assertEquals(x, 1.0f, "setRelease float value");
assertEquals(1.0f, x, "setRelease float value");
}
// Opaque
{
vh.setOpaque(array, i, 2.0f);
float x = (float) vh.getOpaque(array, i);
assertEquals(x, 2.0f, "setOpaque float value");
assertEquals(2.0f, x, "setOpaque float value");
}
vh.set(array, i, 1.0f);
@ -1021,56 +1019,56 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "success compareAndSet float value");
assertEquals(2.0f, x, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(array, i, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "failing compareAndSet float value");
assertEquals(2.0f, x, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success compareAndExchange float value");
assertEquals(1.0f, x, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
assertEquals(1.0f, x, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
assertEquals(1.0f, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
assertEquals(1.0f, x, "failing compareAndExchangeRelease float value");
}
{
@ -1081,14 +1079,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value");
}
{
@ -1099,14 +1097,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
assertEquals(1.0f, x, "success weakCompareAndSetAcquire float");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -1117,14 +1115,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
assertEquals(2.0f, x, "success weakCompareAndSetRelease float");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value");
}
{
@ -1135,14 +1133,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "success weakCompareAndSet float");
assertEquals(1.0f, x, "success weakCompareAndSet float");
}
{
boolean success = vh.weakCompareAndSet(array, i, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
assertEquals(1.0f, x, "failing weakCompareAndSet float value");
}
// Compare set and get
@ -1150,27 +1148,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.set(array, i, 1.0f);
float o = (float) vh.getAndSet(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
assertEquals(1.0f, o, "getAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "getAndSet float value");
assertEquals(2.0f, x, "getAndSet float value");
}
{
vh.set(array, i, 1.0f);
float o = (float) vh.getAndSetAcquire(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSetAcquire float");
assertEquals(1.0f, o, "getAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "getAndSetAcquire float value");
assertEquals(2.0f, x, "getAndSetAcquire float value");
}
{
vh.set(array, i, 1.0f);
float o = (float) vh.getAndSetRelease(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSetRelease float");
assertEquals(1.0f, o, "getAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, 2.0f, "getAndSetRelease float value");
assertEquals(2.0f, x, "getAndSetRelease float value");
}
// get and add, add and get
@ -1178,27 +1176,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest {
vh.set(array, i, 1.0f);
float o = (float) vh.getAndAdd(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndAdd float");
assertEquals(1.0f, o, "getAndAdd float");
float x = (float) vh.get(array, i);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value");
}
{
vh.set(array, i, 1.0f);
float o = (float) vh.getAndAddAcquire(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndAddAcquire float");
assertEquals(1.0f, o, "getAndAddAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value");
}
{
vh.set(array, i, 1.0f);
float o = (float) vh.getAndAddRelease(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndAddReleasefloat");
assertEquals(1.0f, o, "getAndAddReleasefloat");
float x = (float) vh.get(array, i);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,32 +23,34 @@
/*
* @test
* @run testng VarHandleTestAccessModeMethodNames
* @run junit VarHandleTestAccessModeMethodNames
* @modules java.base/java.lang.invoke:open
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.VarHandle;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.stream.Stream;
import static org.testng.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestAccessModeMethodNames {
@DataProvider
public static Object[][] accessModesProvider() {
return Stream.of(VarHandle.AccessMode.values()).
map(am -> new Object[]{am}).
toArray(Object[][]::new);
}
@Test(dataProvider = "accessModesProvider")
@ParameterizedTest
@MethodSource("accessModesProvider")
public void testMethodName(VarHandle.AccessMode am) {
assertEquals(am.methodName(), toMethodName(am.name()));
assertEquals(toMethodName(am.name()), am.methodName());
}
private static String toMethodName(String name) {
@ -62,9 +64,10 @@ public class VarHandleTestAccessModeMethodNames {
}
@Test(dataProvider = "accessModesProvider")
@ParameterizedTest
@MethodSource("accessModesProvider")
public void testReturnType(VarHandle.AccessMode am) throws Exception {
assertEquals(getReturnType(am.methodName()), getAccessModeReturnType(am));
assertEquals(getAccessModeReturnType(am), getReturnType(am.methodName()));
}
private static Class<?> getReturnType(String name) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,28 +23,30 @@
/*
* @test
* @run testng/othervm -Diters=10 -Xint VarHandleTestAccessString
* @run junit/othervm -Diters=10 -Xint VarHandleTestAccessString
*
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
*
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessString
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessString
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessString
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessString
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessString
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessString
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestAccessString extends VarHandleBaseTest {
static final String static_final_v = "foo";
@ -109,7 +111,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
return vhs.toArray(new VarHandle[0]);
}
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestAccessString.class, "final_v", String.class);
@ -127,8 +129,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class);
}
@DataProvider
public Object[][] varHandlesProvider() throws Exception {
List<VarHandle> vhs = new ArrayList<>();
vhs.add(vhField);
@ -158,7 +158,8 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("varHandlesProvider")
public void testIsAccessModeSupported(VarHandle vh) {
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
@ -196,8 +197,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@DataProvider
public Object[][] typesProvider() throws Exception {
List<Object[]> types = new ArrayList<>();
types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessString.class)});
@ -207,16 +206,16 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
return types.stream().toArray(Object[][]::new);
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<Class<?>> pts) {
assertEquals(vh.varType(), String.class);
assertEquals(String.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@Test
public void testLookupInstanceToStatic() {
checkIAE("Lookup of static final field to instance final field", () -> {
@ -243,8 +242,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
});
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -291,7 +288,8 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -304,26 +302,26 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
// Plain
{
String x = (String) vh.get(recv);
assertEquals(x, "foo", "get String value");
assertEquals("foo", x, "get String value");
}
// Volatile
{
String x = (String) vh.getVolatile(recv);
assertEquals(x, "foo", "getVolatile String value");
assertEquals("foo", x, "getVolatile String value");
}
// Lazy
{
String x = (String) vh.getAcquire(recv);
assertEquals(x, "foo", "getRelease String value");
assertEquals("foo", x, "getRelease String value");
}
// Opaque
{
String x = (String) vh.getOpaque(recv);
assertEquals(x, "foo", "getOpaque String value");
assertEquals("foo", x, "getOpaque String value");
}
}
@ -399,26 +397,26 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
// Plain
{
String x = (String) vh.get();
assertEquals(x, "foo", "get String value");
assertEquals("foo", x, "get String value");
}
// Volatile
{
String x = (String) vh.getVolatile();
assertEquals(x, "foo", "getVolatile String value");
assertEquals("foo", x, "getVolatile String value");
}
// Lazy
{
String x = (String) vh.getAcquire();
assertEquals(x, "foo", "getRelease String value");
assertEquals("foo", x, "getRelease String value");
}
// Opaque
{
String x = (String) vh.getOpaque();
assertEquals(x, "foo", "getOpaque String value");
assertEquals("foo", x, "getOpaque String value");
}
}
@ -495,7 +493,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
{
vh.set(recv, "foo");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "set String value");
assertEquals("foo", x, "set String value");
}
@ -503,21 +501,21 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
{
vh.setVolatile(recv, "bar");
String x = (String) vh.getVolatile(recv);
assertEquals(x, "bar", "setVolatile String value");
assertEquals("bar", x, "setVolatile String value");
}
// Lazy
{
vh.setRelease(recv, "foo");
String x = (String) vh.getAcquire(recv);
assertEquals(x, "foo", "setRelease String value");
assertEquals("foo", x, "setRelease String value");
}
// Opaque
{
vh.setOpaque(recv, "bar");
String x = (String) vh.getOpaque(recv);
assertEquals(x, "bar", "setOpaque String value");
assertEquals("bar", x, "setOpaque String value");
}
vh.set(recv, "foo");
@ -527,56 +525,56 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
boolean r = vh.compareAndSet(recv, "foo", "bar");
assertEquals(r, true, "success compareAndSet String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "success compareAndSet String value");
assertEquals("bar", x, "success compareAndSet String value");
}
{
boolean r = vh.compareAndSet(recv, "foo", "baz");
assertEquals(r, false, "failing compareAndSet String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "failing compareAndSet String value");
assertEquals("bar", x, "failing compareAndSet String value");
}
{
String r = (String) vh.compareAndExchange(recv, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "success compareAndExchange String value");
assertEquals("foo", x, "success compareAndExchange String value");
}
{
String r = (String) vh.compareAndExchange(recv, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "failing compareAndExchange String value");
assertEquals("foo", x, "failing compareAndExchange String value");
}
{
String r = (String) vh.compareAndExchangeAcquire(recv, "foo", "bar");
assertEquals(r, "foo", "success compareAndExchangeAcquire String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
assertEquals("bar", x, "success compareAndExchangeAcquire String value");
}
{
String r = (String) vh.compareAndExchangeAcquire(recv, "foo", "baz");
assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
assertEquals("bar", x, "failing compareAndExchangeAcquire String value");
}
{
String r = (String) vh.compareAndExchangeRelease(recv, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeRelease String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "success compareAndExchangeRelease String value");
assertEquals("foo", x, "success compareAndExchangeRelease String value");
}
{
String r = (String) vh.compareAndExchangeRelease(recv, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeRelease String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
assertEquals("foo", x, "failing compareAndExchangeRelease String value");
}
{
@ -587,14 +585,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "success weakCompareAndSetPlain String value");
assertEquals("bar", x, "success weakCompareAndSetPlain String value");
}
{
boolean success = vh.weakCompareAndSetPlain(recv, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetPlain String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "failing weakCompareAndSetPlain String value");
assertEquals("bar", x, "failing weakCompareAndSetPlain String value");
}
{
@ -605,14 +603,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "success weakCompareAndSetAcquire String");
assertEquals("foo", x, "success weakCompareAndSetAcquire String");
}
{
boolean success = vh.weakCompareAndSetAcquire(recv, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value");
assertEquals("foo", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -623,14 +621,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "success weakCompareAndSetRelease String");
assertEquals("bar", x, "success weakCompareAndSetRelease String");
}
{
boolean success = vh.weakCompareAndSetRelease(recv, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetRelease String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "failing weakCompareAndSetRelease String value");
assertEquals("bar", x, "failing weakCompareAndSetRelease String value");
}
{
@ -641,14 +639,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "success weakCompareAndSet String value");
assertEquals("foo", x, "success weakCompareAndSet String value");
}
{
boolean success = vh.weakCompareAndSet(recv, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSet String");
String x = (String) vh.get(recv);
assertEquals(x, "foo", "failing weakCompareAndSet String value");
assertEquals("foo", x, "failing weakCompareAndSet String value");
}
// Compare set and get
@ -656,27 +654,27 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
vh.set(recv, "foo");
String o = (String) vh.getAndSet(recv, "bar");
assertEquals(o, "foo", "getAndSet String");
assertEquals("foo", o, "getAndSet String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "getAndSet String value");
assertEquals("bar", x, "getAndSet String value");
}
{
vh.set(recv, "foo");
String o = (String) vh.getAndSetAcquire(recv, "bar");
assertEquals(o, "foo", "getAndSetAcquire String");
assertEquals("foo", o, "getAndSetAcquire String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "getAndSetAcquire String value");
assertEquals("bar", x, "getAndSetAcquire String value");
}
{
vh.set(recv, "foo");
String o = (String) vh.getAndSetRelease(recv, "bar");
assertEquals(o, "foo", "getAndSetRelease String");
assertEquals("foo", o, "getAndSetRelease String");
String x = (String) vh.get(recv);
assertEquals(x, "bar", "getAndSetRelease String value");
assertEquals("bar", x, "getAndSetRelease String value");
}
@ -739,7 +737,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
{
vh.set("foo");
String x = (String) vh.get();
assertEquals(x, "foo", "set String value");
assertEquals("foo", x, "set String value");
}
@ -747,21 +745,21 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
{
vh.setVolatile("bar");
String x = (String) vh.getVolatile();
assertEquals(x, "bar", "setVolatile String value");
assertEquals("bar", x, "setVolatile String value");
}
// Lazy
{
vh.setRelease("foo");
String x = (String) vh.getAcquire();
assertEquals(x, "foo", "setRelease String value");
assertEquals("foo", x, "setRelease String value");
}
// Opaque
{
vh.setOpaque("bar");
String x = (String) vh.getOpaque();
assertEquals(x, "bar", "setOpaque String value");
assertEquals("bar", x, "setOpaque String value");
}
vh.set("foo");
@ -771,56 +769,56 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
boolean r = vh.compareAndSet("foo", "bar");
assertEquals(r, true, "success compareAndSet String");
String x = (String) vh.get();
assertEquals(x, "bar", "success compareAndSet String value");
assertEquals("bar", x, "success compareAndSet String value");
}
{
boolean r = vh.compareAndSet("foo", "baz");
assertEquals(r, false, "failing compareAndSet String");
String x = (String) vh.get();
assertEquals(x, "bar", "failing compareAndSet String value");
assertEquals("bar", x, "failing compareAndSet String value");
}
{
String r = (String) vh.compareAndExchange("bar", "foo");
assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) vh.get();
assertEquals(x, "foo", "success compareAndExchange String value");
assertEquals("foo", x, "success compareAndExchange String value");
}
{
String r = (String) vh.compareAndExchange("bar", "baz");
assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) vh.get();
assertEquals(x, "foo", "failing compareAndExchange String value");
assertEquals("foo", x, "failing compareAndExchange String value");
}
{
String r = (String) vh.compareAndExchangeAcquire("foo", "bar");
assertEquals(r, "foo", "success compareAndExchangeAcquire String");
String x = (String) vh.get();
assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
assertEquals("bar", x, "success compareAndExchangeAcquire String value");
}
{
String r = (String) vh.compareAndExchangeAcquire("foo", "baz");
assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
String x = (String) vh.get();
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
assertEquals("bar", x, "failing compareAndExchangeAcquire String value");
}
{
String r = (String) vh.compareAndExchangeRelease("bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeRelease String");
String x = (String) vh.get();
assertEquals(x, "foo", "success compareAndExchangeRelease String value");
assertEquals("foo", x, "success compareAndExchangeRelease String value");
}
{
String r = (String) vh.compareAndExchangeRelease("bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeRelease String");
String x = (String) vh.get();
assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
assertEquals("foo", x, "failing compareAndExchangeRelease String value");
}
{
@ -831,14 +829,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain String");
String x = (String) vh.get();
assertEquals(x, "bar", "success weakCompareAndSetPlain String value");
assertEquals("bar", x, "success weakCompareAndSetPlain String value");
}
{
boolean success = vh.weakCompareAndSetPlain("foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetPlain String");
String x = (String) vh.get();
assertEquals(x, "bar", "failing weakCompareAndSetPlain String value");
assertEquals("bar", x, "failing weakCompareAndSetPlain String value");
}
{
@ -849,14 +847,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire String");
String x = (String) vh.get();
assertEquals(x, "foo", "success weakCompareAndSetAcquire String");
assertEquals("foo", x, "success weakCompareAndSetAcquire String");
}
{
boolean success = vh.weakCompareAndSetAcquire("bar", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) vh.get();
assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value");
assertEquals("foo", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -867,14 +865,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease String");
String x = (String) vh.get();
assertEquals(x, "bar", "success weakCompareAndSetRelease String");
assertEquals("bar", x, "success weakCompareAndSetRelease String");
}
{
boolean success = vh.weakCompareAndSetRelease("foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetRelease String");
String x = (String) vh.get();
assertEquals(x, "bar", "failing weakCompareAndSetRelease String value");
assertEquals("bar", x, "failing weakCompareAndSetRelease String value");
}
{
@ -885,14 +883,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet String");
String x = (String) vh.get();
assertEquals(x, "foo", "success weakCompareAndSet String");
assertEquals("foo", x, "success weakCompareAndSet String");
}
{
boolean success = vh.weakCompareAndSet("bar", "baz");
assertEquals(success, false, "failing weakCompareAndSet String");
String x = (String) vh.get();
assertEquals(x, "foo", "failing weakCompareAndSet String value");
assertEquals("foo", x, "failing weakCompareAndSet String value");
}
// Compare set and get
@ -900,27 +898,27 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
vh.set("foo");
String o = (String) vh.getAndSet("bar");
assertEquals(o, "foo", "getAndSet String");
assertEquals("foo", o, "getAndSet String");
String x = (String) vh.get();
assertEquals(x, "bar", "getAndSet String value");
assertEquals("bar", x, "getAndSet String value");
}
{
vh.set("foo");
String o = (String) vh.getAndSetAcquire("bar");
assertEquals(o, "foo", "getAndSetAcquire String");
assertEquals("foo", o, "getAndSetAcquire String");
String x = (String) vh.get();
assertEquals(x, "bar", "getAndSetAcquire String value");
assertEquals("bar", x, "getAndSetAcquire String value");
}
{
vh.set("foo");
String o = (String) vh.getAndSetRelease("bar");
assertEquals(o, "foo", "getAndSetRelease String");
assertEquals("foo", o, "getAndSetRelease String");
String x = (String) vh.get();
assertEquals(x, "bar", "getAndSetRelease String value");
assertEquals("bar", x, "getAndSetRelease String value");
}
@ -986,7 +984,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
{
vh.set(array, i, "foo");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "get String value");
assertEquals("foo", x, "get String value");
}
@ -994,21 +992,21 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
{
vh.setVolatile(array, i, "bar");
String x = (String) vh.getVolatile(array, i);
assertEquals(x, "bar", "setVolatile String value");
assertEquals("bar", x, "setVolatile String value");
}
// Lazy
{
vh.setRelease(array, i, "foo");
String x = (String) vh.getAcquire(array, i);
assertEquals(x, "foo", "setRelease String value");
assertEquals("foo", x, "setRelease String value");
}
// Opaque
{
vh.setOpaque(array, i, "bar");
String x = (String) vh.getOpaque(array, i);
assertEquals(x, "bar", "setOpaque String value");
assertEquals("bar", x, "setOpaque String value");
}
vh.set(array, i, "foo");
@ -1018,56 +1016,56 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
boolean r = vh.compareAndSet(array, i, "foo", "bar");
assertEquals(r, true, "success compareAndSet String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "success compareAndSet String value");
assertEquals("bar", x, "success compareAndSet String value");
}
{
boolean r = vh.compareAndSet(array, i, "foo", "baz");
assertEquals(r, false, "failing compareAndSet String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "failing compareAndSet String value");
assertEquals("bar", x, "failing compareAndSet String value");
}
{
String r = (String) vh.compareAndExchange(array, i, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "success compareAndExchange String value");
assertEquals("foo", x, "success compareAndExchange String value");
}
{
String r = (String) vh.compareAndExchange(array, i, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "failing compareAndExchange String value");
assertEquals("foo", x, "failing compareAndExchange String value");
}
{
String r = (String) vh.compareAndExchangeAcquire(array, i, "foo", "bar");
assertEquals(r, "foo", "success compareAndExchangeAcquire String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
assertEquals("bar", x, "success compareAndExchangeAcquire String value");
}
{
String r = (String) vh.compareAndExchangeAcquire(array, i, "foo", "baz");
assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
assertEquals("bar", x, "failing compareAndExchangeAcquire String value");
}
{
String r = (String) vh.compareAndExchangeRelease(array, i, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeRelease String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "success compareAndExchangeRelease String value");
assertEquals("foo", x, "success compareAndExchangeRelease String value");
}
{
String r = (String) vh.compareAndExchangeRelease(array, i, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeRelease String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
assertEquals("foo", x, "failing compareAndExchangeRelease String value");
}
{
@ -1078,14 +1076,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "success weakCompareAndSetPlain String value");
assertEquals("bar", x, "success weakCompareAndSetPlain String value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetPlain String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "failing weakCompareAndSetPlain String value");
assertEquals("bar", x, "failing weakCompareAndSetPlain String value");
}
{
@ -1096,14 +1094,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "success weakCompareAndSetAcquire String");
assertEquals("foo", x, "success weakCompareAndSetAcquire String");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value");
assertEquals("foo", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -1114,14 +1112,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "success weakCompareAndSetRelease String");
assertEquals("bar", x, "success weakCompareAndSetRelease String");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetRelease String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "failing weakCompareAndSetRelease String value");
assertEquals("bar", x, "failing weakCompareAndSetRelease String value");
}
{
@ -1132,14 +1130,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "success weakCompareAndSet String");
assertEquals("foo", x, "success weakCompareAndSet String");
}
{
boolean success = vh.weakCompareAndSet(array, i, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSet String");
String x = (String) vh.get(array, i);
assertEquals(x, "foo", "failing weakCompareAndSet String value");
assertEquals("foo", x, "failing weakCompareAndSet String value");
}
// Compare set and get
@ -1147,27 +1145,27 @@ public class VarHandleTestAccessString extends VarHandleBaseTest {
vh.set(array, i, "foo");
String o = (String) vh.getAndSet(array, i, "bar");
assertEquals(o, "foo", "getAndSet String");
assertEquals("foo", o, "getAndSet String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "getAndSet String value");
assertEquals("bar", x, "getAndSet String value");
}
{
vh.set(array, i, "foo");
String o = (String) vh.getAndSetAcquire(array, i, "bar");
assertEquals(o, "foo", "getAndSetAcquire String");
assertEquals("foo", o, "getAndSetAcquire String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "getAndSetAcquire String value");
assertEquals("bar", x, "getAndSetAcquire String value");
}
{
vh.set(array, i, "foo");
String o = (String) vh.getAndSetRelease(array, i, "bar");
assertEquals(o, "foo", "getAndSetRelease String");
assertEquals("foo", o, "getAndSetRelease String");
String x = (String) vh.get(array, i);
assertEquals(x, "bar", "getAndSetRelease String value");
assertEquals("bar", x, "getAndSetRelease String value");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsChar
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsChar
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsChar
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsChar
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsChar
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsChar
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
static final int SIZE = Character.BYTES;
@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -158,17 +159,16 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), char.class);
assertEquals(char.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -230,7 +230,8 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -239,7 +240,6 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -740,7 +740,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
char x = (char) vh.get(array, i);
assertEquals(x, VALUE_1, "get char value");
assertEquals(VALUE_1, x, "get char value");
}
}
}
@ -759,7 +759,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
char x = (char) vh.get(array, i);
assertEquals(x, VALUE_1, "get char value");
assertEquals(VALUE_1, x, "get char value");
}
if (iAligned) {
@ -767,21 +767,21 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
char x = (char) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile char value");
assertEquals(VALUE_2, x, "setVolatile char value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
char x = (char) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease char value");
assertEquals(VALUE_1, x, "setRelease char value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
char x = (char) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque char value");
assertEquals(VALUE_2, x, "setOpaque char value");
}
@ -807,26 +807,26 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest {
// Plain
{
char x = (char) vh.get(array, i);
assertEquals(x, v, "get char value");
assertEquals(v, x, "get char value");
}
if (iAligned) {
// Volatile
{
char x = (char) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile char value");
assertEquals(v, x, "getVolatile char value");
}
// Lazy
{
char x = (char) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease char value");
assertEquals(v, x, "getRelease char value");
}
// Opaque
{
char x = (char) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque char value");
assertEquals(v, x, "getOpaque char value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsDouble
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsDouble
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsDouble
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsDouble
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsDouble
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsDouble
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
static final int SIZE = Double.BYTES;
@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -172,17 +173,16 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), double.class);
assertEquals(double.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -244,7 +244,8 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -253,7 +254,6 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -883,7 +883,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "get double value");
assertEquals(VALUE_1, x, "get double value");
}
}
}
@ -902,7 +902,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "get double value");
assertEquals(VALUE_1, x, "get double value");
}
if (iAligned) {
@ -910,21 +910,21 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
double x = (double) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile double value");
assertEquals(VALUE_2, x, "setVolatile double value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
double x = (double) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease double value");
assertEquals(VALUE_1, x, "setRelease double value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
double x = (double) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque double value");
assertEquals(VALUE_2, x, "setOpaque double value");
}
vh.set(array, i, VALUE_1);
@ -934,56 +934,56 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
assertEquals(r, true, "success compareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndSet double value");
assertEquals(VALUE_2, x, "success compareAndSet double value");
}
{
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndSet double value");
assertEquals(VALUE_2, x, "failing compareAndSet double value");
}
{
double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchange double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchange double value");
assertEquals(VALUE_1, x, "success compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchange double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchange double value");
assertEquals(VALUE_1, x, "failing compareAndExchange double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire double value");
assertEquals(VALUE_2, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire double value");
assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeRelease double value");
assertEquals(VALUE_1, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease double value");
assertEquals(VALUE_1, x, "failing compareAndExchangeRelease double value");
}
{
@ -994,14 +994,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetPlain double value");
assertEquals(VALUE_2, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain double value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain double value");
}
{
@ -1012,14 +1012,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire double");
assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire double");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire double value");
assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -1030,14 +1030,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetRelease double");
assertEquals(VALUE_2, x, "success weakCompareAndSetRelease double");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease double value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease double value");
}
{
@ -1048,14 +1048,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSet double");
assertEquals(VALUE_1, x, "success weakCompareAndSet double");
}
{
boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSet double value");
assertEquals(VALUE_1, x, "failing weakCompareAndSet double value");
}
// Compare set and get
@ -1063,27 +1063,27 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
double o = (double) vh.getAndSet(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSet double");
assertEquals(VALUE_1, o, "getAndSet double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSet double value");
assertEquals(VALUE_2, x, "getAndSet double value");
}
{
vh.set(array, i, VALUE_1);
double o = (double) vh.getAndSetAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetAcquire double");
assertEquals(VALUE_1, o, "getAndSetAcquire double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetAcquire double value");
assertEquals(VALUE_2, x, "getAndSetAcquire double value");
}
{
vh.set(array, i, VALUE_1);
double o = (double) vh.getAndSetRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetRelease double");
assertEquals(VALUE_1, o, "getAndSetRelease double");
double x = (double) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetRelease double value");
assertEquals(VALUE_2, x, "getAndSetRelease double value");
}
@ -1109,26 +1109,26 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest {
// Plain
{
double x = (double) vh.get(array, i);
assertEquals(x, v, "get double value");
assertEquals(v, x, "get double value");
}
if (iAligned) {
// Volatile
{
double x = (double) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile double value");
assertEquals(v, x, "getVolatile double value");
}
// Lazy
{
double x = (double) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease double value");
assertEquals(v, x, "getRelease double value");
}
// Opaque
{
double x = (double) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque double value");
assertEquals(v, x, "getOpaque double value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsFloat
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsFloat
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsFloat
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsFloat
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsFloat
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsFloat
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
static final int SIZE = Float.BYTES;
@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -172,17 +173,16 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), float.class);
assertEquals(float.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -244,7 +244,8 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -253,7 +254,6 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -883,7 +883,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "get float value");
assertEquals(VALUE_1, x, "get float value");
}
}
}
@ -902,7 +902,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "get float value");
assertEquals(VALUE_1, x, "get float value");
}
if (iAligned) {
@ -910,21 +910,21 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
float x = (float) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile float value");
assertEquals(VALUE_2, x, "setVolatile float value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
float x = (float) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease float value");
assertEquals(VALUE_1, x, "setRelease float value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
float x = (float) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque float value");
assertEquals(VALUE_2, x, "setOpaque float value");
}
vh.set(array, i, VALUE_1);
@ -934,56 +934,56 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
assertEquals(r, true, "success compareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndSet float value");
assertEquals(VALUE_2, x, "success compareAndSet float value");
}
{
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndSet float value");
assertEquals(VALUE_2, x, "failing compareAndSet float value");
}
{
float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchange float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchange float value");
assertEquals(VALUE_1, x, "success compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchange float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchange float value");
assertEquals(VALUE_1, x, "failing compareAndExchange float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire float value");
assertEquals(VALUE_2, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire float value");
assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeRelease float value");
assertEquals(VALUE_1, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease float value");
assertEquals(VALUE_1, x, "failing compareAndExchangeRelease float value");
}
{
@ -994,14 +994,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetPlain float value");
assertEquals(VALUE_2, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain float value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain float value");
}
{
@ -1012,14 +1012,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire float");
assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire float");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire float value");
assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -1030,14 +1030,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetRelease float");
assertEquals(VALUE_2, x, "success weakCompareAndSetRelease float");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease float value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease float value");
}
{
@ -1048,14 +1048,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSet float");
assertEquals(VALUE_1, x, "success weakCompareAndSet float");
}
{
boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSet float value");
assertEquals(VALUE_1, x, "failing weakCompareAndSet float value");
}
// Compare set and get
@ -1063,27 +1063,27 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
float o = (float) vh.getAndSet(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSet float");
assertEquals(VALUE_1, o, "getAndSet float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSet float value");
assertEquals(VALUE_2, x, "getAndSet float value");
}
{
vh.set(array, i, VALUE_1);
float o = (float) vh.getAndSetAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetAcquire float");
assertEquals(VALUE_1, o, "getAndSetAcquire float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetAcquire float value");
assertEquals(VALUE_2, x, "getAndSetAcquire float value");
}
{
vh.set(array, i, VALUE_1);
float o = (float) vh.getAndSetRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetRelease float");
assertEquals(VALUE_1, o, "getAndSetRelease float");
float x = (float) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetRelease float value");
assertEquals(VALUE_2, x, "getAndSetRelease float value");
}
@ -1109,26 +1109,26 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest {
// Plain
{
float x = (float) vh.get(array, i);
assertEquals(x, v, "get float value");
assertEquals(v, x, "get float value");
}
if (iAligned) {
// Volatile
{
float x = (float) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile float value");
assertEquals(v, x, "getVolatile float value");
}
// Lazy
{
float x = (float) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease float value");
assertEquals(v, x, "getRelease float value");
}
// Opaque
{
float x = (float) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque float value");
assertEquals(v, x, "getOpaque float value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsInt
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsInt
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsInt
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsInt
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsInt
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsInt
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
static final int SIZE = Integer.BYTES;
@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -190,17 +191,16 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), int.class);
assertEquals(int.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -262,7 +262,8 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -271,7 +272,6 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -1039,7 +1039,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "get int value");
assertEquals(VALUE_1, x, "get int value");
}
}
}
@ -1058,7 +1058,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "get int value");
assertEquals(VALUE_1, x, "get int value");
}
if (iAligned) {
@ -1066,21 +1066,21 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
int x = (int) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile int value");
assertEquals(VALUE_2, x, "setVolatile int value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
int x = (int) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease int value");
assertEquals(VALUE_1, x, "setRelease int value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
int x = (int) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque int value");
assertEquals(VALUE_2, x, "setOpaque int value");
}
vh.set(array, i, VALUE_1);
@ -1090,56 +1090,56 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
assertEquals(r, true, "success compareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndSet int value");
assertEquals(VALUE_2, x, "success compareAndSet int value");
}
{
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
assertEquals(r, false, "failing compareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndSet int value");
assertEquals(VALUE_2, x, "failing compareAndSet int value");
}
{
int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchange int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchange int value");
assertEquals(VALUE_1, x, "success compareAndExchange int value");
}
{
int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchange int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchange int value");
assertEquals(VALUE_1, x, "failing compareAndExchange int value");
}
{
int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire int value");
assertEquals(VALUE_2, x, "success compareAndExchangeAcquire int value");
}
{
int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire int value");
assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire int value");
}
{
int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeRelease int value");
assertEquals(VALUE_1, x, "success compareAndExchangeRelease int value");
}
{
int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease int value");
assertEquals(VALUE_1, x, "failing compareAndExchangeRelease int value");
}
{
@ -1150,14 +1150,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetPlain int value");
assertEquals(VALUE_2, x, "success weakCompareAndSetPlain int value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetPlain int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain int value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain int value");
}
{
@ -1168,14 +1168,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire int");
assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire int");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire int value");
assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire int value");
}
{
@ -1186,14 +1186,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetRelease int");
assertEquals(VALUE_2, x, "success weakCompareAndSetRelease int");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease int value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease int value");
}
{
@ -1204,14 +1204,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSet int");
assertEquals(VALUE_1, x, "success weakCompareAndSet int");
}
{
boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSet int value");
assertEquals(VALUE_1, x, "failing weakCompareAndSet int value");
}
// Compare set and get
@ -1219,27 +1219,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndSet(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSet int");
assertEquals(VALUE_1, o, "getAndSet int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSet int value");
assertEquals(VALUE_2, x, "getAndSet int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndSetAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetAcquire int");
assertEquals(VALUE_1, o, "getAndSetAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetAcquire int value");
assertEquals(VALUE_2, x, "getAndSetAcquire int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndSetRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetRelease int");
assertEquals(VALUE_1, o, "getAndSetRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetRelease int value");
assertEquals(VALUE_2, x, "getAndSetRelease int value");
}
// get and add, add and get
@ -1247,27 +1247,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndAdd(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAdd int");
assertEquals(VALUE_1, o, "getAndAdd int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd int value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAdd int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndAddAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAddAcquire int");
assertEquals(VALUE_1, o, "getAndAddAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire int value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAddAcquire int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndAddRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAddRelease int");
assertEquals(VALUE_1, o, "getAndAddRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease int value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAddRelease int value");
}
// get and bitwise or
@ -1275,27 +1275,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseOr(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOr int");
assertEquals(VALUE_1, o, "getAndBitwiseOr int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr int value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOr int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire int");
assertEquals(VALUE_1, o, "getAndBitwiseOrAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire int value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrAcquire int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOrRelease int");
assertEquals(VALUE_1, o, "getAndBitwiseOrRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease int value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrRelease int value");
}
// get and bitwise and
@ -1303,27 +1303,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseAnd(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAnd int");
assertEquals(VALUE_1, o, "getAndBitwiseAnd int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd int value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAnd int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire int");
assertEquals(VALUE_1, o, "getAndBitwiseAndAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire int value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndAcquire int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAndRelease int");
assertEquals(VALUE_1, o, "getAndBitwiseAndRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease int value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndRelease int value");
}
// get and bitwise xor
@ -1331,27 +1331,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseXor(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXor int");
assertEquals(VALUE_1, o, "getAndBitwiseXor int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor int value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXor int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire int");
assertEquals(VALUE_1, o, "getAndBitwiseXorAcquire int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire int value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorAcquire int value");
}
{
vh.set(array, i, VALUE_1);
int o = (int) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXorRelease int");
assertEquals(VALUE_1, o, "getAndBitwiseXorRelease int");
int x = (int) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease int value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorRelease int value");
}
}
}
@ -1375,26 +1375,26 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest {
// Plain
{
int x = (int) vh.get(array, i);
assertEquals(x, v, "get int value");
assertEquals(v, x, "get int value");
}
if (iAligned) {
// Volatile
{
int x = (int) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile int value");
assertEquals(v, x, "getVolatile int value");
}
// Lazy
{
int x = (int) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease int value");
assertEquals(v, x, "getRelease int value");
}
// Opaque
{
int x = (int) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque int value");
assertEquals(v, x, "getOpaque int value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsLong
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsLong
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsLong
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsLong
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsLong
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsLong
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
static final int SIZE = Long.BYTES;
@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -190,17 +191,16 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), long.class);
assertEquals(long.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -262,7 +262,8 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -271,7 +272,6 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -1039,7 +1039,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "get long value");
assertEquals(VALUE_1, x, "get long value");
}
}
}
@ -1058,7 +1058,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "get long value");
assertEquals(VALUE_1, x, "get long value");
}
if (iAligned) {
@ -1066,21 +1066,21 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
long x = (long) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile long value");
assertEquals(VALUE_2, x, "setVolatile long value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
long x = (long) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease long value");
assertEquals(VALUE_1, x, "setRelease long value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
long x = (long) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque long value");
assertEquals(VALUE_2, x, "setOpaque long value");
}
vh.set(array, i, VALUE_1);
@ -1090,56 +1090,56 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
assertEquals(r, true, "success compareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndSet long value");
assertEquals(VALUE_2, x, "success compareAndSet long value");
}
{
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
assertEquals(r, false, "failing compareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndSet long value");
assertEquals(VALUE_2, x, "failing compareAndSet long value");
}
{
long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchange long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchange long value");
assertEquals(VALUE_1, x, "success compareAndExchange long value");
}
{
long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchange long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchange long value");
assertEquals(VALUE_1, x, "failing compareAndExchange long value");
}
{
long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire long value");
assertEquals(VALUE_2, x, "success compareAndExchangeAcquire long value");
}
{
long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire long value");
assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire long value");
}
{
long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeRelease long value");
assertEquals(VALUE_1, x, "success compareAndExchangeRelease long value");
}
{
long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease long value");
assertEquals(VALUE_1, x, "failing compareAndExchangeRelease long value");
}
{
@ -1150,14 +1150,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetPlain long value");
assertEquals(VALUE_2, x, "success weakCompareAndSetPlain long value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetPlain long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain long value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain long value");
}
{
@ -1168,14 +1168,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire long");
assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire long");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire long value");
assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire long value");
}
{
@ -1186,14 +1186,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetRelease long");
assertEquals(VALUE_2, x, "success weakCompareAndSetRelease long");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease long value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease long value");
}
{
@ -1204,14 +1204,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSet long");
assertEquals(VALUE_1, x, "success weakCompareAndSet long");
}
{
boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSet long value");
assertEquals(VALUE_1, x, "failing weakCompareAndSet long value");
}
// Compare set and get
@ -1219,27 +1219,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndSet(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSet long");
assertEquals(VALUE_1, o, "getAndSet long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSet long value");
assertEquals(VALUE_2, x, "getAndSet long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndSetAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetAcquire long");
assertEquals(VALUE_1, o, "getAndSetAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetAcquire long value");
assertEquals(VALUE_2, x, "getAndSetAcquire long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndSetRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetRelease long");
assertEquals(VALUE_1, o, "getAndSetRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetRelease long value");
assertEquals(VALUE_2, x, "getAndSetRelease long value");
}
// get and add, add and get
@ -1247,27 +1247,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndAdd(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAdd long");
assertEquals(VALUE_1, o, "getAndAdd long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd long value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAdd long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndAddAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAddAcquire long");
assertEquals(VALUE_1, o, "getAndAddAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire long value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAddAcquire long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndAddRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAddRelease long");
assertEquals(VALUE_1, o, "getAndAddRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease long value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAddRelease long value");
}
// get and bitwise or
@ -1275,27 +1275,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseOr(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOr long");
assertEquals(VALUE_1, o, "getAndBitwiseOr long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr long value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOr long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire long");
assertEquals(VALUE_1, o, "getAndBitwiseOrAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire long value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrAcquire long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOrRelease long");
assertEquals(VALUE_1, o, "getAndBitwiseOrRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease long value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrRelease long value");
}
// get and bitwise and
@ -1303,27 +1303,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseAnd(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAnd long");
assertEquals(VALUE_1, o, "getAndBitwiseAnd long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd long value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAnd long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire long");
assertEquals(VALUE_1, o, "getAndBitwiseAndAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire long value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndAcquire long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAndRelease long");
assertEquals(VALUE_1, o, "getAndBitwiseAndRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease long value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndRelease long value");
}
// get and bitwise xor
@ -1331,27 +1331,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseXor(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXor long");
assertEquals(VALUE_1, o, "getAndBitwiseXor long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor long value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXor long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire long");
assertEquals(VALUE_1, o, "getAndBitwiseXorAcquire long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire long value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorAcquire long value");
}
{
vh.set(array, i, VALUE_1);
long o = (long) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXorRelease long");
assertEquals(VALUE_1, o, "getAndBitwiseXorRelease long");
long x = (long) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease long value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorRelease long value");
}
}
}
@ -1375,26 +1375,26 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest {
// Plain
{
long x = (long) vh.get(array, i);
assertEquals(x, v, "get long value");
assertEquals(v, x, "get long value");
}
if (iAligned) {
// Volatile
{
long x = (long) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile long value");
assertEquals(v, x, "getVolatile long value");
}
// Lazy
{
long x = (long) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease long value");
assertEquals(v, x, "getRelease long value");
}
// Opaque
{
long x = (long) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque long value");
assertEquals(v, x, "getOpaque long value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsShort
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsShort
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsShort
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsShort
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsShort
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsShort
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
static final int SIZE = Short.BYTES;
@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -158,17 +159,16 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), short.class);
assertEquals(short.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -230,7 +230,8 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -239,7 +240,6 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -740,7 +740,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
short x = (short) vh.get(array, i);
assertEquals(x, VALUE_1, "get short value");
assertEquals(VALUE_1, x, "get short value");
}
}
}
@ -759,7 +759,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
short x = (short) vh.get(array, i);
assertEquals(x, VALUE_1, "get short value");
assertEquals(VALUE_1, x, "get short value");
}
if (iAligned) {
@ -767,21 +767,21 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
short x = (short) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile short value");
assertEquals(VALUE_2, x, "setVolatile short value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
short x = (short) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease short value");
assertEquals(VALUE_1, x, "setRelease short value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
short x = (short) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque short value");
assertEquals(VALUE_2, x, "setOpaque short value");
}
@ -807,26 +807,26 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest {
// Plain
{
short x = (short) vh.get(array, i);
assertEquals(x, v, "get short value");
assertEquals(v, x, "get short value");
}
if (iAligned) {
// Volatile
{
short x = (short) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile short value");
assertEquals(v, x, "getVolatile short value");
}
// Lazy
{
short x = (short) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease short value");
assertEquals(v, x, "getRelease short value");
}
// Opaque
{
short x = (short) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque short value");
assertEquals(v, x, "getOpaque short value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,20 +26,20 @@
* @modules java.base/jdk.internal.access.foreign
* @modules java.base/jdk.internal.foreign.layout
*
* @run testng/othervm -Xverify:all
* @run junit/othervm -Xverify:all
* -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false
* VarHandleTestExact
* @run testng/othervm -Xverify:all
* @run junit/othervm -Xverify:all
* -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false
* -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true
* -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true
* VarHandleTestExact
* @run testng/othervm -Xverify:all
* @run junit/othervm -Xverify:all
* -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false
* -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false
* -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false
* VarHandleTestExact
* @run testng/othervm -Xverify:all
* @run junit/othervm -Xverify:all
* -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false
* -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false
* -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true
@ -50,9 +50,6 @@ import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import jdk.internal.foreign.layout.ValueLayouts;
import org.testng.SkipException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
@ -64,8 +61,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestExact {
private static class Widget {
@ -90,12 +92,13 @@ public class VarHandleTestExact {
final Long aLongField_RO = 1234L;
}
@Test(dataProvider = "dataObjectAccess")
@ParameterizedTest
@MethodSource("dataObjectAccess")
public void testExactSet(String fieldBaseName, Class<?> fieldType, boolean ro, Object testValue,
SetX setter, GetX getter,
SetStaticX staticSetter, GetStaticX staticGetter)
throws NoSuchFieldException, IllegalAccessException {
if (ro) throw new SkipException("Can not test setter with read only field");
Assumptions.assumeFalse(ro, "Can not test setter with read only field");
VarHandle vh = MethodHandles.lookup().findVarHandle(Widget.class, fieldBaseName + "_RW", fieldType);
Widget w = new Widget();
@ -105,7 +108,8 @@ public class VarHandleTestExact {
".*\\Qhandle's method type (Widget," + fieldType.getSimpleName() + ")void \\E.*");
}
@Test(dataProvider = "dataObjectAccess")
@ParameterizedTest
@MethodSource("dataObjectAccess")
public void testExactGet(String fieldBaseName, Class<?> fieldType, boolean ro, Object testValue,
SetX setter, GetX getter,
SetStaticX staticSetter, GetStaticX staticGetter)
@ -119,12 +123,13 @@ public class VarHandleTestExact {
".*\\Qhandle's method type (Widget)" + fieldType.getSimpleName() + " \\E.*");
}
@Test(dataProvider = "dataObjectAccess")
@ParameterizedTest
@MethodSource("dataObjectAccess")
public void testExactSetStatic(String fieldBaseName, Class<?> fieldType, boolean ro, Object testValue,
SetX setter, GetX getter,
SetStaticX staticSetter, GetStaticX staticGetter)
throws NoSuchFieldException, IllegalAccessException {
if (ro) throw new SkipException("Can not test setter with read only field");
Assumptions.assumeFalse(ro, "Can not test setter with read only field");
VarHandle vh = MethodHandles.lookup().findStaticVarHandle(Widget.class, fieldBaseName + "_SRW", fieldType);
doTest(vh,
@ -133,7 +138,8 @@ public class VarHandleTestExact {
".*\\Qhandle's method type (" + fieldType.getSimpleName() + ")void \\E.*");
}
@Test(dataProvider = "dataObjectAccess")
@ParameterizedTest
@MethodSource("dataObjectAccess")
public void testExactGetStatic(String fieldBaseName, Class<?> fieldType, boolean ro, Object testValue,
SetX setter, GetX getter,
SetStaticX staticSetter, GetStaticX staticGetter)
@ -146,7 +152,8 @@ public class VarHandleTestExact {
".*\\Qhandle's method type ()" + fieldType.getSimpleName() + " \\E.*");
}
@Test(dataProvider = "dataSetArray")
@ParameterizedTest
@MethodSource("dataSetArray")
public void testExactArraySet(Class<?> arrayClass, Object testValue, SetArrayX setter) {
VarHandle vh = MethodHandles.arrayElementVarHandle(arrayClass);
Object arr = Array.newInstance(arrayClass.componentType(), 1);
@ -157,7 +164,8 @@ public class VarHandleTestExact {
".*\\Qhandle's method type (" + arrayClass.getSimpleName() + ",int," + arrayClass.componentType().getSimpleName() + ")void \\E.*");
}
@Test(dataProvider = "dataSetBuffer")
@ParameterizedTest
@MethodSource("dataSetBuffer")
public void testExactBufferSet(Class<?> arrayClass, Object testValue, SetBufferX setter) {
VarHandle vh = MethodHandles.byteBufferViewVarHandle(arrayClass, ByteOrder.nativeOrder());
ByteBuffer buff = ByteBuffer.allocateDirect(8);
@ -168,7 +176,8 @@ public class VarHandleTestExact {
".*\\Qhandle's method type (ByteBuffer,int," + arrayClass.componentType().getSimpleName() + ")void \\E.*");
}
@Test(dataProvider = "dataSetMemorySegment")
@ParameterizedTest
@MethodSource("dataSetMemorySegment")
public void testExactSegmentSet(Class<?> carrier, Object testValue, SetSegmentX setter) {
VarHandle vh = ValueLayouts.valueLayout(carrier, ByteOrder.nativeOrder()).varHandle();
try (Arena arena = Arena.ofConfined()) {
@ -265,7 +274,6 @@ public class VarHandleTestExact {
cases.add(new Object[] { carrier, testValue, setter });
}
@DataProvider
public static Object[][] dataObjectAccess() {
List<Object[]> cases = new ArrayList<>();
@ -334,7 +342,6 @@ public class VarHandleTestExact {
return cases.toArray(Object[][]::new);
}
@DataProvider
public static Object[][] dataSetArray() {
List<Object[]> cases = new ArrayList<>();
@ -355,7 +362,6 @@ public class VarHandleTestExact {
return cases.toArray(Object[][]::new);
}
@DataProvider
public static Object[][] dataSetBuffer() {
List<Object[]> cases = new ArrayList<>();
@ -373,7 +379,6 @@ public class VarHandleTestExact {
return cases.toArray(Object[][]::new);
}
@DataProvider
public static Object[][] dataSetMemorySegment() {
List<Object[]> cases = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,22 +25,22 @@
* @test
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessBoolean
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessBoolean
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
static final boolean static_final_v = true;
@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodHandleAccessBoolean.class, "final_v", boolean.class);
@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
}
static void testInstanceField(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable {
// Plain
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "set boolean value");
assertEquals(true, x, "set boolean value");
}
@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, false);
boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, false, "setVolatile boolean value");
assertEquals(false, x, "setVolatile boolean value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, true);
boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, true, "setRelease boolean value");
assertEquals(true, x, "setRelease boolean value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, false);
boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, false, "setOpaque boolean value");
assertEquals(false, x, "setOpaque boolean value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, true);
@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "success compareAndSet boolean value");
assertEquals(false, x, "success compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "failing compareAndSet boolean value");
assertEquals(false, x, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "success compareAndExchange boolean value");
assertEquals(true, x, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "failing compareAndExchange boolean value");
assertEquals(true, x, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
assertEquals(false, x, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
assertEquals(false, x, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
assertEquals(true, x, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
assertEquals(true, x, "failing compareAndExchangeRelease boolean value");
}
{
@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "success weakCompareAndSetPlain boolean value");
assertEquals(false, x, "success weakCompareAndSetPlain boolean value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, true, false);
assertEquals(success, false, "failing weakCompareAndSetPlain boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "failing weakCompareAndSetPlain boolean value");
assertEquals(false, x, "failing weakCompareAndSetPlain boolean value");
}
{
@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "success weakCompareAndSetAcquire boolean");
assertEquals(true, x, "success weakCompareAndSetAcquire boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, false, false);
assertEquals(success, false, "failing weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value");
assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value");
}
{
@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "success weakCompareAndSetRelease boolean");
assertEquals(false, x, "success weakCompareAndSetRelease boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, true, false);
assertEquals(success, false, "failing weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "failing weakCompareAndSetRelease boolean value");
assertEquals(false, x, "failing weakCompareAndSetRelease boolean value");
}
{
@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "success weakCompareAndSet boolean");
assertEquals(true, x, "success weakCompareAndSet boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, false, false);
assertEquals(success, false, "failing weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, true, "failing weakCompareAndSet boolean value");
assertEquals(true, x, "failing weakCompareAndSet boolean value");
}
// Compare set and get
{
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, false);
assertEquals(o, true, "getAndSet boolean");
assertEquals(true, o, "getAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, false, "getAndSet boolean value");
assertEquals(false, x, "getAndSet boolean value");
}
@ -300,27 +298,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseOr boolean");
assertEquals(true, o, "getAndBitwiseOr boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
assertEquals(true, o, "getAndBitwiseOrAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseOrRelease boolean");
assertEquals(true, o, "getAndBitwiseOrRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value");
}
// get and bitwise and
@ -328,27 +326,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseAnd boolean");
assertEquals(true, o, "getAndBitwiseAnd boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
assertEquals(true, o, "getAndBitwiseAndAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseAndRelease boolean");
assertEquals(true, o, "getAndBitwiseAndRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value");
}
// get and bitwise xor
@ -356,27 +354,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseXor boolean");
assertEquals(true, o, "getAndBitwiseXor boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
assertEquals(true, o, "getAndBitwiseXorAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, false);
assertEquals(o, true, "getAndBitwiseXorRelease boolean");
assertEquals(true, o, "getAndBitwiseXorRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value");
}
}
@ -396,7 +394,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "set boolean value");
assertEquals(true, x, "set boolean value");
}
@ -404,21 +402,21 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(false);
boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, false, "setVolatile boolean value");
assertEquals(false, x, "setVolatile boolean value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(true);
boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, true, "setRelease boolean value");
assertEquals(true, x, "setRelease boolean value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(false);
boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, false, "setOpaque boolean value");
assertEquals(false, x, "setOpaque boolean value");
}
hs.get(TestAccessMode.SET).invokeExact(true);
@ -428,56 +426,56 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "success compareAndSet boolean value");
assertEquals(false, x, "success compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "failing compareAndSet boolean value");
assertEquals(false, x, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "success compareAndExchange boolean value");
assertEquals(true, x, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "failing compareAndExchange boolean value");
assertEquals(true, x, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
assertEquals(false, x, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
assertEquals(false, x, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
assertEquals(true, x, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
assertEquals(true, x, "failing compareAndExchangeRelease boolean value");
}
{
@ -489,14 +487,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "success weakCompareAndSetPlain boolean value");
assertEquals(false, x, "success weakCompareAndSetPlain boolean value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(true, false);
assertEquals(success, false, "failing weakCompareAndSetPlain boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "failing weakCompareAndSetPlain boolean value");
assertEquals(false, x, "failing weakCompareAndSetPlain boolean value");
}
{
@ -508,7 +506,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "success weakCompareAndSetAcquire boolean");
assertEquals(true, x, "success weakCompareAndSetAcquire boolean");
}
{
@ -516,7 +514,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
boolean success = (boolean) mh.invokeExact(false, false);
assertEquals(success, false, "failing weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value");
assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value");
}
{
@ -528,14 +526,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "success weakCompareAndSetRelease boolean");
assertEquals(false, x, "success weakCompareAndSetRelease boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(true, false);
assertEquals(success, false, "failing weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "failing weakCompareAndSetRelease boolean value");
assertEquals(false, x, "failing weakCompareAndSetRelease boolean value");
}
{
@ -547,14 +545,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "success weakCompareAndSet boolean");
assertEquals(true, x, "success weakCompareAndSet boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(false, false);
assertEquals(success, false, "failing weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, true, "failing weakCompareAndSetRe boolean value");
assertEquals(true, x, "failing weakCompareAndSetRe boolean value");
}
// Compare set and get
@ -562,9 +560,9 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(false);
assertEquals(o, true, "getAndSet boolean");
assertEquals(true, o, "getAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "getAndSet boolean value");
assertEquals(false, x, "getAndSet boolean value");
}
// Compare set and get
@ -572,9 +570,9 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(false);
assertEquals(o, true, "getAndSetAcquire boolean");
assertEquals(true, o, "getAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "getAndSetAcquire boolean value");
assertEquals(false, x, "getAndSetAcquire boolean value");
}
// Compare set and get
@ -582,9 +580,9 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(false);
assertEquals(o, true, "getAndSetRelease boolean");
assertEquals(true, o, "getAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, false, "getAndSetRelease boolean value");
assertEquals(false, x, "getAndSetRelease boolean value");
}
@ -593,27 +591,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(false);
assertEquals(o, true, "getAndBitwiseOr boolean");
assertEquals(true, o, "getAndBitwiseOr boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(false);
assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
assertEquals(true, o, "getAndBitwiseOrAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(false);
assertEquals(o, true, "getAndBitwiseOrRelease boolean");
assertEquals(true, o, "getAndBitwiseOrRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value");
}
// get and bitwise and
@ -621,27 +619,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(false);
assertEquals(o, true, "getAndBitwiseAnd boolean");
assertEquals(true, o, "getAndBitwiseAnd boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(false);
assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
assertEquals(true, o, "getAndBitwiseAndAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(false);
assertEquals(o, true, "getAndBitwiseAndRelease boolean");
assertEquals(true, o, "getAndBitwiseAndRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value");
}
// get and bitwise xor
@ -649,27 +647,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(false);
assertEquals(o, true, "getAndBitwiseXor boolean");
assertEquals(true, o, "getAndBitwiseXor boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(false);
assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
assertEquals(true, o, "getAndBitwiseXorAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(false);
assertEquals(o, true, "getAndBitwiseXorRelease boolean");
assertEquals(true, o, "getAndBitwiseXorRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value");
}
}
@ -692,7 +690,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "get boolean value");
assertEquals(true, x, "get boolean value");
}
@ -700,21 +698,21 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, false);
boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, false, "setVolatile boolean value");
assertEquals(false, x, "setVolatile boolean value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, true);
boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, true, "setRelease boolean value");
assertEquals(true, x, "setRelease boolean value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, false);
boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, false, "setOpaque boolean value");
assertEquals(false, x, "setOpaque boolean value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
@ -724,56 +722,56 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
assertEquals(r, true, "success compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "success compareAndSet boolean value");
assertEquals(false, x, "success compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false);
assertEquals(r, false, "failing compareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "failing compareAndSet boolean value");
assertEquals(false, x, "failing compareAndSet boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, true);
assertEquals(r, false, "success compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "success compareAndExchange boolean value");
assertEquals(true, x, "success compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, false);
assertEquals(r, true, "failing compareAndExchange boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "failing compareAndExchange boolean value");
assertEquals(true, x, "failing compareAndExchange boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
assertEquals(false, x, "success compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false);
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
assertEquals(false, x, "failing compareAndExchangeAcquire boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, true);
assertEquals(r, false, "success compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
assertEquals(true, x, "success compareAndExchangeRelease boolean value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, false);
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
assertEquals(true, x, "failing compareAndExchangeRelease boolean value");
}
{
@ -785,14 +783,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "success weakCompareAndSetPlain boolean value");
assertEquals(false, x, "success weakCompareAndSetPlain boolean value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, true, false);
assertEquals(success, false, "failing weakCompareAndSetPlain boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "failing weakCompareAndSetPlain boolean value");
assertEquals(false, x, "failing weakCompareAndSetPlain boolean value");
}
{
@ -804,14 +802,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "success weakCompareAndSetAcquire boolean");
assertEquals(true, x, "success weakCompareAndSetAcquire boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, false, false);
assertEquals(success, false, "failing weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value");
assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value");
}
{
@ -823,14 +821,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "success weakCompareAndSetRelease boolean");
assertEquals(false, x, "success weakCompareAndSetRelease boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, true, false);
assertEquals(success, false, "failing weakCompareAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "failing weakCompareAndSetAcquire boolean value");
assertEquals(false, x, "failing weakCompareAndSetAcquire boolean value");
}
{
@ -842,14 +840,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "success weakCompareAndSet boolean");
assertEquals(true, x, "success weakCompareAndSet boolean");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, false, false);
assertEquals(success, false, "failing weakCompareAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, true, "failing weakCompareAndSet boolean value");
assertEquals(true, x, "failing weakCompareAndSet boolean value");
}
// Compare set and get
@ -857,27 +855,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, false);
assertEquals(o, true, "getAndSet boolean");
assertEquals(true, o, "getAndSet boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "getAndSet boolean value");
assertEquals(false, x, "getAndSet boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, false);
assertEquals(o, true, "getAndSetAcquire boolean");
assertEquals(true, o, "getAndSetAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "getAndSetAcquire boolean value");
assertEquals(false, x, "getAndSetAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, false);
assertEquals(o, true, "getAndSetRelease boolean");
assertEquals(true, o, "getAndSetRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, false, "getAndSetRelease boolean value");
assertEquals(false, x, "getAndSetRelease boolean value");
}
@ -886,27 +884,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseOr boolean");
assertEquals(true, o, "getAndBitwiseOr boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseOrAcquire boolean");
assertEquals(true, o, "getAndBitwiseOrAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseOrRelease boolean");
assertEquals(true, o, "getAndBitwiseOrRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value");
assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value");
}
// get and bitwise and
@ -914,27 +912,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseAnd boolean");
assertEquals(true, o, "getAndBitwiseAnd boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseAndAcquire boolean");
assertEquals(true, o, "getAndBitwiseAndAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseAndRelease boolean");
assertEquals(true, o, "getAndBitwiseAndRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value");
assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value");
}
// get and bitwise xor
@ -942,27 +940,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseXor boolean");
assertEquals(true, o, "getAndBitwiseXor boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseXorAcquire boolean");
assertEquals(true, o, "getAndBitwiseXorAcquire boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, true);
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, false);
assertEquals(o, true, "getAndBitwiseXorRelease boolean");
assertEquals(true, o, "getAndBitwiseXorRelease boolean");
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value");
assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,22 +25,22 @@
* @test
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessDouble
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessDouble
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
static final double static_final_v = 1.0d;
@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodHandleAccessDouble.class, "final_v", double.class);
@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(double[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
}
static void testInstanceField(VarHandleTestMethodHandleAccessDouble recv, Handles hs) throws Throwable {
// Plain
{
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "set double value");
assertEquals(1.0d, x, "set double value");
}
@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0d);
double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, 2.0d, "setVolatile double value");
assertEquals(2.0d, x, "setVolatile double value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0d);
double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, 1.0d, "setRelease double value");
assertEquals(1.0d, x, "setRelease double value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0d);
double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, 2.0d, "setOpaque double value");
assertEquals(2.0d, x, "setOpaque double value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "success compareAndSet double value");
assertEquals(2.0d, x, "success compareAndSet double value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "failing compareAndSet double value");
assertEquals(2.0d, x, "failing compareAndSet double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success compareAndExchange double value");
assertEquals(1.0d, x, "success compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
assertEquals(1.0d, x, "failing compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
assertEquals(1.0d, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
assertEquals(1.0d, x, "failing compareAndExchangeRelease double value");
}
{
@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value");
}
{
@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
assertEquals(1.0d, x, "success weakCompareAndSetAcquire double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
assertEquals(2.0d, x, "success weakCompareAndSetRelease double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value");
assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value");
}
{
@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "success weakCompareAndSet double");
assertEquals(1.0d, x, "success weakCompareAndSet double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0d, "failing weakCompareAndSet double value");
assertEquals(1.0d, x, "failing weakCompareAndSet double value");
}
// Compare set and get
{
double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
assertEquals(1.0d, o, "getAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0d, "getAndSet double value");
assertEquals(2.0d, x, "getAndSet double value");
}
// get and add, add and get
@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0d);
assertEquals(o, 1.0d, "getAndAdd double");
assertEquals(1.0d, o, "getAndAdd double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0d);
assertEquals(o, 1.0d, "getAndAddAcquire double");
assertEquals(1.0d, o, "getAndAddAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0d);
assertEquals(o, 1.0d, "getAndAddRelease double");
assertEquals(1.0d, o, "getAndAddRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value");
}
}
@ -340,7 +338,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "set double value");
assertEquals(1.0d, x, "set double value");
}
@ -348,21 +346,21 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0d);
double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, 2.0d, "setVolatile double value");
assertEquals(2.0d, x, "setVolatile double value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0d);
double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, 1.0d, "setRelease double value");
assertEquals(1.0d, x, "setRelease double value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0d);
double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, 2.0d, "setOpaque double value");
assertEquals(2.0d, x, "setOpaque double value");
}
hs.get(TestAccessMode.SET).invokeExact(1.0d);
@ -372,56 +370,56 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "success compareAndSet double value");
assertEquals(2.0d, x, "success compareAndSet double value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "failing compareAndSet double value");
assertEquals(2.0d, x, "failing compareAndSet double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success compareAndExchange double value");
assertEquals(1.0d, x, "success compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing compareAndExchange double value");
assertEquals(1.0d, x, "failing compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
assertEquals(1.0d, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
assertEquals(1.0d, x, "failing compareAndExchangeRelease double value");
}
{
@ -433,14 +431,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value");
}
{
@ -452,7 +450,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
assertEquals(1.0d, x, "success weakCompareAndSetAcquire double");
}
{
@ -460,7 +458,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
boolean success = (boolean) mh.invokeExact(2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -472,14 +470,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
assertEquals(2.0d, x, "success weakCompareAndSetRelease double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value");
assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value");
}
{
@ -491,14 +489,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "success weakCompareAndSet double");
assertEquals(1.0d, x, "success weakCompareAndSet double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0d, "failing weakCompareAndSetRe double value");
assertEquals(1.0d, x, "failing weakCompareAndSetRe double value");
}
// Compare set and get
@ -506,9 +504,9 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2.0d);
assertEquals(o, 1.0d, "getAndSet double");
assertEquals(1.0d, o, "getAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "getAndSet double value");
assertEquals(2.0d, x, "getAndSet double value");
}
// Compare set and get
@ -516,9 +514,9 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0d);
assertEquals(o, 1.0d, "getAndSetAcquire double");
assertEquals(1.0d, o, "getAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "getAndSetAcquire double value");
assertEquals(2.0d, x, "getAndSetAcquire double value");
}
// Compare set and get
@ -526,9 +524,9 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0d);
assertEquals(o, 1.0d, "getAndSetRelease double");
assertEquals(1.0d, o, "getAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0d, "getAndSetRelease double value");
assertEquals(2.0d, x, "getAndSetRelease double value");
}
// get and add, add and get
@ -536,27 +534,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0d);
assertEquals(o, 1.0d, "getAndAdd double");
assertEquals(1.0d, o, "getAndAdd double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0d);
assertEquals(o, 1.0d, "getAndAddAcquire double");
assertEquals(1.0d, o, "getAndAddAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0d);
assertEquals(o, 1.0d, "getAndAddRelease double");
assertEquals(1.0d, o, "getAndAddRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value");
}
}
@ -580,7 +578,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "get double value");
assertEquals(1.0d, x, "get double value");
}
@ -588,21 +586,21 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0d);
double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, 2.0d, "setVolatile double value");
assertEquals(2.0d, x, "setVolatile double value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0d);
double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, 1.0d, "setRelease double value");
assertEquals(1.0d, x, "setRelease double value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0d);
double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, 2.0d, "setOpaque double value");
assertEquals(2.0d, x, "setOpaque double value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
@ -612,56 +610,56 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 2.0d);
assertEquals(r, true, "success compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "success compareAndSet double value");
assertEquals(2.0d, x, "success compareAndSet double value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 3.0d);
assertEquals(r, false, "failing compareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "failing compareAndSet double value");
assertEquals(2.0d, x, "failing compareAndSet double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success compareAndExchange double value");
assertEquals(1.0d, x, "success compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchange double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing compareAndExchange double value");
assertEquals(1.0d, x, "failing compareAndExchange double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 2.0d);
assertEquals(r, 1.0d, "success compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "success compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 3.0d);
assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value");
assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 1.0d);
assertEquals(r, 2.0d, "success compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success compareAndExchangeRelease double value");
assertEquals(1.0d, x, "success compareAndExchangeRelease double value");
}
{
double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(r, 1.0d, "failing compareAndExchangeRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value");
assertEquals(1.0d, x, "failing compareAndExchangeRelease double value");
}
{
@ -673,14 +671,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "success weakCompareAndSetPlain double value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetPlain double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value");
assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value");
}
{
@ -692,14 +690,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double");
assertEquals(1.0d, x, "success weakCompareAndSetAcquire double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -711,14 +709,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "success weakCompareAndSetRelease double");
assertEquals(2.0d, x, "success weakCompareAndSetRelease double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 1.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "failing weakCompareAndSetAcquire double value");
assertEquals(2.0d, x, "failing weakCompareAndSetAcquire double value");
}
{
@ -730,14 +728,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "success weakCompareAndSet double");
assertEquals(1.0d, x, "success weakCompareAndSet double");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 2.0d, 3.0d);
assertEquals(success, false, "failing weakCompareAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0d, "failing weakCompareAndSet double value");
assertEquals(1.0d, x, "failing weakCompareAndSet double value");
}
// Compare set and get
@ -745,27 +743,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSet double");
assertEquals(1.0d, o, "getAndSet double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "getAndSet double value");
assertEquals(2.0d, x, "getAndSet double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSetAcquire double");
assertEquals(1.0d, o, "getAndSetAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "getAndSetAcquire double value");
assertEquals(2.0d, x, "getAndSetAcquire double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndSetRelease double");
assertEquals(1.0d, o, "getAndSetRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0d, "getAndSetRelease double value");
assertEquals(2.0d, x, "getAndSetRelease double value");
}
// get and add, add and get
@ -773,27 +771,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndAdd double");
assertEquals(1.0d, o, "getAndAdd double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndAddAcquire double");
assertEquals(1.0d, o, "getAndAddAcquire double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d);
double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0d);
assertEquals(o, 1.0d, "getAndAddRelease double");
assertEquals(1.0d, o, "getAndAddRelease double");
double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value");
assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,22 +25,22 @@
* @test
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessFloat
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessFloat
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
static final float static_final_v = 1.0f;
@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodHandleAccessFloat.class, "final_v", float.class);
@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(float[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
}
static void testInstanceField(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable {
// Plain
{
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "set float value");
assertEquals(1.0f, x, "set float value");
}
@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0f);
float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, 2.0f, "setVolatile float value");
assertEquals(2.0f, x, "setVolatile float value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0f);
float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, 1.0f, "setRelease float value");
assertEquals(1.0f, x, "setRelease float value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0f);
float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, 2.0f, "setOpaque float value");
assertEquals(2.0f, x, "setOpaque float value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "success compareAndSet float value");
assertEquals(2.0f, x, "success compareAndSet float value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "failing compareAndSet float value");
assertEquals(2.0f, x, "failing compareAndSet float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success compareAndExchange float value");
assertEquals(1.0f, x, "success compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
assertEquals(1.0f, x, "failing compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
assertEquals(1.0f, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
assertEquals(1.0f, x, "failing compareAndExchangeRelease float value");
}
{
@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value");
}
{
@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
assertEquals(1.0f, x, "success weakCompareAndSetAcquire float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
assertEquals(2.0f, x, "success weakCompareAndSetRelease float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value");
}
{
@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "success weakCompareAndSet float");
assertEquals(1.0f, x, "success weakCompareAndSet float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
assertEquals(1.0f, x, "failing weakCompareAndSet float value");
}
// Compare set and get
{
float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
assertEquals(1.0f, o, "getAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, 2.0f, "getAndSet float value");
assertEquals(2.0f, x, "getAndSet float value");
}
// get and add, add and get
@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0f);
assertEquals(o, 1.0f, "getAndAdd float");
assertEquals(1.0f, o, "getAndAdd float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0f);
assertEquals(o, 1.0f, "getAndAddAcquire float");
assertEquals(1.0f, o, "getAndAddAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0f);
assertEquals(o, 1.0f, "getAndAddRelease float");
assertEquals(1.0f, o, "getAndAddRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value");
}
}
@ -340,7 +338,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "set float value");
assertEquals(1.0f, x, "set float value");
}
@ -348,21 +346,21 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0f);
float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, 2.0f, "setVolatile float value");
assertEquals(2.0f, x, "setVolatile float value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0f);
float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, 1.0f, "setRelease float value");
assertEquals(1.0f, x, "setRelease float value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0f);
float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, 2.0f, "setOpaque float value");
assertEquals(2.0f, x, "setOpaque float value");
}
hs.get(TestAccessMode.SET).invokeExact(1.0f);
@ -372,56 +370,56 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "success compareAndSet float value");
assertEquals(2.0f, x, "success compareAndSet float value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "failing compareAndSet float value");
assertEquals(2.0f, x, "failing compareAndSet float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success compareAndExchange float value");
assertEquals(1.0f, x, "success compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing compareAndExchange float value");
assertEquals(1.0f, x, "failing compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
assertEquals(1.0f, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
assertEquals(1.0f, x, "failing compareAndExchangeRelease float value");
}
{
@ -433,14 +431,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value");
}
{
@ -452,7 +450,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
assertEquals(1.0f, x, "success weakCompareAndSetAcquire float");
}
{
@ -460,7 +458,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
boolean success = (boolean) mh.invokeExact(2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -472,14 +470,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
assertEquals(2.0f, x, "success weakCompareAndSetRelease float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value");
}
{
@ -491,14 +489,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "success weakCompareAndSet float");
assertEquals(1.0f, x, "success weakCompareAndSet float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 1.0f, "failing weakCompareAndSetRe float value");
assertEquals(1.0f, x, "failing weakCompareAndSetRe float value");
}
// Compare set and get
@ -506,9 +504,9 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2.0f);
assertEquals(o, 1.0f, "getAndSet float");
assertEquals(1.0f, o, "getAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "getAndSet float value");
assertEquals(2.0f, x, "getAndSet float value");
}
// Compare set and get
@ -516,9 +514,9 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0f);
assertEquals(o, 1.0f, "getAndSetAcquire float");
assertEquals(1.0f, o, "getAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "getAndSetAcquire float value");
assertEquals(2.0f, x, "getAndSetAcquire float value");
}
// Compare set and get
@ -526,9 +524,9 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0f);
assertEquals(o, 1.0f, "getAndSetRelease float");
assertEquals(1.0f, o, "getAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, 2.0f, "getAndSetRelease float value");
assertEquals(2.0f, x, "getAndSetRelease float value");
}
// get and add, add and get
@ -536,27 +534,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0f);
assertEquals(o, 1.0f, "getAndAdd float");
assertEquals(1.0f, o, "getAndAdd float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0f);
assertEquals(o, 1.0f, "getAndAddAcquire float");
assertEquals(1.0f, o, "getAndAddAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0f);
assertEquals(o, 1.0f, "getAndAddRelease float");
assertEquals(1.0f, o, "getAndAddRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value");
}
}
@ -580,7 +578,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "get float value");
assertEquals(1.0f, x, "get float value");
}
@ -588,21 +586,21 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0f);
float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, 2.0f, "setVolatile float value");
assertEquals(2.0f, x, "setVolatile float value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0f);
float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, 1.0f, "setRelease float value");
assertEquals(1.0f, x, "setRelease float value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0f);
float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, 2.0f, "setOpaque float value");
assertEquals(2.0f, x, "setOpaque float value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
@ -612,56 +610,56 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f);
assertEquals(r, true, "success compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "success compareAndSet float value");
assertEquals(2.0f, x, "success compareAndSet float value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 3.0f);
assertEquals(r, false, "failing compareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "failing compareAndSet float value");
assertEquals(2.0f, x, "failing compareAndSet float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success compareAndExchange float value");
assertEquals(1.0f, x, "success compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchange float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing compareAndExchange float value");
assertEquals(1.0f, x, "failing compareAndExchange float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 2.0f);
assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "success compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f);
assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 1.0f);
assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
assertEquals(1.0f, x, "success compareAndExchangeRelease float value");
}
{
float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
assertEquals(1.0f, x, "failing compareAndExchangeRelease float value");
}
{
@ -673,14 +671,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "success weakCompareAndSetPlain float value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetPlain float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value");
}
{
@ -692,14 +690,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
assertEquals(1.0f, x, "success weakCompareAndSetAcquire float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -711,14 +709,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
assertEquals(2.0f, x, "success weakCompareAndSetRelease float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "failing weakCompareAndSetAcquire float value");
assertEquals(2.0f, x, "failing weakCompareAndSetAcquire float value");
}
{
@ -730,14 +728,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "success weakCompareAndSet float");
assertEquals(1.0f, x, "success weakCompareAndSet float");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 2.0f, 3.0f);
assertEquals(success, false, "failing weakCompareAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
assertEquals(1.0f, x, "failing weakCompareAndSet float value");
}
// Compare set and get
@ -745,27 +743,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSet float");
assertEquals(1.0f, o, "getAndSet float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "getAndSet float value");
assertEquals(2.0f, x, "getAndSet float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSetAcquire float");
assertEquals(1.0f, o, "getAndSetAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "getAndSetAcquire float value");
assertEquals(2.0f, x, "getAndSetAcquire float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndSetRelease float");
assertEquals(1.0f, o, "getAndSetRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, 2.0f, "getAndSetRelease float value");
assertEquals(2.0f, x, "getAndSetRelease float value");
}
// get and add, add and get
@ -773,27 +771,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndAdd float");
assertEquals(1.0f, o, "getAndAdd float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndAddAcquire float");
assertEquals(1.0f, o, "getAndAddAcquire float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f);
float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0f);
assertEquals(o, 1.0f, "getAndAddRelease float");
assertEquals(1.0f, o, "getAndAddRelease float");
float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,22 +25,22 @@
* @test
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessString
* @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessString
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
static final String static_final_v = "foo";
@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodHandleAccessString.class, "final_v", String.class);
@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(String[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
}
static void testInstanceField(VarHandleTestMethodHandleAccessString recv, Handles hs) throws Throwable {
// Plain
{
hs.get(TestAccessMode.SET).invokeExact(recv, "foo");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "set String value");
assertEquals("foo", x, "set String value");
}
@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, "bar");
String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
assertEquals(x, "bar", "setVolatile String value");
assertEquals("bar", x, "setVolatile String value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, "foo");
String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
assertEquals(x, "foo", "setRelease String value");
assertEquals("foo", x, "setRelease String value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, "bar");
String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
assertEquals(x, "bar", "setOpaque String value");
assertEquals("bar", x, "setOpaque String value");
}
hs.get(TestAccessMode.SET).invokeExact(recv, "foo");
@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, "foo", "bar");
assertEquals(r, true, "success compareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "success compareAndSet String value");
assertEquals("bar", x, "success compareAndSet String value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, "foo", "baz");
assertEquals(r, false, "failing compareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "failing compareAndSet String value");
assertEquals("bar", x, "failing compareAndSet String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "success compareAndExchange String value");
assertEquals("foo", x, "success compareAndExchange String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "failing compareAndExchange String value");
assertEquals("foo", x, "failing compareAndExchange String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, "foo", "bar");
assertEquals(r, "foo", "success compareAndExchangeAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
assertEquals("bar", x, "success compareAndExchangeAcquire String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, "foo", "baz");
assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
assertEquals("bar", x, "failing compareAndExchangeAcquire String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "success compareAndExchangeRelease String value");
assertEquals("foo", x, "success compareAndExchangeRelease String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
assertEquals("foo", x, "failing compareAndExchangeRelease String value");
}
{
@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "success weakCompareAndSetPlain String value");
assertEquals("bar", x, "success weakCompareAndSetPlain String value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetPlain String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "failing weakCompareAndSetPlain String value");
assertEquals("bar", x, "failing weakCompareAndSetPlain String value");
}
{
@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "success weakCompareAndSetAcquire String");
assertEquals("foo", x, "success weakCompareAndSetAcquire String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value");
assertEquals("foo", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "success weakCompareAndSetRelease String");
assertEquals("bar", x, "success weakCompareAndSetRelease String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "failing weakCompareAndSetRelease String value");
assertEquals("bar", x, "failing weakCompareAndSetRelease String value");
}
{
@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "success weakCompareAndSet String");
assertEquals("foo", x, "success weakCompareAndSet String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "foo", "failing weakCompareAndSet String value");
assertEquals("foo", x, "failing weakCompareAndSet String value");
}
// Compare set and get
{
String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, "bar");
assertEquals(o, "foo", "getAndSet String");
assertEquals("foo", o, "getAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv);
assertEquals(x, "bar", "getAndSet String value");
assertEquals("bar", x, "getAndSet String value");
}
@ -318,7 +316,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact("foo");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "set String value");
assertEquals("foo", x, "set String value");
}
@ -326,21 +324,21 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact("bar");
String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
assertEquals(x, "bar", "setVolatile String value");
assertEquals("bar", x, "setVolatile String value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact("foo");
String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
assertEquals(x, "foo", "setRelease String value");
assertEquals("foo", x, "setRelease String value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact("bar");
String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
assertEquals(x, "bar", "setOpaque String value");
assertEquals("bar", x, "setOpaque String value");
}
hs.get(TestAccessMode.SET).invokeExact("foo");
@ -350,56 +348,56 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "bar");
assertEquals(r, true, "success compareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "success compareAndSet String value");
assertEquals("bar", x, "success compareAndSet String value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "baz");
assertEquals(r, false, "failing compareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "failing compareAndSet String value");
assertEquals("bar", x, "failing compareAndSet String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "foo");
assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "success compareAndExchange String value");
assertEquals("foo", x, "success compareAndExchange String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "baz");
assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "failing compareAndExchange String value");
assertEquals("foo", x, "failing compareAndExchange String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "bar");
assertEquals(r, "foo", "success compareAndExchangeAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
assertEquals("bar", x, "success compareAndExchangeAcquire String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "baz");
assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
assertEquals("bar", x, "failing compareAndExchangeAcquire String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "success compareAndExchangeRelease String value");
assertEquals("foo", x, "success compareAndExchangeRelease String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
assertEquals("foo", x, "failing compareAndExchangeRelease String value");
}
{
@ -411,14 +409,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "success weakCompareAndSetPlain String value");
assertEquals("bar", x, "success weakCompareAndSetPlain String value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact("foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetPlain String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "failing weakCompareAndSetPlain String value");
assertEquals("bar", x, "failing weakCompareAndSetPlain String value");
}
{
@ -430,7 +428,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "success weakCompareAndSetAcquire String");
assertEquals("foo", x, "success weakCompareAndSetAcquire String");
}
{
@ -438,7 +436,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
boolean success = (boolean) mh.invokeExact("bar", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value");
assertEquals("foo", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -450,14 +448,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "success weakCompareAndSetRelease String");
assertEquals("bar", x, "success weakCompareAndSetRelease String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact("foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "failing weakCompareAndSetRelease String value");
assertEquals("bar", x, "failing weakCompareAndSetRelease String value");
}
{
@ -469,14 +467,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "success weakCompareAndSet String");
assertEquals("foo", x, "success weakCompareAndSet String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact("bar", "baz");
assertEquals(success, false, "failing weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "foo", "failing weakCompareAndSetRe String value");
assertEquals("foo", x, "failing weakCompareAndSetRe String value");
}
// Compare set and get
@ -484,9 +482,9 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact("foo");
String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact("bar");
assertEquals(o, "foo", "getAndSet String");
assertEquals("foo", o, "getAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "getAndSet String value");
assertEquals("bar", x, "getAndSet String value");
}
// Compare set and get
@ -494,9 +492,9 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact("foo");
String o = (String) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact("bar");
assertEquals(o, "foo", "getAndSetAcquire String");
assertEquals("foo", o, "getAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "getAndSetAcquire String value");
assertEquals("bar", x, "getAndSetAcquire String value");
}
// Compare set and get
@ -504,9 +502,9 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact("foo");
String o = (String) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact("bar");
assertEquals(o, "foo", "getAndSetRelease String");
assertEquals("foo", o, "getAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact();
assertEquals(x, "bar", "getAndSetRelease String value");
assertEquals("bar", x, "getAndSetRelease String value");
}
@ -536,7 +534,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "get String value");
assertEquals("foo", x, "get String value");
}
@ -544,21 +542,21 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
{
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, "bar");
String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
assertEquals(x, "bar", "setVolatile String value");
assertEquals("bar", x, "setVolatile String value");
}
// Lazy
{
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, "foo");
String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
assertEquals(x, "foo", "setRelease String value");
assertEquals("foo", x, "setRelease String value");
}
// Opaque
{
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, "bar");
String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
assertEquals(x, "bar", "setOpaque String value");
assertEquals("bar", x, "setOpaque String value");
}
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
@ -568,56 +566,56 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "bar");
assertEquals(r, true, "success compareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "success compareAndSet String value");
assertEquals("bar", x, "success compareAndSet String value");
}
{
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "baz");
assertEquals(r, false, "failing compareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "failing compareAndSet String value");
assertEquals("bar", x, "failing compareAndSet String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "success compareAndExchange String value");
assertEquals("foo", x, "success compareAndExchange String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchange String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "failing compareAndExchange String value");
assertEquals("foo", x, "failing compareAndExchange String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "bar");
assertEquals(r, "foo", "success compareAndExchangeAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "success compareAndExchangeAcquire String value");
assertEquals("bar", x, "success compareAndExchangeAcquire String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "baz");
assertEquals(r, "bar", "failing compareAndExchangeAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value");
assertEquals("bar", x, "failing compareAndExchangeAcquire String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "foo");
assertEquals(r, "bar", "success compareAndExchangeRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "success compareAndExchangeRelease String value");
assertEquals("foo", x, "success compareAndExchangeRelease String value");
}
{
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "baz");
assertEquals(r, "foo", "failing compareAndExchangeRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "failing compareAndExchangeRelease String value");
assertEquals("foo", x, "failing compareAndExchangeRelease String value");
}
{
@ -629,14 +627,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "success weakCompareAndSetPlain String value");
assertEquals("bar", x, "success weakCompareAndSetPlain String value");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetPlain String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "failing weakCompareAndSetPlain String value");
assertEquals("bar", x, "failing weakCompareAndSetPlain String value");
}
{
@ -648,14 +646,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "success weakCompareAndSetAcquire String");
assertEquals("foo", x, "success weakCompareAndSetAcquire String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value");
assertEquals("foo", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -667,14 +665,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "success weakCompareAndSetRelease String");
assertEquals("bar", x, "success weakCompareAndSetRelease String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, "foo", "baz");
assertEquals(success, false, "failing weakCompareAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "failing weakCompareAndSetAcquire String value");
assertEquals("bar", x, "failing weakCompareAndSetAcquire String value");
}
{
@ -686,14 +684,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
}
assertEquals(success, true, "success weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "success weakCompareAndSet String");
assertEquals("foo", x, "success weakCompareAndSet String");
}
{
boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, "bar", "baz");
assertEquals(success, false, "failing weakCompareAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "foo", "failing weakCompareAndSet String value");
assertEquals("foo", x, "failing weakCompareAndSet String value");
}
// Compare set and get
@ -701,27 +699,27 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, "bar");
assertEquals(o, "foo", "getAndSet String");
assertEquals("foo", o, "getAndSet String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "getAndSet String value");
assertEquals("bar", x, "getAndSet String value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
String o = (String) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, "bar");
assertEquals(o, "foo", "getAndSetAcquire String");
assertEquals("foo", o, "getAndSetAcquire String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "getAndSetAcquire String value");
assertEquals("bar", x, "getAndSetAcquire String value");
}
{
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo");
String o = (String) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, "bar");
assertEquals(o, "foo", "getAndSetRelease String");
assertEquals("foo", o, "getAndSetRelease String");
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i);
assertEquals(x, "bar", "getAndSetRelease String value");
assertEquals("bar", x, "getAndSetRelease String value");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeBoolean
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeBoolean
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
* @run junit/othervm VarHandleTestMethodTypeBoolean
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeBoolean
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
static final boolean static_final_v = true;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeBoolean.class, "final_v", boolean.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeByte
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeByte
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
* @run junit/othervm VarHandleTestMethodTypeByte
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeByte
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeByte extends VarHandleBaseTest {
static final byte static_final_v = (byte)0x01;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeByte.class, "final_v", byte.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeChar
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeChar
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar
* @run junit/othervm VarHandleTestMethodTypeChar
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeChar
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeChar extends VarHandleBaseTest {
static final char static_final_v = '\u0123';
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeChar.class, "final_v", char.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(char[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeChar recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeDouble
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeDouble
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
* @run junit/othervm VarHandleTestMethodTypeDouble
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeDouble
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
static final double static_final_v = 1.0d;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeDouble.class, "final_v", double.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(double[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeDouble recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeFloat
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeFloat
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat
* @run junit/othervm VarHandleTestMethodTypeFloat
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeFloat
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest {
static final float static_final_v = 1.0f;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeFloat.class, "final_v", float.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(float[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeFloat recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeInt
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeInt
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt
* @run junit/othervm VarHandleTestMethodTypeInt
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeInt
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeInt extends VarHandleBaseTest {
static final int static_final_v = 0x01234567;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeInt.class, "final_v", int.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(int[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeInt recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeLong
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeLong
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
* @run junit/othervm VarHandleTestMethodTypeLong
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeLong
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
static final long static_final_v = 0x0123456789ABCDEFL;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeLong.class, "final_v", long.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(long[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeLong recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeShort
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeShort
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort
* @run junit/othervm VarHandleTestMethodTypeShort
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeShort
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
static final short static_final_v = (short)0x0123;
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeShort.class, "final_v", short.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(short[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeShort recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodTypeString
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeString
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString
* @run junit/othervm VarHandleTestMethodTypeString
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeString
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
static final String static_final_v = "foo";
@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodTypeString.class, "final_v", String.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle(String[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeString recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,9 @@
/*
* @test
* @run testng VarHandleTestReflection
* @run junit VarHandleTestReflection
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandleInfo;
@ -36,11 +34,16 @@ import java.lang.invoke.VarHandle;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.stream.Stream;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertThrows;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestReflection extends VarHandleBaseTest {
String string;
@DataProvider
public static Object[][] accessModesProvider() {
return Stream.of(VarHandle.AccessMode.values()).
map(am -> new Object[]{am}).
@ -52,17 +55,19 @@ public class VarHandleTestReflection extends VarHandleBaseTest {
findVarHandle(VarHandleTestReflection.class, "string", String.class);
}
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
@ParameterizedTest
@MethodSource("accessModesProvider")
public void methodInvocationArgumentMismatch(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
// Try a reflective invoke using a Method, with no arguments
Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class);
vhm.invoke(v, new Object[]{});
assertThrows(IllegalArgumentException.class, () -> vhm.invoke(v, new Object[]{}));
}
@Test(dataProvider = "accessModesProvider")
@ParameterizedTest
@MethodSource("accessModesProvider")
public void methodInvocationMatchingArguments(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
@ -70,17 +75,15 @@ public class VarHandleTestReflection extends VarHandleBaseTest {
Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class);
Object arg = new Object[0];
try {
vhm.invoke(v, arg);
} catch (InvocationTargetException e) {
if (!(e.getCause() instanceof UnsupportedOperationException)) {
throw new RuntimeException("expected UnsupportedOperationException but got: "
+ e.getCause().getClass().getName(), e);
}
var e = assertThrows(InvocationTargetException.class, () -> vhm.invoke(v, arg));
if (!(e.getCause() instanceof UnsupportedOperationException)) {
throw new RuntimeException("expected UnsupportedOperationException but got: "
+ e.getCause().getClass().getName(), e);
}
}
@Test(dataProvider = "accessModesProvider", expectedExceptions = UnsupportedOperationException.class)
@ParameterizedTest
@MethodSource("accessModesProvider")
public void methodHandleInvoke(VarHandle.AccessMode accessMode) throws Throwable {
VarHandle v = handle();
@ -90,10 +93,13 @@ public class VarHandleTestReflection extends VarHandleBaseTest {
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[]{});
assertThrows(UnsupportedOperationException.class, () -> {
Object o = (Object) mh.invoke(v, new Object[]{});
});
}
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
@ParameterizedTest
@MethodSource("accessModesProvider")
public void methodInvocationFromMethodInfo(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
@ -104,10 +110,13 @@ public class VarHandleTestReflection extends VarHandleBaseTest {
VarHandle.class.getMethod(accessMode.methodName(), Object[].class));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
Method im = info.reflectAs(Method.class, MethodHandles.lookup());
im.invoke(v, new Object[]{});
assertThrows(IllegalArgumentException.class, () -> {
im.invoke(v, new Object[]{});
});
}
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
@ParameterizedTest
@MethodSource("accessModesProvider")
public void reflectAsFromVarHandleInvoker(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
@ -116,10 +125,11 @@ public class VarHandleTestReflection extends VarHandleBaseTest {
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
info.reflectAs(Method.class, MethodHandles.lookup());
assertThrows(IllegalArgumentException.class, () -> info.reflectAs(Method.class, MethodHandles.lookup()));
}
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
@ParameterizedTest
@MethodSource("accessModesProvider")
public void reflectAsFromFindVirtual(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
@ -128,6 +138,6 @@ public class VarHandleTestReflection extends VarHandleBaseTest {
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
info.reflectAs(Method.class, MethodHandles.lookup());
assertThrows(IllegalArgumentException.class, () -> info.reflectAs(Method.class, MethodHandles.lookup()));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,25 +26,25 @@
* @bug 8154556
* @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations
* to hit compilation thresholds
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAs$Type$
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAs$Type$
* @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAs$Type$
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAs$Type$
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAs$Type$
* @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAs$Type$
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
static final int SIZE = $BoxType$.BYTES;
@ -111,7 +111,8 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}
}
@Test(dataProvider = "varHandlesProvider")
@ParameterizedTest
@MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider")
public void testIsAccessModeSupported(VarHandleSource vhs) {
VarHandle vh = vhs.s;
@ -206,17 +207,16 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
#end[Bitwise]
}
@Test(dataProvider = "typesProvider")
@ParameterizedTest
@MethodSource("typesProvider")
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) {
assertEquals(vh.varType(), $type$.class);
assertEquals($type$.class, vh.varType());
assertEquals(vh.coordinateTypes(), pts);
assertEquals(pts, vh.coordinateTypes());
testTypes(vh);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -278,7 +278,8 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -287,7 +288,6 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}
}
static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
VarHandle vh = vhs.s;
byte[] array = null;
@ -1272,7 +1272,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "get $type$ value");
assertEquals(VALUE_1, x, "get $type$ value");
}
}
}
@ -1291,7 +1291,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
{
vh.set(array, i, VALUE_1);
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "get $type$ value");
assertEquals(VALUE_1, x, "get $type$ value");
}
if (iAligned) {
@ -1299,21 +1299,21 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
{
vh.setVolatile(array, i, VALUE_2);
$type$ x = ($type$) vh.getVolatile(array, i);
assertEquals(x, VALUE_2, "setVolatile $type$ value");
assertEquals(VALUE_2, x, "setVolatile $type$ value");
}
// Lazy
{
vh.setRelease(array, i, VALUE_1);
$type$ x = ($type$) vh.getAcquire(array, i);
assertEquals(x, VALUE_1, "setRelease $type$ value");
assertEquals(VALUE_1, x, "setRelease $type$ value");
}
// Opaque
{
vh.setOpaque(array, i, VALUE_2);
$type$ x = ($type$) vh.getOpaque(array, i);
assertEquals(x, VALUE_2, "setOpaque $type$ value");
assertEquals(VALUE_2, x, "setOpaque $type$ value");
}
#if[CAS]
@ -1324,56 +1324,56 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2);
assertEquals(r, true, "success compareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndSet $type$ value");
assertEquals(VALUE_2, x, "success compareAndSet $type$ value");
}
{
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3);
assertEquals(r, false, "failing compareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndSet $type$ value");
assertEquals(VALUE_2, x, "failing compareAndSet $type$ value");
}
{
$type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchange $type$ value");
assertEquals(VALUE_1, x, "success compareAndExchange $type$ value");
}
{
$type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchange $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchange $type$ value");
assertEquals(VALUE_1, x, "failing compareAndExchange $type$ value");
}
{
$type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2);
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire $type$ value");
assertEquals(VALUE_2, x, "success compareAndExchangeAcquire $type$ value");
}
{
$type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3);
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire $type$ value");
assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire $type$ value");
}
{
$type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1);
assertEquals(r, VALUE_2, "success compareAndExchangeRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "success compareAndExchangeRelease $type$ value");
assertEquals(VALUE_1, x, "success compareAndExchangeRelease $type$ value");
}
{
$type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3);
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease $type$ value");
assertEquals(VALUE_1, x, "failing compareAndExchangeRelease $type$ value");
}
{
@ -1384,14 +1384,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetPlain $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetPlain $type$ value");
assertEquals(VALUE_2, x, "success weakCompareAndSetPlain $type$ value");
}
{
boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetPlain $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain $type$ value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain $type$ value");
}
{
@ -1402,14 +1402,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire $type$");
assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire $type$");
}
{
boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire $type$ value");
assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire $type$ value");
}
{
@ -1420,14 +1420,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "success weakCompareAndSetRelease $type$");
assertEquals(VALUE_2, x, "success weakCompareAndSetRelease $type$");
}
{
boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSetRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease $type$ value");
assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease $type$ value");
}
{
@ -1438,14 +1438,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
}
assertEquals(success, true, "success weakCompareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "success weakCompareAndSet $type$");
assertEquals(VALUE_1, x, "success weakCompareAndSet $type$");
}
{
boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3);
assertEquals(success, false, "failing weakCompareAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1, "failing weakCompareAndSet $type$ value");
assertEquals(VALUE_1, x, "failing weakCompareAndSet $type$ value");
}
// Compare set and get
@ -1453,27 +1453,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndSet(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSet $type$");
assertEquals(VALUE_1, o, "getAndSet $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSet $type$ value");
assertEquals(VALUE_2, x, "getAndSet $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndSetAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetAcquire $type$");
assertEquals(VALUE_1, o, "getAndSetAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetAcquire $type$ value");
assertEquals(VALUE_2, x, "getAndSetAcquire $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndSetRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndSetRelease $type$");
assertEquals(VALUE_1, o, "getAndSetRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_2, "getAndSetRelease $type$ value");
assertEquals(VALUE_2, x, "getAndSetRelease $type$ value");
}
#end[CAS]
@ -1483,27 +1483,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndAdd(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAdd $type$");
assertEquals(VALUE_1, o, "getAndAdd $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd $type$ value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAdd $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndAddAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAddAcquire $type$");
assertEquals(VALUE_1, o, "getAndAddAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire $type$ value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAddAcquire $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndAddRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndAddRelease $type$");
assertEquals(VALUE_1, o, "getAndAddRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease $type$ value");
assertEquals(VALUE_1 + VALUE_2, x, "getAndAddRelease $type$ value");
}
#end[AtomicAdd]
@ -1513,27 +1513,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseOr(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOr $type$");
assertEquals(VALUE_1, o, "getAndBitwiseOr $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr $type$ value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOr $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire $type$");
assertEquals(VALUE_1, o, "getAndBitwiseOrAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire $type$ value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrAcquire $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseOrRelease $type$");
assertEquals(VALUE_1, o, "getAndBitwiseOrRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease $type$ value");
assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrRelease $type$ value");
}
// get and bitwise and
@ -1541,27 +1541,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseAnd(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAnd $type$");
assertEquals(VALUE_1, o, "getAndBitwiseAnd $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd $type$ value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAnd $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire $type$");
assertEquals(VALUE_1, o, "getAndBitwiseAndAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire $type$ value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndAcquire $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseAndRelease $type$");
assertEquals(VALUE_1, o, "getAndBitwiseAndRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease $type$ value");
assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndRelease $type$ value");
}
// get and bitwise xor
@ -1569,27 +1569,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseXor(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXor $type$");
assertEquals(VALUE_1, o, "getAndBitwiseXor $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor $type$ value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXor $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire $type$");
assertEquals(VALUE_1, o, "getAndBitwiseXorAcquire $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire $type$ value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorAcquire $type$ value");
}
{
vh.set(array, i, VALUE_1);
$type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, VALUE_2);
assertEquals(o, VALUE_1, "getAndBitwiseXorRelease $type$");
assertEquals(VALUE_1, o, "getAndBitwiseXorRelease $type$");
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease $type$ value");
assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorRelease $type$ value");
}
#end[Bitwise]
}
@ -1614,26 +1614,26 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
// Plain
{
$type$ x = ($type$) vh.get(array, i);
assertEquals(x, v, "get $type$ value");
assertEquals(v, x, "get $type$ value");
}
if (iAligned) {
// Volatile
{
$type$ x = ($type$) vh.getVolatile(array, i);
assertEquals(x, v, "getVolatile $type$ value");
assertEquals(v, x, "getVolatile $type$ value");
}
// Lazy
{
$type$ x = ($type$) vh.getAcquire(array, i);
assertEquals(x, v, "getRelease $type$ value");
assertEquals(v, x, "getRelease $type$ value");
}
// Opaque
{
$type$ x = ($type$) vh.getOpaque(array, i);
assertEquals(x, v, "getOpaque $type$ value");
assertEquals(v, x, "getOpaque $type$ value");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,26 +24,26 @@
/*
* @test
* @bug 8156486
* @run testng/othervm VarHandleTestMethodType$Type$
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodType$Type$
* @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$
* @run junit/othervm VarHandleTestMethodType$Type$
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodType$Type$
* @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$
*/
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
import static java.lang.invoke.MethodType.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
static final $type$ static_final_v = $value1$;
@ -63,7 +63,7 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
VarHandle vhArray;
@BeforeClass
@BeforeAll
public void setup() throws Exception {
vhFinalField = MethodHandles.lookup().findVarHandle(
VarHandleTestMethodType$Type$.class, "final_v", $type$.class);
@ -80,7 +80,6 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
}
@DataProvider
public Object[][] accessTestCaseProvider() throws Exception {
List<AccessTestCase<?>> cases = new ArrayList<>();
@ -115,7 +114,8 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
}
@Test(dataProvider = "accessTestCaseProvider")
@ParameterizedTest
@MethodSource("accessTestCaseProvider")
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
T t = atc.get();
int iters = atc.requiresLoop() ? ITERS : 1;
@ -124,7 +124,6 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest {
}
}
static void testInstanceFieldWrongMethodType(VarHandleTestMethodType$Type$ recv, VarHandle vh) throws Throwable {
// Get
// Incorrect argument types

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,14 +27,11 @@
* @compile TestFieldLookupAccessibility.java
* pkg/A.java pkg/B_extends_A.java pkg/C.java
* pkg/subpkg/B_extends_A.java pkg/subpkg/C.java
* @run testng/othervm --enable-final-field-mutation=ALL-UNNAMED -DwriteAccess=true TestFieldLookupAccessibility
* @run testng/othervm --illegal-final-field-mutation=deny -DwriteAccess=false TestFieldLookupAccessibility
* @run junit/othervm --enable-final-field-mutation=ALL-UNNAMED -DwriteAccess=true TestFieldLookupAccessibility
* @run junit/othervm --illegal-final-field-mutation=deny -DwriteAccess=false TestFieldLookupAccessibility
*/
import static org.testng.Assert.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import pkg.B_extends_A;
import java.lang.invoke.MethodHandles;
@ -48,11 +45,14 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class TestFieldLookupAccessibility {
static boolean writeAccess;
@BeforeClass
@BeforeAll
static void setup() {
String s = System.getProperty("writeAccess");
assertNotNull(s);
@ -188,8 +188,7 @@ public class TestFieldLookupAccessibility {
}
}
@DataProvider
public Object[][] lookupProvider() throws Exception {
public static Object[][] lookupProvider() throws Exception {
Stream<List<Object>> baseCases = Stream.of(
// Look up from same package
List.of(pkg.A.class, pkg.A.lookup(), pkg.A.inaccessibleFields()),
@ -215,7 +214,8 @@ public class TestFieldLookupAccessibility {
return pl.toArray();
}
@Test(dataProvider = "lookupProvider")
@ParameterizedTest
@MethodSource("lookupProvider")
public void test(FieldLookup fl, Class<?> src, MethodHandles.Lookup l, Set<String> inaccessibleFields) {
// Add to the expected failures all inaccessible fields due to accessibility modifiers
Set<String> expected = fl.inaccessibleFields(inaccessibleFields);
@ -240,10 +240,10 @@ public class TestFieldLookupAccessibility {
collect(Collectors.toSet());
if (!actualFieldNames.equals(expected)) {
if (actualFieldNames.isEmpty()) {
assertEquals(actualFieldNames, expected, "No accessibility failures:");
assertEquals(expected, actualFieldNames, "No accessibility failures:");
}
else {
assertEquals(actualFieldNames, expected, "Accessibility failures differ:");
assertEquals(expected, actualFieldNames, "Accessibility failures differ:");
}
}
else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,8 +21,9 @@
* questions.
*/
/* @test 8299183
* @run testng WrongMethodTypeTest
/* @test
* @bug 8299183
* @run junit WrongMethodTypeTest
*/
import java.lang.invoke.MethodHandle;
@ -33,9 +34,10 @@ import java.lang.invoke.WrongMethodTypeException;
import static java.lang.invoke.MethodType.methodType;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class WrongMethodTypeTest {
static final Lookup LOOKUP = MethodHandles.lookup();
@ -43,13 +45,11 @@ public class WrongMethodTypeTest {
@Test
public void checkExactType() throws Throwable {
String expectedMessage = "handle's method type (int)int but found ()boolean";
try {
MethodHandle mh = LOOKUP.findStatic(WrongMethodTypeTest.class, "m", methodType(int.class, int.class));
MethodHandle mh = LOOKUP.findStatic(WrongMethodTypeTest.class, "m", methodType(int.class, int.class));
var ex = assertThrows(WrongMethodTypeException.class, () -> {
boolean b = (boolean)mh.invokeExact();
fail("Expected WrongMethodTypeException");
} catch (WrongMethodTypeException ex) {
assertEquals(expectedMessage, ex.getMessage());
}
});
assertEquals(expectedMessage, ex.getMessage());
}
@Test
@ -57,11 +57,10 @@ public class WrongMethodTypeTest {
String expectedMessage = "handle's method type ()int but found ()Void";
VarHandle vh = LOOKUP.findStaticVarHandle(WrongMethodTypeTest.class, "x", int.class)
.withInvokeExactBehavior();
try {
var ex = assertThrows(WrongMethodTypeException.class, () -> {
Void o = (Void) vh.get();
} catch (WrongMethodTypeException ex) {
assertEquals(expectedMessage, ex.getMessage());
}
});
assertEquals(expectedMessage, ex.getMessage());
}
@Test
@ -69,11 +68,10 @@ public class WrongMethodTypeTest {
String expectedMessage = "handle's method type (WrongMethodTypeTest)boolean but found (WrongMethodTypeTest)int";
VarHandle vh = LOOKUP.findVarHandle(WrongMethodTypeTest.class, "y", boolean.class)
.withInvokeExactBehavior();
try {
var ex = assertThrows(WrongMethodTypeException.class, () -> {
int o = (int) vh.get(new WrongMethodTypeTest());
} catch (WrongMethodTypeException ex) {
assertEquals(expectedMessage, ex.getMessage());
}
});
assertEquals(expectedMessage, ex.getMessage());
}
static int m(int x) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @bug 8150782 8207027 8266269
* @compile TestAccessClass.java TestCls.java p/Foo.java q/Bar.java
* @run testng/othervm -ea -esa test.java.lang.invoke.TestAccessClass
* @run junit/othervm -ea -esa test.java.lang.invoke.TestAccessClass
*/
package test.java.lang.invoke;
@ -36,9 +36,11 @@ import q.Bar;
import static java.lang.invoke.MethodHandles.*;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
public class TestAccessClass {
@ -68,17 +70,19 @@ public class TestAccessClass {
assertEquals(Class1[].class, aClass);
}
@DataProvider
Object[][] illegalAccessAccess() {
static Object[][] illegalAccessAccess() {
return new Object[][] {
{publicLookup(), Class1.class},
{publicLookup(), TestCls.getPrivateSIC()}
};
}
@Test(dataProvider = "illegalAccessAccess", expectedExceptions = {IllegalAccessException.class})
@ParameterizedTest
@MethodSource("illegalAccessAccess")
public void illegalAccessExceptionTest(Lookup lookup, Class<?> klass) throws IllegalAccessException {
lookup.accessClass(klass);
assertThrows(IllegalAccessException.class, () -> {
lookup.accessClass(klass);
});
}
@Test
@ -98,8 +102,8 @@ public class TestAccessClass {
mh.invoke(null);
}
@Test(expectedExceptions = {NullPointerException.class})
@Test
public void illegalArgument() throws IllegalAccessException {
lookup().accessClass(null);
assertThrows(NullPointerException.class, () -> lookup().accessClass(null));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @bug 8150782 8207027 8266269
* @compile TestFindClass.java TestCls.java p/Foo.java q/Bar.java
* @run testng/othervm -ea -esa test.java.lang.invoke.TestFindClass
* @run junit/othervm -ea -esa test.java.lang.invoke.TestFindClass
*/
package test.java.lang.invoke;
@ -34,9 +34,11 @@ import q.Bar;
import static java.lang.invoke.MethodHandles.*;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testng.annotations.*;
import static org.junit.jupiter.api.Assertions.*;
public class TestFindClass {
@ -68,13 +70,12 @@ public class TestFindClass {
assertEquals(Class1[].class, aClass);
}
@Test(expectedExceptions = {ClassNotFoundException.class})
@Test
public void classNotFoundExceptionTest() throws IllegalAccessException, ClassNotFoundException {
lookup().findClass(PACKAGE_PREFIX + "TestFindClass$NonExistent");
assertThrows(ClassNotFoundException.class, () -> lookup().findClass(PACKAGE_PREFIX + "TestFindClass$NonExistent"));
}
@DataProvider
Object[][] illegalAccessFind() {
static Object[][] illegalAccessFind() {
return new Object[][] {
{publicLookup(), PACKAGE_PREFIX + "TestFindClass$Class1"},
{publicLookup(), PACKAGE_PREFIX + "TestCls$PrivateSIC"}
@ -84,9 +85,10 @@ public class TestFindClass {
/**
* Assertion: @throws IllegalAccessException if the class is not accessible, using the allowed access modes.
*/
@Test(dataProvider = "illegalAccessFind", expectedExceptions = {ClassNotFoundException.class})
@ParameterizedTest
@MethodSource("illegalAccessFind")
public void illegalAccessExceptionTest(Lookup lookup, String className) throws IllegalAccessException, ClassNotFoundException {
lookup.findClass(className);
assertThrows(ClassNotFoundException.class, () -> lookup.findClass(className));
}
@Test
@ -104,8 +106,8 @@ public class TestFindClass {
lookup().findClass("[Lp.Foo$T;");
}
@Test(expectedExceptions = {NullPointerException.class})
@Test
public void illegalArgument() throws IllegalAccessException, ClassNotFoundException {
lookup().findClass(null);
assertThrows(NullPointerException.class, () -> lookup().findClass(null));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,15 +23,15 @@
/* @test
* @compile TestLookup.java TestCls.java
* @run testng/othervm -ea -esa test.java.lang.invoke.TestLookup
* @run junit/othervm -ea -esa test.java.lang.invoke.TestLookup
*/
package test.java.lang.invoke;
import org.testng.annotations.Test;
import static java.lang.invoke.MethodHandles.*;
import static org.testng.AssertJUnit.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class TestLookup {
@ -43,10 +43,10 @@ public class TestLookup {
assertNull(lookup2.lookupClass().getClassLoader());
}
@Test(expectedExceptions = {ClassNotFoundException.class})
@Test
public void testPublicCannotLoadUserClass() throws IllegalAccessException, ClassNotFoundException {
Lookup lookup = publicLookup();
lookup.findClass("test.java.lang.invoke.TestCls");
assertThrows(ClassNotFoundException.class, () -> lookup.findClass("test.java.lang.invoke.TestCls"));
}
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* @test
* @bug 8196830 8235351 8257874
* @modules java.base/jdk.internal.reflect
* @run testng/othervm CallerSensitiveAccess
* @run junit/othervm CallerSensitiveAccess
* @summary Check Lookup findVirtual, findStatic and unreflect behavior with
* caller sensitive methods with focus on AccessibleObject.setAccessible
*/
@ -50,17 +50,16 @@ import java.util.stream.Stream;
import jdk.internal.reflect.CallerSensitive;
import org.testng.annotations.DataProvider;
import org.testng.annotations.NoInjection;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class CallerSensitiveAccess {
/**
* Caller sensitive methods in APIs exported by java.base.
*/
@DataProvider(name = "callerSensitiveMethods")
static Object[][] callerSensitiveMethods() {
try (Stream<Method> stream = callerSensitiveMethods(Object.class.getModule())) {
return stream.map(m -> new Object[]{m, shortDescription(m)})
@ -72,34 +71,35 @@ public class CallerSensitiveAccess {
* Using publicLookup, attempt to use findVirtual or findStatic to obtain a
* method handle to a caller sensitive method.
*/
@Test(dataProvider = "callerSensitiveMethods",
expectedExceptions = IllegalAccessException.class)
public void testPublicLookupFind(@NoInjection Method method, String desc) throws Exception {
@ParameterizedTest
@MethodSource("callerSensitiveMethods")
public void testPublicLookupFind(Method method, String desc) throws Exception {
Lookup lookup = MethodHandles.publicLookup();
Class<?> refc = method.getDeclaringClass();
String name = method.getName();
MethodType mt = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
if (Modifier.isStatic(method.getModifiers())) {
lookup.findStatic(refc, name, mt);
} else {
lookup.findVirtual(refc, name, mt);
}
assertThrows(IllegalAccessException.class, () -> {
if (Modifier.isStatic(method.getModifiers())) {
lookup.findStatic(refc, name, mt);
} else {
lookup.findVirtual(refc, name, mt);
}
});
}
/**
* Using publicLookup, attempt to use unreflect to obtain a method handle to a
* caller sensitive method.
*/
@Test(dataProvider = "callerSensitiveMethods",
expectedExceptions = IllegalAccessException.class)
public void testPublicLookupUnreflect(@NoInjection Method method, String desc) throws Exception {
MethodHandles.publicLookup().unreflect(method);
@ParameterizedTest
@MethodSource("callerSensitiveMethods")
public void testPublicLookupUnreflect(Method method, String desc) throws Exception {
assertThrows(IllegalAccessException.class, () -> MethodHandles.publicLookup().unreflect(method));
}
/**
* public accessible caller sensitive methods in APIs exported by java.base.
*/
@DataProvider(name = "accessibleCallerSensitiveMethods")
static Object[][] accessibleCallerSensitiveMethods() {
try (Stream<Method> stream = callerSensitiveMethods(Object.class.getModule())) {
return stream
@ -114,41 +114,43 @@ public class CallerSensitiveAccess {
* Using publicLookup, attempt to use unreflect to obtain a method handle to a
* caller sensitive method.
*/
@Test(dataProvider = "accessibleCallerSensitiveMethods",
expectedExceptions = IllegalAccessException.class)
public void testLookupUnreflect(@NoInjection Method method, String desc) throws Exception {
MethodHandles.publicLookup().unreflect(method);
@ParameterizedTest
@MethodSource("accessibleCallerSensitiveMethods")
public void testLookupUnreflect(Method method, String desc) throws Exception {
assertThrows(IllegalAccessException.class, () -> MethodHandles.publicLookup().unreflect(method));
}
/**
* Using a Lookup with no original access that can't lookup caller-sensitive
* method
*/
@Test(dataProvider = "callerSensitiveMethods",
expectedExceptions = IllegalAccessException.class)
public void testLookupNoOriginalAccessFind(@NoInjection Method method, String desc) throws Exception {
@ParameterizedTest
@MethodSource("callerSensitiveMethods")
public void testLookupNoOriginalAccessFind(Method method, String desc) throws Exception {
Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.ORIGINAL);
assertTrue(lookup.hasFullPrivilegeAccess());
Class<?> refc = method.getDeclaringClass();
String name = method.getName();
MethodType mt = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
if (Modifier.isStatic(method.getModifiers())) {
lookup.findStatic(refc, name, mt);
} else {
lookup.findVirtual(refc, name, mt);
}
assertThrows(IllegalAccessException.class, () -> {
if (Modifier.isStatic(method.getModifiers())) {
lookup.findStatic(refc, name, mt);
} else {
lookup.findVirtual(refc, name, mt);
}
});
}
/**
* Using a Lookup with no original access that can't unreflect caller-sensitive
* method
*/
@Test(dataProvider = "callerSensitiveMethods",
expectedExceptions = IllegalAccessException.class)
public void testLookupNoOriginalAccessUnreflect(@NoInjection Method method, String desc) throws Exception {
@ParameterizedTest
@MethodSource("callerSensitiveMethods")
public void testLookupNoOriginalAccessUnreflect(Method method, String desc) throws Exception {
Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.ORIGINAL);
assertTrue(lookup.hasFullPrivilegeAccess());
lookup.unreflect(method);
assertThrows(IllegalAccessException.class, () -> lookup.unreflect(method));
}
// -- Test method handles to setAccessible --
@ -156,21 +158,12 @@ public class CallerSensitiveAccess {
private int aField;
Field accessibleField() {
try {
return getClass().getDeclaredField("aField");
} catch (NoSuchFieldException e) {
fail();
return null;
}
var clazz = getClass();
return assertDoesNotThrow(() -> clazz.getDeclaredField("aField"));
}
Field inaccessibleField() {
try {
return String.class.getDeclaredField("hash");
} catch (NoSuchFieldException e) {
fail();
return null;
}
return assertDoesNotThrow(() -> String.class.getDeclaredField("hash"));
}
void findAndInvokeSetAccessible(Class<? extends AccessibleObject> refc, Field f) throws Throwable {
@ -215,23 +208,23 @@ public class CallerSensitiveAccess {
* Create a method handle to setAccessible and attempt to use it to suppress
* access to an inaccessible member.
*/
@Test(expectedExceptions = InaccessibleObjectException.class)
@Test
public void testSetAccessible5() throws Throwable {
findAndInvokeSetAccessible(AccessibleObject.class, inaccessibleField());
assertThrows(InaccessibleObjectException.class, () -> findAndInvokeSetAccessible(AccessibleObject.class, inaccessibleField()));
}
@Test(expectedExceptions = InaccessibleObjectException.class)
@Test
public void testSetAccessible6() throws Throwable {
findAndInvokeSetAccessible(Field.class, inaccessibleField());
assertThrows(InaccessibleObjectException.class, () -> findAndInvokeSetAccessible(Field.class, inaccessibleField()));
}
@Test(expectedExceptions = InaccessibleObjectException.class)
@Test
public void testSetAccessible7() throws Throwable {
Method m = AccessibleObject.class.getMethod("setAccessible", boolean.class);
unreflectAndInvokeSetAccessible(m, inaccessibleField());
assertThrows(InaccessibleObjectException.class, () -> unreflectAndInvokeSetAccessible(m, inaccessibleField()));
}
@Test(expectedExceptions = InaccessibleObjectException.class)
@Test
public void testSetAccessible8() throws Throwable {
Method m = Field.class.getMethod("setAccessible", boolean.class);
unreflectAndInvokeSetAccessible(m, inaccessibleField());
assertThrows(InaccessibleObjectException.class, () -> unreflectAndInvokeSetAccessible(m, inaccessibleField()));
}
@ -241,7 +234,6 @@ public class CallerSensitiveAccess {
* Custom AccessibleObject objects. One class overrides setAccessible, the other
* does not override this method.
*/
@DataProvider(name = "customAccessibleObjects")
static Object[][] customAccessibleObjectClasses() {
return new Object[][] { { new S1() }, { new S2() } };
}
@ -271,20 +263,20 @@ public class CallerSensitiveAccess {
* Using publicLookup, create a method handle to setAccessible and invoke it
* on a custom AccessibleObject object.
*/
@Test(expectedExceptions = IllegalAccessException.class)
@Test
public void testPublicLookupSubclass1() throws Throwable {
// S1 does not override setAccessible
findAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1());
assertThrows(IllegalAccessException.class, () -> findAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1()));
}
@Test
public void testPublicLookupSubclass2() throws Throwable {
// S2 overrides setAccessible
findAndInvokeSetAccessible(MethodHandles.publicLookup(), new S2());
}
@Test(expectedExceptions = IllegalAccessException.class)
@Test
public void testPublicLookupSubclass3() throws Throwable {
// S1 does not override setAccessible
unreflectAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1());
assertThrows(IllegalAccessException.class, () -> unreflectAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1()));
}
@Test
public void testPublicLookupSubclass4() throws Throwable {
@ -296,11 +288,13 @@ public class CallerSensitiveAccess {
* Using a full power lookup, create a method handle to setAccessible and
* invoke it on a custom AccessibleObject object.
*/
@Test(dataProvider = "customAccessibleObjects")
@ParameterizedTest
@MethodSource("customAccessibleObjectClasses")
public void testLookupSubclass1(AccessibleObject obj) throws Throwable {
findAndInvokeSetAccessible(MethodHandles.lookup(), obj);
}
@Test(dataProvider = "customAccessibleObjects")
@ParameterizedTest
@MethodSource("customAccessibleObjectClasses")
public void testLookupSubclass2(AccessibleObject obj) throws Throwable {
unreflectAndInvokeSetAccessible(MethodHandles.lookup(), obj);
}
@ -309,13 +303,13 @@ public class CallerSensitiveAccess {
* Using a full power lookup, create a method handle to setAccessible on a
* sub-class of AccessibleObject and then attempt to invoke it on a Field object.
*/
@Test(dataProvider = "customAccessibleObjects",
expectedExceptions = ClassCastException.class)
@ParameterizedTest
@MethodSource("customAccessibleObjectClasses")
public void testLookupSubclass3(AccessibleObject obj) throws Throwable {
MethodType mt = MethodType.methodType(void.class, boolean.class);
Lookup lookup = MethodHandles.lookup();
MethodHandle mh = lookup.findVirtual(obj.getClass(), "setAccessible", mt);
mh.invoke(accessibleField(), true); // should throw ClassCastException
assertThrows(ClassCastException.class, () -> mh.invoke(accessibleField(), true));
}
/**
@ -333,29 +327,29 @@ public class CallerSensitiveAccess {
mh.invoke(f, true);
assertTrue(f.isAccessible());
}
@Test(expectedExceptions = InaccessibleObjectException.class)
@Test
public void testLookupSubclass5() throws Throwable {
// S1 does not override setAccessible
Method m = S1.class.getMethod("setAccessible", boolean.class);
assertTrue(m.getDeclaringClass() == AccessibleObject.class);
MethodHandle mh = MethodHandles.lookup().unreflect(m);
mh.invoke(inaccessibleField(), true); // should throw InaccessibleObjectException
assertThrows(InaccessibleObjectException.class, () -> mh.invoke(inaccessibleField(), true));
}
@Test(expectedExceptions = ClassCastException.class)
@Test
public void testLookupSubclass6() throws Throwable {
// S2 overrides setAccessible
Method m = S2.class.getMethod("setAccessible", boolean.class);
assertTrue(m.getDeclaringClass() == S2.class);
MethodHandle mh = MethodHandles.lookup().unreflect(m);
mh.invoke(accessibleField(), true); // should throw ClassCastException
assertThrows(ClassCastException.class, () -> mh.invoke(accessibleField(), true));
}
@Test(expectedExceptions = ClassCastException.class)
@Test
public void testLookupSubclass7() throws Throwable {
// S2 overrides setAccessible
Method m = S2.class.getMethod("setAccessible", boolean.class);
assertTrue(m.getDeclaringClass() == S2.class);
MethodHandle mh = MethodHandles.lookup().unreflect(m);
mh.invoke(inaccessibleField(), true); // should throw ClassCastException
assertThrows(ClassCastException.class, () -> mh.invoke(inaccessibleField(), true));
}
/**
@ -373,7 +367,7 @@ public class CallerSensitiveAccess {
// Field::getInt
mh = MethodHandles.lookup().findVirtual(Field.class, "getInt", MethodType.methodType(int.class, Object.class));
int value = (int)mh.invokeExact(f, (Object)null);
assertTrue(value == 5);
assertEquals(5, value);
}
private static class Inner {
@ -400,7 +394,7 @@ public class CallerSensitiveAccess {
* exported by a named module.
*/
static Stream<Method> callerSensitiveMethods(Module module) {
assert module.isNamed();
assertTrue(module.isNamed());
ModuleReference mref = module.getLayer().configuration()
.findModule(module.getName())
.orElseThrow(() -> new RuntimeException())

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,12 +27,10 @@
* @summary Test bootstrap methods throwing an exception
* @library /java/lang/invoke/common
* @build test.java.lang.invoke.lib.InstructionHelper
* @run testng BootstrapMethodJumboArgsTest
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 BootstrapMethodJumboArgsTest
* @run junit BootstrapMethodJumboArgsTest
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 BootstrapMethodJumboArgsTest
*/
import org.testng.Assert;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.InstructionHelper;
import java.lang.invoke.ConstantCallSite;
@ -43,6 +41,10 @@ import java.util.stream.IntStream;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class BootstrapMethodJumboArgsTest {
static final MethodHandles.Lookup L = MethodHandles.lookup();
@ -93,7 +95,7 @@ public class BootstrapMethodJumboArgsTest {
Object.class, Object[].class), expected);
Object[] actual = (Object[]) mh.invoke();
Assert.assertEquals(actual, expected);
assertArrayEquals(expected, actual);
}
{
@ -103,7 +105,7 @@ public class BootstrapMethodJumboArgsTest {
Object.class, Object.class, Object[].class), expected);
Object[] actual = (Object[]) mh.invoke();
Assert.assertEquals(actual, expected);
assertArrayEquals(expected, actual);
}
{
@ -113,7 +115,7 @@ public class BootstrapMethodJumboArgsTest {
Object.class, Object.class, Object.class, Object[].class), expected);
Object[] actual = (Object[]) mh.invoke();
Assert.assertEquals(actual, expected);
assertArrayEquals(expected, actual);
}
}
@ -128,7 +130,7 @@ public class BootstrapMethodJumboArgsTest {
Object.class, Object[].class), expected);
Object[] actual = (Object[]) mh.invoke();
Assert.assertEquals(actual, expected);
assertArrayEquals(expected, actual);
}
{
@ -138,7 +140,7 @@ public class BootstrapMethodJumboArgsTest {
Object.class, Object.class, Object[].class), expected);
Object[] actual = (Object[]) mh.invoke();
Assert.assertEquals(actual, expected);
assertArrayEquals(expected, actual);
}
{
@ -148,7 +150,7 @@ public class BootstrapMethodJumboArgsTest {
Object.class, Object.class, Object.class, Object[].class), expected);
Object[] actual = (Object[]) mh.invoke();
Assert.assertEquals(actual, expected);
assertArrayEquals(expected, actual);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,12 +27,10 @@
* @summary Test bootstrap methods throwing an exception
* @library /java/lang/invoke/common
* @build test.java.lang.invoke.lib.InstructionHelper
* @run testng CondyBSMException
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMException
* @run junit CondyBSMException
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMException
*/
import org.testng.Assert;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.InstructionHelper;
import java.lang.invoke.MethodHandle;
@ -41,6 +39,10 @@ import java.lang.reflect.Constructor;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CondyBSMException {
@Test
@ -70,26 +72,17 @@ public class CondyBSMException {
static void test(String message, Class<? extends Throwable>... ts) {
MethodHandle mh = thrower(message, ts[ts.length - 1]);
Throwable caught = null;
try {
mh.invoke();
} catch (Throwable t) {
caught = t;
}
if (caught == null) {
Assert.fail("Throwable expected");
}
Throwable caught = assertThrows(Throwable.class, mh::invoke);
String actualMessage = null;
for (int i = 0; i < ts.length; i++) {
int level = i;
assertInstanceOf(ts[i], caught, () -> "Level %d".formatted(level));
actualMessage = caught.getMessage();
Assert.assertNotNull(caught);
Assert.assertTrue(ts[i].isAssignableFrom(caught.getClass()));
caught = caught.getCause();
}
Assert.assertEquals(actualMessage, message);
assertEquals(message, actualMessage);
}
static Throwable throwingBsm(MethodHandles.Lookup l, String name, Class<Throwable> type) throws Throwable {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,13 +27,10 @@
* @summary Test basic invocation of bootstrap methods
* @library /java/lang/invoke/common
* @build test.java.lang.invoke.lib.InstructionHelper
* @run testng CondyBSMInvocation
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMInvocation
* @run junit CondyBSMInvocation
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMInvocation
*/
import org.testng.Assert;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.InstructionHelper;
import java.lang.constant.ConstantDesc;
@ -48,6 +45,10 @@ import java.util.stream.Stream;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CondyBSMInvocation {
static final MethodHandles.Lookup L = MethodHandles.lookup();
@ -59,11 +60,7 @@ public class CondyBSMInvocation {
"bsm", methodType(Object.class)
);
try {
mh.invoke();
Assert.fail("NoSuchMethodError expected to be thrown");
} catch (NoSuchMethodError e) {
}
assertThrows(NoSuchMethodError.class, mh::invoke);
}
static MethodHandle[] bsms(String bsmName) {
@ -114,11 +111,7 @@ public class CondyBSMInvocation {
"shape_bsm", bsm.type()
);
try {
Object r = mh.invoke();
Assert.fail("BootstrapMethodError expected to be thrown for " + bsm);
} catch (BootstrapMethodError e) {
}
assertThrows(BootstrapMethodError.class, mh::invoke);
}
}
@ -139,11 +132,7 @@ public class CondyBSMInvocation {
"sig_bsm", bsm.type()
);
try {
Object r = mh.invoke();
Assert.fail("BootstrapMethodError expected to be thrown for " + bsm);
} catch (BootstrapMethodError e) {
}
assertThrows(BootstrapMethodError.class, mh::invoke);
}
}
@ -202,7 +191,7 @@ public class CondyBSMInvocation {
static void assertAll(Object... as) {
for (int i = 0; i < as.length; i++) {
Assert.assertEquals(as[i], i);
assertEquals(i, as[i]);
}
}
@ -219,7 +208,7 @@ public class CondyBSMInvocation {
);
Object r = mh.invoke();
Assert.assertEquals(r, Integer.toString(n));
assertEquals(Integer.toString(n), r);
}
{
@ -231,7 +220,7 @@ public class CondyBSMInvocation {
);
Object r = mh.invoke();
Assert.assertEquals(r, Integer.toString(9));
assertEquals(Integer.toString(9), r);
}
}
@ -248,13 +237,8 @@ public class CondyBSMInvocation {
IntStream.range(0, n - 1).boxed().toArray(ConstantDesc[]::new)
);
try {
Object r = mh.invoke();
Assert.fail("BootstrapMethodError expected to be thrown for arrity " + n);
} catch (BootstrapMethodError e) {
Throwable t = e.getCause();
Assert.assertTrue(WrongMethodTypeException.class.isAssignableFrom(t.getClass()));
}
var e = assertThrows(BootstrapMethodError.class, mh::invoke);
assertInstanceOf(WrongMethodTypeException.class, e.getCause());
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,28 +27,29 @@
* @summary Test invalid name in name and type
* @library /java/lang/invoke/common
* @build test.java.lang.invoke.lib.InstructionHelper
* @run testng CondyBSMValidationTest
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMValidationTest
* @run junit CondyBSMValidationTest
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMValidationTest
*/
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.InstructionHelper;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.stream.Stream;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CondyBSMValidationTest {
static final MethodHandles.Lookup L = MethodHandles.lookup();
static final String BSM_TYPE = methodType(Object.class, MethodHandles.Lookup.class, String.class, Object.class)
.toMethodDescriptorString();
@DataProvider
public Object[][] invalidSignaturesProvider() throws Exception {
public static Object[][] invalidSignaturesProvider() throws Exception {
return Stream.of(BSM_TYPE.replace("(", ""),
BSM_TYPE.replace(")", ""),
BSM_TYPE.replace("(", "").replace(")", ""),
@ -57,15 +58,13 @@ public class CondyBSMValidationTest {
.map(e -> new Object[]{e}).toArray(Object[][]::new);
}
@Test(dataProvider = "invalidSignaturesProvider")
@ParameterizedTest
@MethodSource("invalidSignaturesProvider")
public void testInvalidBSMSignature(String sig) throws Exception {
try {
MethodHandle mh = InstructionHelper.ldcDynamicConstant(
L, "name", "Ljava/lang/Object;",
"bsm", sig
);
} catch (IllegalArgumentException e) {
Assert.assertTrue(e.getMessage().contains("Bad method descriptor"));
}
var e = assertThrows(IllegalArgumentException.class, () -> InstructionHelper.ldcDynamicConstant(
L, "name", "Ljava/lang/Object;",
"bsm", sig
));
assertTrue(e.getMessage().contains("Bad method descriptor"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,20 +27,20 @@
* @summary Test for an interface using condy with default overpass methods
* @library /java/lang/invoke/common
* @build test.java.lang.invoke.lib.InstructionHelper
* @run testng CondyInterfaceWithOverpassMethods
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyInterfaceWithOverpassMethods
* @run junit CondyInterfaceWithOverpassMethods
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyInterfaceWithOverpassMethods
*/
import java.lang.classfile.ClassFile;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.InstructionHelper;
import java.lang.constant.*;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@Test
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class CondyInterfaceWithOverpassMethods {
interface A {
int a();
@ -52,14 +52,14 @@ public class CondyInterfaceWithOverpassMethods {
// Generated class with methods containing condy ldc
Class<?> gc;
static Class<?> gc;
public static Object bsm(MethodHandles.Lookup l, String name, Class<?> type) {
return name;
}
@BeforeClass
public void generateClass() throws Exception {
@BeforeAll
public static void generateClass() throws Exception {
// interface B extends A {
// // Overpass for method A.a
//

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,13 +27,10 @@
* @summary Test invalid name in name and type
* @library /java/lang/invoke/common
* @build test.java.lang.invoke.lib.InstructionHelper
* @run testng CondyNameValidationTest
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNameValidationTest
* @run junit CondyNameValidationTest
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNameValidationTest
*/
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import test.java.lang.invoke.lib.InstructionHelper;
import java.lang.invoke.MethodHandle;
@ -43,12 +40,17 @@ import java.util.stream.Stream;
import static java.lang.invoke.MethodType.methodType;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CondyNameValidationTest {
static final MethodHandles.Lookup L = MethodHandles.lookup();
static final MethodType BSM_TYPE = methodType(Object.class, MethodHandles.Lookup.class, String.class, Object.class);
@DataProvider
public Object[][] invalidNamesProvider() {
public static Object[][] invalidNamesProvider() {
return Stream.of(
new Object[]{"", "zero-length member name"},
new Object[]{".", "Invalid member name"},
@ -59,26 +61,24 @@ public class CondyNameValidationTest {
.toArray(Object[][]::new);
}
@Test(dataProvider = "invalidNamesProvider")
@ParameterizedTest
@MethodSource("invalidNamesProvider")
public void testInvalidNames(String name, String errMessContent) throws Exception {
try {
MethodHandle mh = InstructionHelper.ldcDynamicConstant(
L, name, Object.class,
"bsm", BSM_TYPE
);
} catch (IllegalArgumentException e) {
Assert.assertTrue(e.getMessage().contains(errMessContent));
}
var e = assertThrows(IllegalArgumentException.class, () -> InstructionHelper.ldcDynamicConstant(
L, name, Object.class,
"bsm", BSM_TYPE
));
assertTrue(e.getMessage().contains(errMessContent));
}
@DataProvider
public Object[][] validNamesProvider() throws Exception {
public static Object[][] validNamesProvider() throws Exception {
return Stream.of("<clinit>",
"<init>")
.map(e -> new Object[]{e}).toArray(Object[][]::new);
}
@Test(dataProvider = "validNamesProvider")
@ParameterizedTest
@MethodSource("validNamesProvider")
public void testValidNames(String name) throws Exception {
MethodHandle mh = InstructionHelper.ldcDynamicConstant(
L, name, Object.class,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,24 +26,25 @@
* @bug 8186046
* @summary Test nested dynamic constant declarations that are recursive
* @compile CondyNestedTest_Code.jcod
* @run testng CondyNestedTest
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNestedTest
* @run junit CondyNestedTest
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNestedTest
*/
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CondyNestedTest {
static final Class[] THROWABLES = {InvocationTargetException.class, StackOverflowError.class};
private static final MethodHandles.Lookup L = MethodHandles.lookup();
Class<?> c;
static Class<?> c;
// static final MethodHandles.Lookup L = MethodHandles.lookup();
//
@ -243,28 +244,17 @@ public class CondyNestedTest {
// }
static void test(Method m, Class<? extends Throwable>... ts) {
Throwable caught = null;
try {
m.invoke(null);
} catch (Throwable t) {
caught = t;
}
Throwable caught = assertThrows(Throwable.class, () -> m.invoke(null));
if (caught == null) {
Assert.fail("Throwable expected");
}
String actualMessage = null;
for (int i = 0; i < ts.length; i++) {
actualMessage = caught.getMessage();
Assert.assertNotNull(caught);
Assert.assertTrue(ts[i].isAssignableFrom(caught.getClass()));
int level = i;
assertInstanceOf(ts[i], caught, () -> "Level %d".formatted(level));
caught = caught.getCause();
}
}
@BeforeClass
public void findClass() throws Exception {
@BeforeAll
public static void findClass() throws Exception {
c = Class.forName("CondyNestedTest_Code");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,28 +26,28 @@
* @bug 8186211
* @summary Test basic invocation of multiple ldc's of the same dynamic constant that fail resolution
* @library /java/lang/invoke/common
* @run testng CondyRepeatFailedResolution
* @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyRepeatFailedResolution
* @run junit CondyRepeatFailedResolution
* @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyRepeatFailedResolution
*/
import java.lang.classfile.ClassFile;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.lang.constant.*;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@Test
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CondyRepeatFailedResolution {
// Counter used to determine if a given BSM is invoked more than once
static int bsm_called = 0;
// Generated class with methods containing condy ldc
Class<?> gc;
static Class<?> gc;
// Bootstrap method used to represent primitive values
// that cannot be represented directly in the constant pool,
@ -90,8 +90,8 @@ public class CondyRepeatFailedResolution {
}
}
@BeforeClass
public void generateClass() throws Exception {
@BeforeAll
public static void generateClass() throws Exception {
String genClassName = CondyRepeatFailedResolution.class.getSimpleName() + "$Code";
String bsmClassDesc = CondyRepeatFailedResolution.class.descriptorString();
String bsmMethodName = "intConversion";
@ -319,29 +319,21 @@ public class CondyRepeatFailedResolution {
Method m = gc.getDeclaredMethod(name);
bsm_called = 0;
try {
InvocationTargetException e1 = assertThrows(InvocationTargetException.class, () -> {
Object r1 = m.invoke(null);
Assert.fail("InvocationTargetException expected to be thrown after first invocation");
} catch (InvocationTargetException e1) {
// bsm_called should have been incremented prior to the exception
Assert.assertEquals(bsm_called, 1);
Assert.assertTrue(e1.getCause() instanceof BootstrapMethodError);
// Try invoking method again to ensure that the bootstrap
// method is not invoked twice and a resolution failure
// results.
try {
Object r2 = m.invoke(null);
Assert.fail("InvocationTargetException expected to be thrown after second invocation");
} catch (InvocationTargetException e2) {
// bsm_called should remain at 1 since the bootstrap
// method should not have been invoked.
Assert.assertEquals(bsm_called, 1);
Assert.assertTrue(e2.getCause() instanceof BootstrapMethodError);
} catch (Throwable t2) {
Assert.fail("InvocationTargetException expected to be thrown");
}
} catch (Throwable t1) {
Assert.fail("InvocationTargetException expected to be thrown");
}
});
// bsm_called should have been incremented prior to the exception
assertEquals(1, bsm_called);
assertInstanceOf(BootstrapMethodError.class, e1.getCause());
// Try invoking method again to ensure that the bootstrap
// method is not invoked twice and a resolution failure
// results.
InvocationTargetException e2 = assertThrows(InvocationTargetException.class, () -> {
Object r2 = m.invoke(null);
});
// bsm_called should remain at 1 since the bootstrap
// method should not have been invoked.
assertEquals(1, bsm_called);
assertInstanceOf(BootstrapMethodError.class, e2.getCause());
}
}

Some files were not shown because too many files have changed in this diff Show More