< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.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                   VarHandleTestAccessChar
   * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar
   * @run testng/othervm -Diters=20000                         VarHandleTestAccessChar

@@ -40,10 +42,12 @@
  import java.util.List;
  
  import static org.testng.Assert.*;
  
  public class VarHandleTestAccessChar extends VarHandleBaseTest {
+     static final Class<?> type = char.class;
+ 
      static final char static_final_v = '\u0123';
  
      static char static_v;
  
      final char final_v = '\u0123';

@@ -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(
-                     VarHandleTestAccessChar.class, "final_v" + postfix, char.class);
+                     VarHandleTestAccessChar.class, "final_v" + postfix, type);
              vhs.add(vh);
  
              vh = MethodHandles.lookup().findVarHandle(
-                     VarHandleTestAccessChar.class, "v" + postfix, char.class);
+                     VarHandleTestAccessChar.class, "v" + postfix, type);
              vhs.add(vh);
  
              vh = MethodHandles.lookup().findStaticVarHandle(
-                 VarHandleTestAccessChar.class, "static_final_v" + postfix, char.class);
+                 VarHandleTestAccessChar.class, "static_final_v" + postfix, type);
              vhs.add(vh);
  
              vh = MethodHandles.lookup().findStaticVarHandle(
-                 VarHandleTestAccessChar.class, "static_v" + postfix, char.class);
+                 VarHandleTestAccessChar.class, "static_v" + postfix, type);
              vhs.add(vh);
  
              if (same) {
                  vh = MethodHandles.arrayElementVarHandle(char[].class);
              }

@@ -105,22 +110,25 @@
      }
  
      @BeforeClass
      public void setup() throws Exception {
          vhFinalField = MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessChar.class, "final_v", char.class);
+                 VarHandleTestAccessChar.class, "final_v", type);
  
          vhField = MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessChar.class, "v", char.class);
+                 VarHandleTestAccessChar.class, "v", type);
  
          vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
-             VarHandleTestAccessChar.class, "static_final_v", char.class);
+             VarHandleTestAccessChar.class, "static_final_v", type);
  
          vhStaticField = MethodHandles.lookup().findStaticVarHandle(
-             VarHandleTestAccessChar.class, "static_v", char.class);
+             VarHandleTestAccessChar.class, "static_v", type);
  
          vhArray = MethodHandles.arrayElementVarHandle(char[].class);
+ 
+         vhValueTypeField = MethodHandles.lookup().findVarHandle(
+                     Value.class, "char_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(), char.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(
-                     VarHandleTestAccessChar.class, "final_v", char.class);
+                     VarHandleTestAccessChar.class, "final_v", type);
          });
  
          checkIAE("Lookup of static field to instance field", () -> {
              MethodHandles.lookup().findStaticVarHandle(
-                     VarHandleTestAccessChar.class, "v", char.class);
+                     VarHandleTestAccessChar.class, "v", type);
          });
      }
  
      @Test
      public void testLookupStaticToInstance() {
          checkIAE("Lookup of instance final field to static final field", () -> {
              MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessChar.class, "static_final_v", char.class);
+                 VarHandleTestAccessChar.class, "static_final_v", type);
          });
  
          checkIAE("Lookup of instance field to static field", () -> {
              vhStaticField = MethodHandles.lookup().findVarHandle(
-                 VarHandleTestAccessChar.class, "static_v", char.class);
+                 VarHandleTestAccessChar.class, "static_v", type);
          });
      }
  
  
      @DataProvider

@@ -272,10 +280,15 @@
                                                vhArray, VarHandleTestAccessChar::testArrayUnsupported,
                                                false));
          cases.add(new VarHandleAccessTestCase("Array index out of bounds",
                                                vhArray, VarHandleTestAccessChar::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);
      }

@@ -338,10 +351,23 @@
  
  
  
      }
  
+     static void testValueTypeField(Value recv, VarHandle vh) {
+         // Plain
+         {
+             char x = (char) vh.get(recv);
+             assertEquals(x, '\u0123', "get char value");
+         }
+     }
+ 
+     static void testValueTypeFieldUnsupported(Value recv, VarHandle vh) {
+         checkUOE(() -> {
+             vh.set(recv, '\u4567');
+         });
+     }
  
      static void testStaticFinalField(VarHandle vh) {
          // Plain
          {
              char x = (char) vh.get();
< prev index next >