test/hotspot/jtreg/compiler/linkage/LinkageErrors.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 51351 2bb9b1abadbf
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     1
/*
51351
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     4
 *
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     8
 *
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    14
 *
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    18
 *
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    21
 * questions.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    22
 */
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40059
diff changeset
    23
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    24
/*
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    25
 * @test
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    26
 * @bug 8132879
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    27
 * @compile CallSites.jasm
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    28
 * @run main/othervm -Xverify:all -Xbatch
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    29
 *                   -XX:CompileCommand=dontinline,compiler.linkage.LinkageErrors::test*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    30
 *                   compiler.linkage.LinkageErrors
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    31
 */
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    32
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    33
package compiler.linkage;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    34
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    35
import java.lang.invoke.MethodHandle;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    36
import java.lang.invoke.MethodHandles;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    37
import java.lang.invoke.MethodType;
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    38
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    39
interface I {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    40
    void m1(int i);
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    41
    static void s1() {}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    42
}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    43
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    44
class A implements I {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    45
    public void m1(int i) {}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    46
}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    47
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    48
class X {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    49
    public        void m1(int i) {}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    50
    public final  void f1(int i) {}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    51
    public static void s1(int i) {}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    52
}
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    53
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    54
public class LinkageErrors {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    55
    final static MethodHandles.Lookup L = MethodHandles.lookup();
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    56
51351
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    57
    static void testICCE(MethodHandle mh) {
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    58
        try {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    59
            mh.invokeExact();
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    60
            throw new AssertionError("No exception thrown");
51351
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    61
        } catch (IncompatibleClassChangeError e) {
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    62
            return; // expected
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    63
        } catch (AssertionError e) {
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    64
            throw e; // rethrow
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    65
        } catch (Throwable e) {
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    66
            throw new AssertionError("Unexpected exception", e);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    67
        }
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    68
    }
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    69
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    70
    static void testNSME(MethodHandle mh) {
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    71
        try {
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    72
            mh.invokeExact();
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    73
            throw new AssertionError("No exception thrown");
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
    74
        } catch (NoSuchMethodError e) {
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    75
            return; // expected
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    76
        } catch (AssertionError e) {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    77
            throw e; // rethrow
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    78
        } catch (Throwable e) {
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    79
            throw new AssertionError("Unexpected exception", e);
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    80
        }
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    81
    }
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    82
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    83
    public static void main(String args[]) throws Throwable {
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38132
diff changeset
    84
        Class<?> test = Class.forName("compiler.linkage.CallSites");
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    85
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    86
        // Non-existent method lookups.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    87
        MethodHandle testI1 = L.findStatic(test, "testI1", MethodType.methodType(void.class, I.class));
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    88
        MethodHandle testX1 = L.findStatic(test, "testX1", MethodType.methodType(void.class, X.class));
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    89
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    90
        MethodHandle testI1_A    = testI1.bindTo(new A());
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    91
        MethodHandle testI1_null = testI1.bindTo(null);
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    92
        MethodHandle testX1_X    = testX1.bindTo(new X());
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    93
        MethodHandle testX1_null = testX1.bindTo(null);
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    94
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    95
        // invokestatic of instance methods.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    96
        MethodHandle testI2 = L.findStatic(test, "testI2", MethodType.methodType(void.class));
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    97
        MethodHandle testX2 = L.findStatic(test, "testX2", MethodType.methodType(void.class));
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    98
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
    99
        MethodHandle testI3 = L.findStatic(test, "testI3", MethodType.methodType(void.class, I.class));
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   100
        MethodHandle testX3 = L.findStatic(test, "testX3", MethodType.methodType(void.class, X.class));
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   101
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   102
        // Virtual invocation of static methods.
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   103
        MethodHandle testI3_A    = testI3.bindTo(new A());
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   104
        MethodHandle testI3_null = testI3.bindTo(null);
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   105
        MethodHandle testX3_X    = testX3.bindTo(new X());
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   106
        MethodHandle testX3_null = testX3.bindTo(null);
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   107
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   108
        for (int i = 0; i < 20_000; i++) {
51351
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   109
            testNSME(testI1_A);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   110
            testNSME(testI1_null);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   111
            testNSME(testX1_X);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   112
            testNSME(testX1_null);
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   113
51351
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   114
            testICCE(testI2);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   115
            testICCE(testX2);
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   116
51351
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   117
            testICCE(testI3_A);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   118
            testICCE(testI3_null);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   119
            testICCE(testX3_X);
2bb9b1abadbf 8199081: [Testbug] compiler/linkage/LinkageErrors.java fails if run twice
iignatyev
parents: 47216
diff changeset
   120
            testICCE(testX3_null);
38132
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   121
        }
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   122
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   123
        System.out.println("TEST PASSED");
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   124
    }
ba888a4f352a 8154172: C1: NPE is thrown instead of linkage error when invoking nonexistent method
vlivanov
parents:
diff changeset
   125
}