hotspot/test/runtime/lambda-features/TestInterfaceOrder.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 27402 5c4675ddc00c
permissions -rw-r--r--
8165687: Fix license and copyright headers in jd9 under hotspot/test Summary: Legal notices and Oracle copyrights were updated (white and blank space, commas) in tests files for uniformity to meet Oracle requirements. Reviewed-by: dholmes, iris Contributed-by: Stanislav Smirnov <stanislav.smirnov@oracle.com>, Vassili Igouchkine <vassili.igouchkine@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     1
/*
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     4
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     8
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    13
 * accompanied this code).
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    14
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    18
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    21
 * questions.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    22
 */
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    23
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    24
/*
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    25
 * @test
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    26
 * @bug 8034275
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    27
 * @summary [JDK 8u40] Test interface initialization order
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    28
 * @run main TestInterfaceOrder
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    29
 */
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    30
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    31
import java.util.List;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    32
import java.util.Arrays;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    33
import java.util.ArrayList;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    34
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    35
public class TestInterfaceOrder {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    36
  static List<Class<?>> cInitOrder = new ArrayList<>();
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    37
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    38
  public static void main(java.lang.String[] args) {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    39
    //Trigger initialization
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    40
    C c = new C();
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    41
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    42
    List<Class<?>> expectedCInitOrder = Arrays.asList(I.class, J.class, A.class, K.class, B.class, L.class, C.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    43
    if (!cInitOrder.equals(expectedCInitOrder)) {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    44
      throw new RuntimeException(String.format("Class initialization order %s not equal to expected order %s", cInitOrder, expectedCInitOrder));
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    45
    }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    46
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    47
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    48
  interface I {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    49
    boolean v = TestInterfaceOrder.out(I.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    50
   default void i() {}
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    51
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    52
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    53
  interface J extends I {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    54
    boolean v = TestInterfaceOrder.out(J.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    55
    default void j() {}
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    56
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    57
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    58
  static class A implements J {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    59
    static boolean v = TestInterfaceOrder.out(A.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    60
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    61
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    62
  interface K extends I {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    63
    boolean v = TestInterfaceOrder.out(K.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    64
    default void k() {}
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    65
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    66
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    67
  static class B extends A implements K {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    68
    static boolean v = TestInterfaceOrder.out(B.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    69
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    70
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    71
  interface L  {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    72
    boolean v = TestInterfaceOrder.out(L.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    73
    default void l() {}
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    74
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    75
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    76
  static class C extends B implements L {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    77
    static boolean v = TestInterfaceOrder.out(C.class);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    78
  }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    79
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    80
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    81
   static boolean out(Class c) {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    82
       System.out.println("#: initializing " + c.getName());
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    83
       cInitOrder.add(c);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    84
       return true;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    85
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    86
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    87
}