hotspot/test/compiler/inlining/DefaultAndConcreteMethodsCHA.java
author duke
Wed, 05 Jul 2017 22:24:41 +0200
changeset 41867 d62173b931bf
parent 40059 c2304140ed64
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22514
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     1
/*
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     4
 *
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     8
 *
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    14
 *
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    18
 *
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    21
 * questions.
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    22
 */
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    23
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    24
/**
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    25
 * @test
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    26
 * @bug 8031695
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    27
 * @summary CHA ignores default methods during analysis leading to incorrect code generation
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    28
 *
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    29
 * @run main/othervm -Xbatch compiler.inlining.DefaultAndConcreteMethodsCHA
22514
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    30
 */
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    31
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    32
package compiler.inlining;
22514
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    33
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    34
public class DefaultAndConcreteMethodsCHA {
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    35
    interface I {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    36
        default int m() { return 0; }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    37
    }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    38
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    39
    static class A implements I {}
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    40
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    41
    static class C extends A { }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    42
    static class D extends A { public int m() { return 1; } }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 22514
diff changeset
    43
22514
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    44
    public static int test(A obj) {
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    45
        return obj.m();
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    46
    }
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    47
    public static void main(String[] args) {
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    48
        for (int i = 0; i < 10000; i++) {
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    49
            int idC = test(new C());
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    50
            if (idC != 0) {
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    51
                throw new Error("C.m didn't invoke I.m: id "+idC);
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    52
            }
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    53
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    54
            int idD = test(new D());
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    55
            if (idD != 1) {
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    56
                throw new Error("D.m didn't invoke D.m: id "+idD);
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    57
            }
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    58
        }
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    59
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    60
    }
7f26d1aea7a4 8031695: CHA ignores default methods during analysis leading to incorrect code generation
vlivanov
parents:
diff changeset
    61
}