< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java

Print this page
@@ -19,10 +19,12 @@
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
+ // -- This file was mechanically generated: Do not edit! -- //
+ 
  /*
   * @test
   * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccessDouble
   * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessDouble
   * @run testng/othervm -Diters=20000                         VarHandleTestAccessDouble

@@ -40,10 +42,12 @@
  import java.util.List;
  
  import static org.testng.Assert.*;
  
  public class VarHandleTestAccessDouble extends VarHandleBaseTest {
+     static final Class<?> type = double.class;
+ 
      static final double static_final_v = 1.0d;
  
      static double static_v;
  
      final double final_v = 1.0d;

@@ -66,31 +70,32 @@
  
      VarHandle vhStaticFinalField;
  
      VarHandle vhArray;
  
+     VarHandle vhValueTypeField;
  
      VarHandle[] allocate(boolean same) {
          List<VarHandle> vhs = new ArrayList<>();
  
          String postfix = same ? "" : "2";
          VarHandle vh;
          try {
              vh = MethodHandles.lookup().findVarHandle(
-                     VarHandleTestAccessDouble.class, "final_v" + postfix, double.class);
+                     VarHandleTestAccessDouble.class, "final_v" + postfix, type);
              vhs.add(vh);
  
              vh = MethodHandles.lookup().findVarHandle(
-                     VarHandleTestAccessDouble.class, "v" + postfix, double.class);
+                     VarHandleTestAccessDouble.class, "v" + postfix, type);
              vhs.add(vh);
  
              vh = MethodHandles.lookup().findStaticVarHandle(
-                 VarHandleTestAccessDouble.class, "static_final_v" + postfix, double.class);
+                 VarHandleTestAccessDouble.class, "static_final_v" + postfix, type);
              vhs.add(vh);
  
              vh = MethodHandles.lookup().findStaticVarHandle(
-                 VarHandleTestAccessDouble.class, "static_v" + postfix, double.class);
+                 VarHandleTestAccessDouble.class, "static_v" + postfix, type);
              vhs.add(vh);
  
              if (same) {
                  vh = MethodHandles.arrayElementVarHandle(double[].class);
              }

@@ -105,22 +110,25 @@
      }
  
      @BeforeClass
      public void setup() throws Exception {
          vhFinalField = MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessDouble.class, "final_v", double.class);
+                 VarHandleTestAccessDouble.class, "final_v", type);
  
          vhField = MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessDouble.class, "v", double.class);
+                 VarHandleTestAccessDouble.class, "v", type);
  
          vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
-             VarHandleTestAccessDouble.class, "static_final_v", double.class);
+             VarHandleTestAccessDouble.class, "static_final_v", type);
  
          vhStaticField = MethodHandles.lookup().findStaticVarHandle(
-             VarHandleTestAccessDouble.class, "static_v", double.class);
+             VarHandleTestAccessDouble.class, "static_v", type);
  
          vhArray = MethodHandles.arrayElementVarHandle(double[].class);
+ 
+         vhValueTypeField = MethodHandles.lookup().findVarHandle(
+                     Value.class, "double_v", type);
      }
  
  
      @DataProvider
      public Object[][] varHandlesProvider() throws Exception {

@@ -201,11 +209,11 @@
          return types.stream().toArray(Object[][]::new);
      }
  
      @Test(dataProvider = "typesProvider")
      public void testTypes(VarHandle vh, List<Class<?>> pts) {
-         assertEquals(vh.varType(), double.class);
+         assertEquals(vh.varType(), type);
  
          assertEquals(vh.coordinateTypes(), pts);
  
          testTypes(vh);
      }

@@ -213,29 +221,29 @@
  
      @Test
      public void testLookupInstanceToStatic() {
          checkIAE("Lookup of static final field to instance final field", () -> {
              MethodHandles.lookup().findStaticVarHandle(
-                     VarHandleTestAccessDouble.class, "final_v", double.class);
+                     VarHandleTestAccessDouble.class, "final_v", type);
          });
  
          checkIAE("Lookup of static field to instance field", () -> {
              MethodHandles.lookup().findStaticVarHandle(
-                     VarHandleTestAccessDouble.class, "v", double.class);
+                     VarHandleTestAccessDouble.class, "v", type);
          });
      }
  
      @Test
      public void testLookupStaticToInstance() {
          checkIAE("Lookup of instance final field to static final field", () -> {
              MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessDouble.class, "static_final_v", double.class);
+                 VarHandleTestAccessDouble.class, "static_final_v", type);
          });
  
          checkIAE("Lookup of instance field to static field", () -> {
              vhStaticField = MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessDouble.class, "static_v", double.class);
+                 VarHandleTestAccessDouble.class, "static_v", type);
          });
      }
  
  
      @DataProvider

@@ -272,10 +280,15 @@
                                                vhArray, VarHandleTestAccessDouble::testArrayUnsupported,
                                                false));
          cases.add(new VarHandleAccessTestCase("Array index out of bounds",
                                                vhArray, VarHandleTestAccessDouble::testArrayIndexOutOfBounds,
                                                false));
+         cases.add(new VarHandleAccessTestCase("Value type field",
+                                               vhValueTypeField, vh -> testValueTypeField(Value.getInstance(), vh)));
+         cases.add(new VarHandleAccessTestCase("Value type field unsupported",
+                                               vhValueTypeField, vh -> testValueTypeFieldUnsupported(Value.getInstance(), vh),
+                                               false));
          // Work around issue with jtreg summary reporting which truncates
          // the String result of Object.toString to 30 characters, hence
          // the first dummy argument
          return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
      }

@@ -373,10 +386,23 @@
          checkUOE(() -> {
              double o = (double) vh.getAndBitwiseXorRelease(recv, 1.0d);
          });
      }
  
+     static void testValueTypeField(Value recv, VarHandle vh) {
+         // Plain
+         {
+             double x = (double) vh.get(recv);
+             assertEquals(x, 1.0d, "get double value");
+         }
+     }
+ 
+     static void testValueTypeFieldUnsupported(Value recv, VarHandle vh) {
+         checkUOE(() -> {
+             vh.set(recv, 2.0d);
+         });
+     }
  
      static void testStaticFinalField(VarHandle vh) {
          // Plain
          {
              double x = (double) vh.get();
< prev index next >