< prev index next >

test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java

Print this page


   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 618     public void testFindGetter0() throws Throwable {
 619         if (CAN_SKIP_WORKING)  return;
 620         startTest("findGetter");
 621         testGetter(TEST_FIND_FIELD);
 622         testGetter(TEST_FIND_FIELD | TEST_BOUND);
 623     }
 624 
 625     @Test
 626     public void testFindStaticGetter() throws Throwable {
 627         CodeCacheOverflowProcessor.runMHTest(this::testFindStaticGetter0);
 628     }
 629 
 630     public void testFindStaticGetter0() throws Throwable {
 631         if (CAN_SKIP_WORKING)  return;
 632         startTest("findStaticGetter");
 633         testGetter(TEST_FIND_STATIC);
 634     }
 635 
 636     public void testGetter(int testMode) throws Throwable {
 637         Lookup lookup = PRIVATE;  // FIXME: test more lookups than this one
 638         for (Object[] c : HasFields.testCasesFor(testMode)) {
 639             boolean positive = (c[1] != Error.class);
 640             testGetter(positive, lookup, c[0], c[1], testMode);
 641             if (positive)
 642                 testGetter(positive, lookup, c[0], c[1], testMode | TEST_NPE);
 643         }
 644         testGetter(true, lookup,
 645                    new Object[]{ true,  System.class, "out", java.io.PrintStream.class },
 646                    System.out, testMode);
 647         for (int isStaticN = 0; isStaticN <= 1; isStaticN++) {
 648             testGetter(false, lookup,
 649                        new Object[]{ (isStaticN != 0), System.class, "bogus", char.class },
 650                        null, testMode);
 651         }
 652     }
 653 
 654     public void testGetter(boolean positive, MethodHandles.Lookup lookup,
 655                            Object fieldRef, Object value, int testMode) throws Throwable {
 656         testAccessor(positive, lookup, fieldRef, value, testMode);
 657     }
 658 
 659     public void testAccessor(boolean positive0, MethodHandles.Lookup lookup,
 660                              Object fieldRef, Object value, int testMode0) throws Throwable {
 661         if (verbosity >= 4)
 662             System.out.println("testAccessor"+Arrays.deepToString(new Object[]{positive0, lookup, fieldRef, value, testMode0}));
 663         boolean isGetter = ((testMode0 & TEST_SETTER) == 0);
 664         boolean doBound  = ((testMode0 & TEST_BOUND) != 0);
 665         boolean testNPE  = ((testMode0 & TEST_NPE) != 0);
 666         int testMode = testMode0 & ~(TEST_SETTER | TEST_BOUND | TEST_NPE);
 667         boolean positive = positive0 && !testNPE;

 668         boolean isStatic;
 669         Class<?> fclass;
 670         String   fname;
 671         Class<?> ftype;
 672         Field f = (fieldRef instanceof Field ? (Field)fieldRef : null);
 673         if (f != null) {
 674             isStatic = Modifier.isStatic(f.getModifiers());

 675             fclass   = f.getDeclaringClass();
 676             fname    = f.getName();
 677             ftype    = f.getType();
 678         } else {
 679             Object[] scnt = (Object[]) fieldRef;
 680             isStatic = (Boolean)  scnt[0];

 681             fclass   = (Class<?>) scnt[1];
 682             fname    = (String)   scnt[2];
 683             ftype    = (Class<?>) scnt[3];
 684             try {
 685                 f = fclass.getDeclaredField(fname);
 686             } catch (ReflectiveOperationException ex) {
 687                 f = null;
 688             }
 689         }
 690         if (!testModeMatches(testMode, isStatic))  return;
 691         if (f == null && testMode == TEST_UNREFLECT)  return;
 692         if (testNPE && isStatic)  return;
 693         countTest(positive);
 694         MethodType expType;
 695         if (isGetter)
 696             expType = MethodType.methodType(ftype, HasFields.class);
 697         else
 698             expType = MethodType.methodType(void.class, HasFields.class, ftype);
 699         if (isStatic)  expType = expType.dropParameterTypes(0, 1);
 700         Exception noAccess = null;


 704             case TEST_UNREFLECT:   mh = lookup.unreflectGetter(f);                      break;
 705             case TEST_FIND_FIELD:  mh = lookup.findGetter(fclass, fname, ftype);        break;
 706             case TEST_FIND_STATIC: mh = lookup.findStaticGetter(fclass, fname, ftype);  break;
 707             case TEST_SETTER|
 708                  TEST_UNREFLECT:   mh = lookup.unreflectSetter(f);                      break;
 709             case TEST_SETTER|
 710                  TEST_FIND_FIELD:  mh = lookup.findSetter(fclass, fname, ftype);        break;
 711             case TEST_SETTER|
 712                  TEST_FIND_STATIC: mh = lookup.findStaticSetter(fclass, fname, ftype);  break;
 713             default:
 714                 throw new InternalError("testMode="+testMode);
 715             }
 716         } catch (ReflectiveOperationException ex) {
 717             mh = null;
 718             noAccess = ex;
 719             assertExceptionClass(
 720                 (fname.contains("bogus"))
 721                 ?   NoSuchFieldException.class
 722                 :   IllegalAccessException.class,
 723                 noAccess);

 724             if (verbosity >= 5)  ex.printStackTrace(System.out);
 725         }
 726         if (verbosity >= 3)
 727             System.out.format("%s%s %s.%s/%s => %s %s%n",
 728                               (testMode0 & TEST_UNREFLECT) != 0
 729                                   ? "unreflect"
 730                                   : "find" + ((testMode0 & TEST_FIND_STATIC) != 0 ? "Static" : ""),
 731                               (isGetter ? "Getter" : "Setter"),
 732                               fclass.getName(), fname, ftype, mh,
 733                               (noAccess == null ? "" : " !! "+noAccess));
 734         // negative test case and expected noAccess, then done.
 735         if (!positive && noAccess != null) return;
 736         // positive test case but found noAccess, then error
 737         if (positive && !testNPE && noAccess != null)  throw new RuntimeException(noAccess);
 738         assertEquals(positive0 ? "positive test" : "negative test erroneously passed", positive0, mh != null);

 739         if (!positive && !testNPE)  return; // negative access test failed as expected
 740         assertEquals((isStatic ? 0 : 1)+(isGetter ? 0 : 1), mh.type().parameterCount());
 741         assertSame(mh.type(), expType);
 742         //assertNameStringContains(mh, fname);  // This does not hold anymore with LFs
 743         HasFields fields = new HasFields();
 744         HasFields fieldsForMH = fields;
 745         if (testNPE)  fieldsForMH = null;  // perturb MH argument to elicit expected error
 746         if (doBound)
 747             mh = mh.bindTo(fieldsForMH);
 748         Object sawValue;
 749         Class<?> vtype = ftype;
 750         if (ftype != int.class)  vtype = Object.class;
 751         if (isGetter) {
 752             mh = mh.asType(mh.type().generic()
 753                            .changeReturnType(vtype));
 754         } else {
 755             int last = mh.type().parameterCount() - 1;
 756             mh = mh.asType(mh.type().generic()
 757                            .changeReturnType(void.class)
 758                            .changeParameterType(last, vtype));
 759         }
 760         if (f != null && f.getDeclaringClass() == HasFields.class) {
 761             assertEquals(f.get(fields), value);  // clean to start with
 762         }
 763         Throwable caughtEx = null;
 764         // non-final field and setAccessible(true) on instance field will have write access
 765         boolean writeAccess = !Modifier.isFinal(f.getModifiers()) ||
 766                               (!Modifier.isStatic(f.getModifiers()) && f.isAccessible());
 767         if (isGetter) {
 768             Object expValue = value;
 769             for (int i = 0; i <= 1; i++) {
 770                 sawValue = null;  // make DA rules happy under try/catch
 771                 try {
 772                     if (isStatic || doBound) {
 773                         if (ftype == int.class)
 774                             sawValue = (int) mh.invokeExact();  // do these exactly
 775                         else
 776                             sawValue = mh.invokeExact();
 777                     } else {
 778                         if (ftype == int.class)
 779                             sawValue = (int) mh.invokeExact((Object) fieldsForMH);
 780                         else
 781                             sawValue = mh.invokeExact((Object) fieldsForMH);
 782                     }
 783                 } catch (RuntimeException ex) {
 784                     if (ex instanceof NullPointerException && testNPE) {
 785                         caughtEx = ex;
 786                         break;
 787                     }
 788                 }
 789                 assertEquals(sawValue, expValue);
 790                 if (f != null && f.getDeclaringClass() == HasFields.class && writeAccess) {
 791                     Object random = randomArg(ftype);
 792                     f.set(fields, random);
 793                     expValue = random;
 794                 } else {
 795                     break;
 796                 }
 797             }
 798         } else {
 799             for (int i = 0; i <= 1; i++) {
 800                 Object putValue = randomArg(ftype);
 801                 try {
 802                     if (isStatic || doBound) {
 803                         if (ftype == int.class)
 804                             mh.invokeExact((int)putValue);  // do these exactly
 805                         else
 806                             mh.invokeExact(putValue);
 807                     } else {
 808                         if (ftype == int.class)
 809                             mh.invokeExact((Object) fieldsForMH, (int)putValue);
 810                         else
 811                             mh.invokeExact((Object) fieldsForMH, putValue);
 812                     }
 813                 } catch (RuntimeException ex) {
 814                     if (ex instanceof NullPointerException && testNPE) {
 815                         caughtEx = ex;
 816                         break;
 817                     }
 818                 }
 819                 if (f != null && f.getDeclaringClass() == HasFields.class) {
 820                     assertEquals(f.get(fields), putValue);
 821                 }
 822             }
 823         }
 824         if (f != null && f.getDeclaringClass() == HasFields.class && writeAccess) {
 825             f.set(fields, value);  // put it back if it has write access
 826         }
 827         if (testNPE) {
 828             if (caughtEx == null || !(caughtEx instanceof NullPointerException))
 829                 throw new RuntimeException("failed to catch NPE exception"+(caughtEx == null ? " (caughtEx=null)" : ""), caughtEx);
 830             caughtEx = null;  // nullify expected exception
 831         }
 832         if (caughtEx != null) {
 833             throw new RuntimeException("unexpected exception", caughtEx);
 834         }
 835     }
 836 
 837     @Test
 838     public void testUnreflectSetter() throws Throwable {
 839         CodeCacheOverflowProcessor.runMHTest(this::testUnreflectSetter0);
 840     }
 841 
 842     public void testUnreflectSetter0() throws Throwable {
 843         if (CAN_SKIP_WORKING)  return;
 844         startTest("unreflectSetter");
 845         testSetter(TEST_UNREFLECT);


 853     public void testFindSetter0() throws Throwable {
 854         if (CAN_SKIP_WORKING)  return;
 855         startTest("findSetter");
 856         testSetter(TEST_FIND_FIELD);
 857         testSetter(TEST_FIND_FIELD | TEST_BOUND);
 858     }
 859 
 860     @Test
 861     public void testFindStaticSetter() throws Throwable {
 862         CodeCacheOverflowProcessor.runMHTest(this::testFindStaticSetter0);
 863     }
 864 
 865     public void testFindStaticSetter0() throws Throwable {
 866         if (CAN_SKIP_WORKING)  return;
 867         startTest("findStaticSetter");
 868         testSetter(TEST_FIND_STATIC);
 869     }
 870 
 871     public void testSetter(int testMode) throws Throwable {
 872         Lookup lookup = PRIVATE;  // FIXME: test more lookups than this one
 873         startTest("testSetter");
 874         for (Object[] c : HasFields.testCasesFor(testMode|TEST_SETTER)) {
 875             boolean positive = (c[1] != Error.class);
 876             testSetter(positive, lookup, c[0], c[1], testMode);
 877             if (positive)
 878                 testSetter(positive, lookup, c[0], c[1], testMode | TEST_NPE);
 879         }
 880         for (int isStaticN = 0; isStaticN <= 1; isStaticN++) {
 881             testSetter(false, lookup,
 882                        new Object[]{ (isStaticN != 0), System.class, "bogus", char.class },
 883                        null, testMode);
 884         }
 885     }
 886 
 887     public void testSetter(boolean positive, MethodHandles.Lookup lookup,
 888                            Object fieldRef, Object value, int testMode) throws Throwable {
 889         testAccessor(positive, lookup, fieldRef, value, testMode | TEST_SETTER);
 890     }
 891 
 892     @Test
 893     public void testArrayElementGetter() throws Throwable {
 894         CodeCacheOverflowProcessor.runMHTest(this::testArrayElementGetter0);


   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 618     public void testFindGetter0() throws Throwable {
 619         if (CAN_SKIP_WORKING)  return;
 620         startTest("findGetter");
 621         testGetter(TEST_FIND_FIELD);
 622         testGetter(TEST_FIND_FIELD | TEST_BOUND);
 623     }
 624 
 625     @Test
 626     public void testFindStaticGetter() throws Throwable {
 627         CodeCacheOverflowProcessor.runMHTest(this::testFindStaticGetter0);
 628     }
 629 
 630     public void testFindStaticGetter0() throws Throwable {
 631         if (CAN_SKIP_WORKING)  return;
 632         startTest("findStaticGetter");
 633         testGetter(TEST_FIND_STATIC);
 634     }
 635 
 636     public void testGetter(int testMode) throws Throwable {
 637         Lookup lookup = PRIVATE;  // FIXME: test more lookups than this one
 638         for (Object[] c : HasFields.CASES) {
 639             boolean positive = (c[1] != Error.class);
 640             testGetter(positive, lookup, c[0], c[1], testMode);
 641             if (positive)
 642                 testGetter(positive, lookup, c[0], c[1], testMode | TEST_NPE);
 643         }
 644         testGetter(true, lookup,
 645                    new Object[]{ true,  System.class, "out", java.io.PrintStream.class },
 646                    System.out, testMode);
 647         for (int isStaticN = 0; isStaticN <= 1; isStaticN++) {
 648             testGetter(false, lookup,
 649                        new Object[]{ (isStaticN != 0), System.class, "bogus", char.class },
 650                        null, testMode);
 651         }
 652     }
 653 
 654     public void testGetter(boolean positive, MethodHandles.Lookup lookup,
 655                            Object fieldRef, Object value, int testMode) throws Throwable {
 656         testAccessor(positive, lookup, fieldRef, value, testMode);
 657     }
 658 
 659     public void testAccessor(boolean positive0, MethodHandles.Lookup lookup,
 660                              Object fieldRef, Object value, int testMode0) throws Throwable {
 661         if (verbosity >= 4)
 662             System.out.println("testAccessor"+Arrays.deepToString(new Object[]{positive0, lookup, fieldRef, value, testMode0}));
 663         boolean isGetter = ((testMode0 & TEST_SETTER) == 0);
 664         boolean doBound  = ((testMode0 & TEST_BOUND) != 0);
 665         boolean testNPE  = ((testMode0 & TEST_NPE) != 0);
 666         int testMode = testMode0 & ~(TEST_SETTER | TEST_BOUND | TEST_NPE);
 667         boolean positive = positive0 && !testNPE;
 668         boolean isFinal;
 669         boolean isStatic;
 670         Class<?> fclass;
 671         String   fname;
 672         Class<?> ftype;
 673         Field f = (fieldRef instanceof Field ? (Field)fieldRef : null);
 674         if (f != null) {
 675             isStatic = Modifier.isStatic(f.getModifiers());
 676             isFinal  = Modifier.isFinal(f.getModifiers());
 677             fclass   = f.getDeclaringClass();
 678             fname    = f.getName();
 679             ftype    = f.getType();
 680         } else {
 681             Object[] scnt = (Object[]) fieldRef;
 682             isStatic = (Boolean)  scnt[0];
 683             isFinal  = false;
 684             fclass   = (Class<?>) scnt[1];
 685             fname    = (String)   scnt[2];
 686             ftype    = (Class<?>) scnt[3];
 687             try {
 688                 f = fclass.getDeclaredField(fname);
 689             } catch (ReflectiveOperationException ex) {
 690                 f = null;
 691             }
 692         }
 693         if (!testModeMatches(testMode, isStatic))  return;
 694         if (f == null && testMode == TEST_UNREFLECT)  return;
 695         if (testNPE && isStatic)  return;
 696         countTest(positive);
 697         MethodType expType;
 698         if (isGetter)
 699             expType = MethodType.methodType(ftype, HasFields.class);
 700         else
 701             expType = MethodType.methodType(void.class, HasFields.class, ftype);
 702         if (isStatic)  expType = expType.dropParameterTypes(0, 1);
 703         Exception noAccess = null;


 707             case TEST_UNREFLECT:   mh = lookup.unreflectGetter(f);                      break;
 708             case TEST_FIND_FIELD:  mh = lookup.findGetter(fclass, fname, ftype);        break;
 709             case TEST_FIND_STATIC: mh = lookup.findStaticGetter(fclass, fname, ftype);  break;
 710             case TEST_SETTER|
 711                  TEST_UNREFLECT:   mh = lookup.unreflectSetter(f);                      break;
 712             case TEST_SETTER|
 713                  TEST_FIND_FIELD:  mh = lookup.findSetter(fclass, fname, ftype);        break;
 714             case TEST_SETTER|
 715                  TEST_FIND_STATIC: mh = lookup.findStaticSetter(fclass, fname, ftype);  break;
 716             default:
 717                 throw new InternalError("testMode="+testMode);
 718             }
 719         } catch (ReflectiveOperationException ex) {
 720             mh = null;
 721             noAccess = ex;
 722             assertExceptionClass(
 723                 (fname.contains("bogus"))
 724                 ?   NoSuchFieldException.class
 725                 :   IllegalAccessException.class,
 726                 noAccess);
 727             if (((testMode0 & TEST_SETTER) != 0) && (isFinal && isStatic)) return; // Final static field setter test failed as intended.
 728             if (verbosity >= 5)  ex.printStackTrace(System.out);
 729         }
 730         if (verbosity >= 3)
 731             System.out.println((((testMode0 & TEST_UNREFLECT) != 0)?"unreflect":"find")
 732                               +(((testMode0 & TEST_FIND_STATIC) != 0)?"Static":"")
 733                               +(isGetter?"Getter":"Setter")
 734                               +" "+fclass.getName()+"."+fname+"/"+ftype
 735                               +" => "+mh
 736                               +(noAccess == null ? "" : " !! "+noAccess));




 737         if (positive && !testNPE && noAccess != null)  throw new RuntimeException(noAccess);
 738         assertEquals(positive0 ? "positive test" : "negative test erroneously passed", positive0, mh != null);
 739         assertFalse("Setter methods should throw an exception if passed a final static field.", ((testMode0 & TEST_SETTER) != 0) && (isFinal && isStatic));
 740         if (!positive && !testNPE)  return; // negative access test failed as expected
 741         assertEquals((isStatic ? 0 : 1)+(isGetter ? 0 : 1), mh.type().parameterCount());
 742         assertSame(mh.type(), expType);
 743         //assertNameStringContains(mh, fname);  // This does not hold anymore with LFs
 744         HasFields fields = new HasFields();
 745         HasFields fieldsForMH = fields;
 746         if (testNPE)  fieldsForMH = null;  // perturb MH argument to elicit expected error
 747         if (doBound)
 748             mh = mh.bindTo(fieldsForMH);
 749         Object sawValue;
 750         Class<?> vtype = ftype;
 751         if (ftype != int.class)  vtype = Object.class;
 752         if (isGetter) {
 753             mh = mh.asType(mh.type().generic()
 754                            .changeReturnType(vtype));
 755         } else {
 756             int last = mh.type().parameterCount() - 1;
 757             mh = mh.asType(mh.type().generic()
 758                            .changeReturnType(void.class)
 759                            .changeParameterType(last, vtype));
 760         }
 761         if (f != null && f.getDeclaringClass() == HasFields.class) {
 762             assertEquals(f.get(fields), value);  // clean to start with
 763         }
 764         Throwable caughtEx = null;



 765         if (isGetter) {
 766             Object expValue = value;
 767             for (int i = 0; i <= 1; i++) {
 768                 sawValue = null;  // make DA rules happy under try/catch
 769                 try {
 770                     if (isStatic || doBound) {
 771                         if (ftype == int.class)
 772                             sawValue = (int) mh.invokeExact();  // do these exactly
 773                         else
 774                             sawValue = mh.invokeExact();
 775                     } else {
 776                         if (ftype == int.class)
 777                             sawValue = (int) mh.invokeExact((Object) fieldsForMH);
 778                         else
 779                             sawValue = mh.invokeExact((Object) fieldsForMH);
 780                     }
 781                 } catch (RuntimeException ex) {
 782                     if (ex instanceof NullPointerException && testNPE) {
 783                         caughtEx = ex;
 784                         break;
 785                     }
 786                 }
 787                 assertEquals(sawValue, expValue);
 788                 if (f != null && f.getDeclaringClass() == HasFields.class && !isFinal) {
 789                     Object random = randomArg(ftype);
 790                     f.set(fields, random);
 791                     expValue = random;
 792                 } else {
 793                     break;
 794                 }
 795             }
 796         } else {
 797             for (int i = 0; i <= 1; i++) {
 798                 Object putValue = randomArg(ftype);
 799                 try {
 800                     if (isStatic || doBound) {
 801                         if (ftype == int.class)
 802                             mh.invokeExact((int)putValue);  // do these exactly
 803                         else
 804                             mh.invokeExact(putValue);
 805                     } else {
 806                         if (ftype == int.class)
 807                             mh.invokeExact((Object) fieldsForMH, (int)putValue);
 808                         else
 809                             mh.invokeExact((Object) fieldsForMH, putValue);
 810                     }
 811                 } catch (RuntimeException ex) {
 812                     if (ex instanceof NullPointerException && testNPE) {
 813                         caughtEx = ex;
 814                         break;
 815                     }
 816                 }
 817                 if (f != null && f.getDeclaringClass() == HasFields.class) {
 818                     assertEquals(f.get(fields), putValue);
 819                 }
 820             }
 821         }
 822         if ((f != null) && (f.getDeclaringClass() == HasFields.class) && !isFinal) {
 823             f.set(fields, value);  // put it back if we changed it.
 824         }
 825         if (testNPE) {
 826             if (caughtEx == null || !(caughtEx instanceof NullPointerException))
 827                 throw new RuntimeException("failed to catch NPE exception"+(caughtEx == null ? " (caughtEx=null)" : ""), caughtEx);
 828             caughtEx = null;  // nullify expected exception
 829         }
 830         if (caughtEx != null) {
 831             throw new RuntimeException("unexpected exception", caughtEx);
 832         }
 833     }
 834 
 835     @Test
 836     public void testUnreflectSetter() throws Throwable {
 837         CodeCacheOverflowProcessor.runMHTest(this::testUnreflectSetter0);
 838     }
 839 
 840     public void testUnreflectSetter0() throws Throwable {
 841         if (CAN_SKIP_WORKING)  return;
 842         startTest("unreflectSetter");
 843         testSetter(TEST_UNREFLECT);


 851     public void testFindSetter0() throws Throwable {
 852         if (CAN_SKIP_WORKING)  return;
 853         startTest("findSetter");
 854         testSetter(TEST_FIND_FIELD);
 855         testSetter(TEST_FIND_FIELD | TEST_BOUND);
 856     }
 857 
 858     @Test
 859     public void testFindStaticSetter() throws Throwable {
 860         CodeCacheOverflowProcessor.runMHTest(this::testFindStaticSetter0);
 861     }
 862 
 863     public void testFindStaticSetter0() throws Throwable {
 864         if (CAN_SKIP_WORKING)  return;
 865         startTest("findStaticSetter");
 866         testSetter(TEST_FIND_STATIC);
 867     }
 868 
 869     public void testSetter(int testMode) throws Throwable {
 870         Lookup lookup = PRIVATE;  // FIXME: test more lookups than this one
 871         for (Object[] c : HasFields.CASES) {

 872             boolean positive = (c[1] != Error.class);
 873             testSetter(positive, lookup, c[0], c[1], testMode);
 874             if (positive)
 875                 testSetter(positive, lookup, c[0], c[1], testMode | TEST_NPE);
 876         }
 877         for (int isStaticN = 0; isStaticN <= 1; isStaticN++) {
 878             testSetter(false, lookup,
 879                        new Object[]{ (isStaticN != 0), System.class, "bogus", char.class },
 880                        null, testMode);
 881         }
 882     }
 883 
 884     public void testSetter(boolean positive, MethodHandles.Lookup lookup,
 885                            Object fieldRef, Object value, int testMode) throws Throwable {
 886         testAccessor(positive, lookup, fieldRef, value, testMode | TEST_SETTER);
 887     }
 888 
 889     @Test
 890     public void testArrayElementGetter() throws Throwable {
 891         CodeCacheOverflowProcessor.runMHTest(this::testArrayElementGetter0);


< prev index next >