test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/StaticMethodsTest.java
changeset 50243 4fac3c99487d
equal deleted inserted replaced
50242:9a87afc49148 50243:4fac3c99487d
       
     1 /*
       
     2  * Copyright (c) 2013, 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  */
       
    23 
       
    24 package vm.runtime.defmeth;
       
    25 
       
    26 import nsk.share.test.TestBase;
       
    27 import vm.runtime.defmeth.shared.DefMethTest;
       
    28 import vm.runtime.defmeth.shared.annotation.Crash;
       
    29 import vm.runtime.defmeth.shared.data.*;
       
    30 import vm.runtime.defmeth.shared.builder.TestBuilder;
       
    31 import vm.runtime.defmeth.shared.annotation.NotApplicableFor;
       
    32 import static vm.runtime.defmeth.shared.data.method.body.CallMethod.Invoke.*;
       
    33 import static vm.runtime.defmeth.shared.data.method.body.CallMethod.IndexbyteOp.*;
       
    34 import static vm.runtime.defmeth.shared.ExecutionMode.*;
       
    35 
       
    36 /*
       
    37  * Scenarios on static methods in interfaces.
       
    38  */
       
    39 public class StaticMethodsTest extends DefMethTest {
       
    40 
       
    41     public static void main(String[] args) {
       
    42         TestBase.runTest(new StaticMethodsTest(), args);
       
    43     }
       
    44 
       
    45     // static method in interface
       
    46     /*
       
    47      * testStaticMethod
       
    48      *
       
    49      * interface I {
       
    50      *  default static public int m() { return 1; }
       
    51      * }
       
    52      *
       
    53      * class C implements I {}
       
    54      */
       
    55     public void testStaticMethod() {
       
    56         TestBuilder b = factory.getBuilder();
       
    57 
       
    58         Interface I = b.intf("I")
       
    59                 .defaultMethod("m", "()I")
       
    60                     .static_().public_().returns(1).build()
       
    61             .build();
       
    62 
       
    63         ConcreteClass C = b.clazz("C").implement(I).build();
       
    64 
       
    65         b.test().staticCallSite(I, "m", "()I").returns(1).done()
       
    66 
       
    67         .run();
       
    68     }
       
    69 
       
    70     // invoke[virtual|interface|special] from same/subintf
       
    71     /*
       
    72      * testInvokeVirtual
       
    73      *
       
    74      * interface I {
       
    75      *  default static public int staticM() { return 1; }
       
    76      *  default public int m() { return ((I)this).staticM(); }
       
    77      * }
       
    78      *
       
    79      * class C implements I {}
       
    80      */
       
    81     public void testInvokeVirtual() {
       
    82         TestBuilder b = factory.getBuilder();
       
    83 
       
    84         Interface I = b.intf("I")
       
    85                 .defaultMethod("staticM", "()I")
       
    86                     .static_().public_().returns(1).build()
       
    87 
       
    88                 // force an invokevirtual MR of staticM()
       
    89                 .defaultMethod("m", "()I")
       
    90                     .invoke(VIRTUAL, b.intfByName("I"), null, "staticM", "()I", METHODREF).build()
       
    91             .build();
       
    92 
       
    93         ConcreteClass C = b.clazz("C").implement(I).build();
       
    94 
       
    95         b.test().staticCallSite(I, "staticM", "()I").returns(1).done()
       
    96 
       
    97          .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
    98          .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
    99 
       
   100         .run();
       
   101     }
       
   102 
       
   103     /*
       
   104      * testInvokeIntf
       
   105      *
       
   106      * interface I {
       
   107      *  default static public int staticM() { return 1; }
       
   108      *  default public int m() { return ((I)this).staticM(); }
       
   109      * }
       
   110      *
       
   111      * class C implements I {}
       
   112      */
       
   113     public void testInvokeIntf() {
       
   114         TestBuilder b = factory.getBuilder();
       
   115 
       
   116         Interface I = b.intf("I")
       
   117                 .defaultMethod("staticM", "()I")
       
   118                     .static_().public_().returns(1).build()
       
   119 
       
   120                 .defaultMethod("m", "()I")
       
   121                     .invoke(INTERFACE, b.intfByName("I"), null, "staticM", "()I", CALLSITE).build()
       
   122             .build();
       
   123 
       
   124         ConcreteClass C = b.clazz("C").implement(I).build();
       
   125 
       
   126         b.test().staticCallSite(I, "staticM", "()I").returns(1).done()
       
   127 
       
   128          .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   129          .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   130 
       
   131         .run();
       
   132     }
       
   133 
       
   134     /*
       
   135      * testInvokeSpecial
       
   136      *
       
   137      * interface I {
       
   138      *  default static public int staticM() { return 1; }
       
   139      *  default public int m() { return I.super.staticM(); }
       
   140      * }
       
   141      *
       
   142      * class C implements I {}
       
   143      */
       
   144     public void testInvokeSpecial() {
       
   145         TestBuilder b = factory.getBuilder();
       
   146 
       
   147         Interface I = b.intf("I")
       
   148                 .defaultMethod("staticM", "()I")
       
   149                     .static_().public_().returns(1).build()
       
   150 
       
   151                 .defaultMethod("m", "()I")
       
   152                     .invoke(SPECIAL, b.intfByName("I"), null, "staticM", "()I", CALLSITE).build()
       
   153             .build();
       
   154 
       
   155         ConcreteClass C = b.clazz("C").implement(I).build();
       
   156 
       
   157         b.test().staticCallSite(I, "staticM", "()I").returns(1).done()
       
   158 
       
   159          .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   160          .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   161 
       
   162         .run();
       
   163     }
       
   164 
       
   165     /*
       
   166      * testStaticVsDefault
       
   167      *
       
   168      * interface I {
       
   169      *  default static public int m() { return 1; }
       
   170      *  default public int m() { return 2; }
       
   171      * }
       
   172      *
       
   173      * class C implements I {}
       
   174      */
       
   175     public void testStaticVsDefault() {
       
   176         TestBuilder b = factory.getBuilder();
       
   177 
       
   178         Interface I = b.intf("I")
       
   179                 .defaultMethod("m", "()I")
       
   180                     .static_().public_().returns(1).build()
       
   181                 .defaultMethod("m", "()I")
       
   182                     .public_().returns(2).build()
       
   183             .build();
       
   184 
       
   185         ConcreteClass C = b.clazz("C").implement(I).build();
       
   186 
       
   187         b.test().staticCallSite(I, "m", "()I").throws_(ClassFormatError.class).done()
       
   188 
       
   189          // FIXME: throws exception during an attempt to lookup Test2.test() method
       
   190 
       
   191          // Invalid test. ClassFormatError is thrown at verification time, rather
       
   192          // than execution time.
       
   193          // .test().callSite(I, C, "m", "()I").throws_(ClassFormatError.class).done()
       
   194          .test().callSite(C, C, "m", "()I").throws_(ClassFormatError.class).done()
       
   195 
       
   196         .run();
       
   197     }
       
   198 
       
   199     // call static method from default method
       
   200     /*
       
   201      * testInvokeFromDefaultMethod
       
   202      *
       
   203      * interface I {
       
   204      *  default static public int staticPublicM() { return 1; }
       
   205      *  default public int invokePublic() { return I.staticPublicM(); }
       
   206      *  default static private int staticPrivateM() { return 1; }
       
   207      *  default public int invokePrivate() { return I.staticPrivateM(); }
       
   208      * }
       
   209      *
       
   210      * class C implements I {}
       
   211      */
       
   212     public void testInvokeFromDefaultMethod() throws Exception {
       
   213         TestBuilder b = factory.getBuilder();
       
   214 
       
   215         Interface I = b.intf("I")
       
   216                 .defaultMethod("staticPublicM", "()I")
       
   217                     .static_().public_().returns(1).build()
       
   218                 .defaultMethod("invokePublic", "()I")
       
   219                     .invokeStatic(b.intfByName("I"), "staticPublicM", "()I").build()
       
   220 
       
   221                 .defaultMethod("staticPrivateM", "()I")
       
   222                     .static_().private_().returns(1).build()
       
   223                 .defaultMethod("invokePrivate", "()I")
       
   224                     .invokeStatic(b.intfByName("I"), "staticPrivateM", "()I").build()
       
   225             .build();
       
   226 
       
   227         ConcreteClass C = b.clazz("C").implement(I).build();
       
   228 
       
   229         Class expectedClass;
       
   230         if (factory.getExecutionMode().equals("REFLECTION")) {
       
   231             expectedClass = NoSuchMethodException.class;
       
   232         } else {
       
   233             expectedClass = IllegalAccessError.class;
       
   234         }
       
   235 
       
   236         // call static method from another class
       
   237         b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
       
   238          .test().staticCallSite(I, "staticPrivateM", "()I").throws_(expectedClass).done()
       
   239 
       
   240          // call public static method from default method
       
   241          .test().callSite(I, C, "invokePublic", "()I").returns(1).done()
       
   242          .test().callSite(C, C, "invokePublic", "()I").returns(1).done()
       
   243 
       
   244          // call private static method from default method
       
   245          .test().callSite(I, C, "invokePrivate", "()I").returns(1).done()
       
   246          .test().callSite(C, C, "invokePrivate", "()I").returns(1).done()
       
   247 
       
   248         .run();
       
   249     }
       
   250 
       
   251     // call static method from implementing subclass
       
   252     /*
       
   253      * testInvokeFromSubclass
       
   254      *
       
   255      * interface I {
       
   256      *  default static public int staticPublicM() { return 1; }
       
   257      *  default static private int staticPrivateM() { return 1; }
       
   258      * }
       
   259      *
       
   260      * class C implements I {
       
   261      *  public int invokePublic() { return I.staticPublicM(); }
       
   262      *  public int invokePrivate() { return I.staticPublicM(); }
       
   263      *
       
   264      * I.staticPublicM();  ==> returns 1;
       
   265      * I.staticPrivateM(); ==> Either NSME or IAE depending on execution mode
       
   266      * C c = new C(); c.invokePublic(); ==> returns 1 or if -ver < 52 IAE or VerifyError
       
   267      * C c = new C(); c.invokePrivate() ==> IAE or if -ver < 52, IAE or VerifyError
       
   268      * }
       
   269      */
       
   270 
       
   271     @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
       
   272     public void testInvokeFromSubclass() throws Exception {
       
   273         TestBuilder b = factory.getBuilder();
       
   274 
       
   275         Interface I = b.intf("I")
       
   276                 .defaultMethod("staticPublicM", "()I")
       
   277                     .static_().public_().returns(1).build()
       
   278 
       
   279                 .defaultMethod("staticPrivateM", "()I")
       
   280                     .static_().private_().returns(1).build()
       
   281             .build();
       
   282 
       
   283         ConcreteClass C = b.clazz("C").implement(I)
       
   284                 .concreteMethod("invokePublic", "()I")
       
   285                     .invokeStatic(b.intfByName("I"), "staticPublicM", "()I").build()
       
   286                 .concreteMethod("invokePrivate", "()I")
       
   287                     .invokeStatic(b.intfByName("I"), "staticPrivateM", "()I").build()
       
   288             .build();
       
   289 
       
   290         Class expectedError1;
       
   291         if (factory.getExecutionMode().equals("REFLECTION")) {
       
   292             expectedError1 = NoSuchMethodException.class;
       
   293         } else {
       
   294             expectedError1 = IllegalAccessError.class;
       
   295         }
       
   296 
       
   297         // Adjust for -ver < 52
       
   298         if (factory.getVer() >=52) {
       
   299             // call static method from another class
       
   300             b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
       
   301              .test().staticCallSite(I, "staticPrivateM", "()I").throws_(expectedError1).done()
       
   302 
       
   303             // call static method from implementing subclass
       
   304              .test().callSite(C, C, "invokePublic", "()I").returns(1).done()
       
   305              .test().callSite(C, C, "invokePrivate", "()I").throws_(IllegalAccessError.class).done()
       
   306 
       
   307             .run();
       
   308         } else {
       
   309             // call static method from another class
       
   310             b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
       
   311              .test().staticCallSite(I, "staticPrivateM", "()I").throws_(expectedError1).done()
       
   312 
       
   313             // call static method from implementing subclass
       
   314             // invokestatic IMR - not supported for ver < 52
       
   315              .test().callSite(C, C, "invokePublic",  "()I").throws_(VerifyError.class).done()
       
   316              .test().callSite(C, C, "invokePrivate", "()I").throws_(VerifyError.class).done()
       
   317 
       
   318             .run();
       
   319         }
       
   320     }
       
   321 
       
   322     // static method doesn't participate in default method analysis:
       
   323     //   method overriding
       
   324     /*
       
   325      * testNotInherited
       
   326      *
       
   327      * interface I {
       
   328      *  default static public int m() { return 1; }
       
   329      * }
       
   330      *
       
   331      * class C implements I {}
       
   332      */
       
   333     public void testNotInherited() {
       
   334         TestBuilder b = factory.getBuilder();
       
   335 
       
   336         Interface I = b.intf("I")
       
   337                 .defaultMethod("m", "()I")
       
   338                     .static_().public_().returns(1).build()
       
   339             .build();
       
   340 
       
   341         ConcreteClass C = b.clazz("C").implement(I).build();
       
   342 
       
   343         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   344             b.test().staticCallSite(I, "m", "()I").returns(1).done()
       
   345               // invokeinterface to static method ==> ICCE
       
   346               .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   347              .test().callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done()
       
   348             .run();
       
   349         } else {
       
   350             b.test().staticCallSite(I, "m", "()I").returns(1).done()
       
   351              .test().callSite(I, C, "m", "()I").returns(1).done()
       
   352              .test().callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done()
       
   353             .run();
       
   354         }
       
   355     }
       
   356 
       
   357     /*
       
   358      * testDefaultVsConcrete
       
   359      *
       
   360      * interface I {
       
   361      *  default static public int m() { return 1; }
       
   362      * }
       
   363      *
       
   364      * class C implements I {
       
   365      *  public int m() { return 2; }
       
   366      * }
       
   367      * TEST: I o = new C(); o.m()I throws ICCE
       
   368      * TEST: C o = new C(); o.m()I == 2
       
   369      */
       
   370     public void testDefaultVsConcrete() {
       
   371         TestBuilder b = factory.getBuilder();
       
   372 
       
   373         Interface I = b.intf("I")
       
   374                 .defaultMethod("m", "()I")
       
   375                     .static_().public_().returns(1).build()
       
   376             .build();
       
   377 
       
   378         ConcreteClass C = b.clazz("C").implement(I)
       
   379                 .concreteMethod("m", "()I").returns(2).build()
       
   380             .build();
       
   381 
       
   382         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   383             // invokeinterface to static method ==> ICCE
       
   384             b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   385              .test().callSite(C, C, "m", "()I").returns(2).done().run();
       
   386         } else {
       
   387             b.test().callSite(I, C, "m", "()I").returns(1).done()
       
   388              .test().callSite(C, C, "m", "()I").returns(2).done().run();
       
   389         }
       
   390 
       
   391     }
       
   392 
       
   393     /*
       
   394      * TEST: StaticMethodsTest.testOverrideStatic
       
   395      *
       
   396      * interface I {
       
   397      *  default static public int m() { return 1; }
       
   398      * }
       
   399      *
       
   400      * interface J extends I {
       
   401      *  default public int m() { return 2; }
       
   402      * }
       
   403      *
       
   404      * class C implements J {
       
   405      * }
       
   406      */
       
   407     public void testOverrideStatic() {
       
   408         TestBuilder b = factory.getBuilder();
       
   409 
       
   410         Interface I = b.intf("I")
       
   411                 .defaultMethod("m", "()I")
       
   412                     .static_().public_().returns(1).build()
       
   413             .build();
       
   414 
       
   415         Interface J = b.intf("J").extend(I)
       
   416                 .defaultMethod("m", "()I")
       
   417                     .returns(2).build()
       
   418             .build();
       
   419 
       
   420         ConcreteClass C = b.clazz("C").implement(J).build();
       
   421 
       
   422         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   423             b.test().staticCallSite(I, "m", "()I").returns(1).done()
       
   424              .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   425              .test().callSite(J, C, "m", "()I").returns(2).done()
       
   426              .test().callSite(C, C, "m", "()I").returns(2).done()
       
   427             .run();
       
   428         } else {
       
   429             b.test().staticCallSite(I, "m", "()I").returns(1).done()
       
   430              .test().callSite(I, C, "m", "()I").returns(1).done()
       
   431              .test().callSite(J, C, "m", "()I").returns(2).done()
       
   432              .test().callSite(C, C, "m", "()I").returns(2).done()
       
   433             .run();
       
   434         }
       
   435 
       
   436     }
       
   437 
       
   438     /*
       
   439      * testOverrideDefault
       
   440      *
       
   441      * interface I {
       
   442      *  default public int m() { return 1; }
       
   443      * }
       
   444      *
       
   445      * interface J extends I {
       
   446      *  default static public int m() { return 2; }
       
   447      * }
       
   448      *
       
   449      * class C implements J {}
       
   450      *
       
   451      * TEST: I o = new C(); o.m()I == 1
       
   452      * TEST: J o = new C(); o.m()I == ICCE
       
   453      * TEST: C o = new C(); o.m()I == 1
       
   454      */
       
   455     public void testOverrideDefault() {
       
   456         TestBuilder b = factory.getBuilder();
       
   457 
       
   458         Interface I = b.intf("I")
       
   459                 .defaultMethod("m", "()I")
       
   460                     .returns(1).build()
       
   461             .build();
       
   462 
       
   463         Interface J = b.intf("J").extend(I)
       
   464                 .defaultMethod("m", "()I")
       
   465                     .static_().public_().returns(2).build()
       
   466             .build();
       
   467 
       
   468         ConcreteClass C = b.clazz("C").implement(J).build();
       
   469 
       
   470         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   471             b.test().callSite(I, C, "m", "()I").returns(1).done()
       
   472              .test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   473              .test().callSite(C, C, "m", "()I").returns(1).done()
       
   474 
       
   475             .run();
       
   476 
       
   477         } else {
       
   478             // Reflection correctly finds the static method defined in J and
       
   479             // calls it with invokestatic.
       
   480 
       
   481             b.test().callSite(I, C, "m", "()I").returns(1).done()
       
   482              .test().callSite(J, C, "m", "()I").returns(2).done()
       
   483              .test().callSite(C, C, "m", "()I").returns(1).done()
       
   484 
       
   485             .run();
       
   486         }
       
   487     }
       
   488 
       
   489     /*
       
   490      * testReabstract
       
   491      *
       
   492      * interface I {
       
   493      *  default static public int m() { return 1; }
       
   494      * }
       
   495      *
       
   496      * interface J extends I {
       
   497      *  abstract public int m();
       
   498      * }
       
   499      *
       
   500      * class C implements J {}
       
   501      *
       
   502      * TEST: I o = new C(); o.m()I throws ICCE
       
   503      *                             -mode reflect returns 1
       
   504      * TEST: J o = new C(); o.m()I throws AME
       
   505      * TEST: C o = new C(); o.m()I throws AME
       
   506      */
       
   507     public void testReabstract() {
       
   508         TestBuilder b = factory.getBuilder();
       
   509 
       
   510         Interface I = b.intf("I")
       
   511                 .defaultMethod("m", "()I")
       
   512                     .static_().public_().returns(1).build()
       
   513             .build();
       
   514 
       
   515         Interface J = b.intf("J").extend(I)
       
   516                 .abstractMethod("m", "()I").build()
       
   517             .build();
       
   518 
       
   519         ConcreteClass C = b.clazz("C").implement(J).build();
       
   520 
       
   521         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   522             b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   523              .test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   524              .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   525             .run();
       
   526         } else {
       
   527             b.test().callSite(I, C, "m", "()I").returns(1).done()
       
   528              .test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   529              .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   530             .run();
       
   531         }
       
   532     }
       
   533 
       
   534     /*
       
   535      * testOverrideAbstract
       
   536      *
       
   537      * interface I {
       
   538      *  abstract public int m();
       
   539      * }
       
   540      *
       
   541      * interface J extends I {
       
   542      *  default static public int m() { return 1; }
       
   543      * }
       
   544      *
       
   545      * class C implements J {}
       
   546      *
       
   547      * TEST: I o = new C(); o.m()I throws AME
       
   548      * TEST: J o = new C(); o.m()I throws ICCE
       
   549      *                             -mode reflect returns 1
       
   550      * TEST: C o = new C(); o.m()I throws AME
       
   551      */
       
   552     public void testOverrideAbstract() {
       
   553         TestBuilder b = factory.getBuilder();
       
   554 
       
   555         Interface I = b.intf("I")
       
   556                 .abstractMethod("m", "()I").build()
       
   557             .build();
       
   558 
       
   559         Interface J = b.intf("J").extend(I)
       
   560                 .defaultMethod("m", "()I")
       
   561                     .static_().public_().returns(1).build()
       
   562             .build();
       
   563 
       
   564         ConcreteClass C = b.clazz("C").implement(J).build();
       
   565 
       
   566         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   567             b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   568              .test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   569              .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   570 
       
   571             .run();
       
   572         } else {
       
   573             b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   574              .test().callSite(J, C, "m", "()I").returns(1).done()
       
   575              .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
       
   576 
       
   577             .run();
       
   578         }
       
   579     }
       
   580 
       
   581     /*
       
   582      * testInheritedDefault
       
   583      *
       
   584      * interface I {
       
   585      *  default static public int m() { return 1; }
       
   586      * }
       
   587      *
       
   588      * class B implements I {}
       
   589      *
       
   590      * class C extends B {}
       
   591      *
       
   592      * TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError
       
   593      *                             -mode reflect returns 1
       
   594      * TEST: B o = new C(); o.m()I throws NoSuchMethodError
       
   595      * TEST: C o = new C(); o.m()I throws NoSuchMethodError
       
   596      */
       
   597     public void testInheritedDefault() {
       
   598         TestBuilder b = factory.getBuilder();
       
   599 
       
   600         Interface I = b.intf("I")
       
   601                 .defaultMethod("m", "()I")
       
   602                     .static_().public_().returns(1).build()
       
   603             .build();
       
   604 
       
   605         ConcreteClass B = b.clazz("B").implement(I).build();
       
   606         ConcreteClass C = b.clazz("C").extend(B).build();
       
   607 
       
   608         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   609             b.test().callSite(I, C, "m","()I").throws_(IncompatibleClassChangeError.class).done()
       
   610              .test().callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done()
       
   611              .test().callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done()
       
   612             .run();
       
   613         } else {
       
   614             b.test().callSite(I, C, "m","()I").returns(1).done()
       
   615              .test().callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done()
       
   616              .test().callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done()
       
   617             .run();
       
   618         }
       
   619 
       
   620     }
       
   621 
       
   622     /*
       
   623      * testDefaultVsConcreteInherited
       
   624      *
       
   625      * interface I {
       
   626      *  default static public int m() { return 1; }
       
   627      * }
       
   628      *
       
   629      * class B {
       
   630      *  public int m() { return 2; }
       
   631      * }
       
   632      *
       
   633      * class C extends B implements I {}
       
   634      *
       
   635      */
       
   636     public void testDefaultVsConcreteInherited() {
       
   637         TestBuilder b = factory.getBuilder();
       
   638 
       
   639         Interface I = b.intf("I")
       
   640                 .defaultMethod("m", "()I")
       
   641                     .static_().public_().returns(1).build()
       
   642             .build();
       
   643 
       
   644         ConcreteClass B = b.clazz("B")
       
   645                 .concreteMethod("m", "()I").returns(2).build()
       
   646                 .build();
       
   647 
       
   648         ConcreteClass C = b.clazz("C").extend(B).implement(I).build();
       
   649 
       
   650         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   651             b.test().staticCallSite(I, "m","()I").returns(1).done()
       
   652              .test().callSite(I, C, "m","()I").throws_(IncompatibleClassChangeError.class).done()
       
   653              .test().callSite(B, C, "m","()I").returns(2).done()
       
   654              .test().callSite(C, C, "m","()I").returns(2).done()
       
   655             .run();
       
   656         } else {
       
   657             b.test().staticCallSite(I, "m","()I").returns(1).done()
       
   658              .test().callSite(I, C, "m","()I").returns(1).done()
       
   659              .test().callSite(B, C, "m","()I").returns(2).done()
       
   660              .test().callSite(C, C, "m","()I").returns(2).done()
       
   661             .run();
       
   662         }
       
   663 
       
   664     }
       
   665 
       
   666     /*
       
   667      * testDefaultVsStaticConflict
       
   668      *
       
   669      * interface I {
       
   670      *  default static public int m() { return 1; }
       
   671      * }
       
   672      *
       
   673      * interface J {
       
   674      *  default public int m() { return 2; }
       
   675      * }
       
   676      *
       
   677      * class C implements I, J {}
       
   678      *
       
   679      * TEST: I o = new C(); o.m()I throws ICCE
       
   680      *                             -mode reflect returns 1
       
   681      * TEST: J o = new C(); o.m()I == 2
       
   682      * TEST: C o = new C(); o.m()I == 2
       
   683      */
       
   684     public void testDefaultVsStaticConflict() {
       
   685         TestBuilder b = factory.getBuilder();
       
   686 
       
   687         Interface I = b.intf("I")
       
   688                 .defaultMethod("m", "()I")
       
   689                     .static_().public_().returns(1).build()
       
   690             .build();
       
   691 
       
   692         Interface J = b.intf("J")
       
   693                 .defaultMethod("m", "()I").returns(2).build()
       
   694             .build();
       
   695 
       
   696         ConcreteClass C = b.clazz("C").implement(I,J).build();
       
   697 
       
   698         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   699             b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   700              .test().callSite(J, C, "m", "()I").returns(2).done()
       
   701              .test().callSite(C, C, "m", "()I").returns(2).done()
       
   702             .run();
       
   703         } else {
       
   704             b.test().callSite(I, C, "m", "()I").returns(1).done()
       
   705              .test().callSite(J, C, "m", "()I").returns(2).done()
       
   706              .test().callSite(C, C, "m", "()I").returns(2).done()
       
   707             .run();
       
   708         }
       
   709 
       
   710     }
       
   711     /*
       
   712      * testStaticSuperClassVsDefaultSuperInterface
       
   713      *
       
   714      * interface I {
       
   715      *  default public int m() { return 1; }
       
   716      * }
       
   717      *
       
   718      * class A {
       
   719      *  public static int m() { return 2; }
       
   720      * }
       
   721      *
       
   722      * class C extends A implements I {}
       
   723      *
       
   724      * TEST: C o = new C(); o.m()I throws ICCE
       
   725      *                             -mode reflect returns 2
       
   726      * TEST: I o = new C(); o.m()I == 1
       
   727      */
       
   728     public void testStaticSuperClassVsDefaultSuperInterface() {
       
   729         TestBuilder b = factory.getBuilder();
       
   730 
       
   731         Interface I = b.intf("I")
       
   732                 .defaultMethod("m", "()I")
       
   733                     .public_().returns(1).build()
       
   734             .build();
       
   735 
       
   736         ConcreteClass A = b.clazz("A")
       
   737                 .concreteMethod("m", "()I")
       
   738                     .static_().public_().returns(2).build()
       
   739             .build();
       
   740 
       
   741         ConcreteClass C = b.clazz("C").extend(A).implement(I).build();
       
   742 
       
   743         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   744             b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   745              .test().callSite(I, C, "m", "()I").returns(1).done()
       
   746             .run();
       
   747         } else {
       
   748             b.test().callSite(C, C, "m", "()I").returns(2).done()
       
   749              .test().callSite(I, C, "m", "()I").returns(1).done()
       
   750             .run();
       
   751         }
       
   752     }
       
   753     /*
       
   754      * testStaticLocalVsDefaultSuperInterface
       
   755      *
       
   756      * interface I {
       
   757      *  default public int m() { return 1; }
       
   758      * }
       
   759      *
       
   760      * class A implements I {
       
   761      *  public static int m() { return 2; }
       
   762      * }
       
   763      *
       
   764      * class C extends A implements I {}
       
   765      *
       
   766      * TEST: A o = new A(); o.m()I throws ICCE
       
   767      *                             -mode reflect returns 2
       
   768      * TEST: I o = new A(); o.m()I == 1
       
   769      */
       
   770     public void testStaticLocalVsDefaultSuperInterface() {
       
   771         TestBuilder b = factory.getBuilder();
       
   772 
       
   773         Interface I = b.intf("I")
       
   774                 .defaultMethod("m", "()I")
       
   775                     .public_().returns(1).build()
       
   776             .build();
       
   777 
       
   778         ConcreteClass A = b.clazz("A").implement(I)
       
   779                 .concreteMethod("m", "()I")
       
   780                     .static_().public_().returns(2).build()
       
   781             .build();
       
   782 
       
   783         ConcreteClass C = b.clazz("C").extend(A).implement(I).build();
       
   784 
       
   785         if (!factory.getExecutionMode().equals("REFLECTION")) {
       
   786             b.test().callSite(A, A, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
       
   787              .test().callSite(I, A, "m", "()I").returns(1).done()
       
   788             .run();
       
   789         } else {
       
   790             b.test().callSite(A, A, "m", "()I").returns(2).done()
       
   791              .test().callSite(I, A, "m", "()I").returns(1).done()
       
   792             .run();
       
   793         }
       
   794     }
       
   795     /*
       
   796      * testConflictingDefaultsandStaticMethod
       
   797      * @bug 8033150
       
   798      *
       
   799      * interface I {
       
   800      *  default public int m() { return 1; }
       
   801      * }
       
   802      *
       
   803      * interface J {
       
   804      *  default public int m() { return 2; }
       
   805      * }
       
   806      *
       
   807      * class A implements I, J {
       
   808      *  public static int m() { return 3; }
       
   809      * }
       
   810      *
       
   811      * class C extends A {}
       
   812      *
       
   813      * TEST: C.m(); should call A.m, return value = 3
       
   814      */
       
   815     public void testConflictingDefaultsandStaticMethod() {
       
   816         TestBuilder b = factory.getBuilder();
       
   817 
       
   818         Interface I = b.intf("I")
       
   819                 .defaultMethod("m", "()I")
       
   820                     .public_().returns(1).build()
       
   821             .build();
       
   822 
       
   823         Interface J = b.intf("J")
       
   824                 .defaultMethod("m", "()I")
       
   825                     .public_().returns(2).build()
       
   826             .build();
       
   827 
       
   828         ConcreteClass A = b.clazz("A").implement(I,J)
       
   829                 .concreteMethod("m", "()I")
       
   830                     .static_().public_().returns(3).build()
       
   831             .build();
       
   832 
       
   833         ConcreteClass C = b.clazz("C").extend(A).build();
       
   834 
       
   835         b.test().staticCallSite(C, "m", "()I").returns(3).done()
       
   836          .run();
       
   837     }
       
   838 }