test/hotspot/jtreg/runtime/LoaderConstraints/vtableAME/Test.java
author michaelm
Fri, 16 Feb 2018 10:34:17 +0000
branchhttp-client-branch
changeset 56137 dd867826d55b
parent 47554 bc112140e089
child 50036 e0dbf14885b8
permissions -rw-r--r--
http-client-branch: added system property to disable hostname verification for testing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47554
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     1
/*
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     4
 *
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     8
 *
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    13
 * accompanied this code).
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    14
 *
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    18
 *
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    21
 * questions.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    22
 */
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    23
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    24
/*
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    25
 * @test
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    26
 * @bug 8186092
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    27
 * @compile ../common/Foo.java
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    28
 *          ../common/J.java
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    29
 *          I.java
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    30
 *          ../common/C.jasm
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    31
 *          Task.java
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    32
 *          ../common/PreemptingClassLoader.java
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    33
 * @run main/othervm Test
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    34
 */
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    35
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    36
import java.io.PrintStream;
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    37
import java.lang.reflect.*;
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    38
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    39
public class Test {
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    40
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    41
    // Test that LinkageError exceptions are not thrown during vtable creation,
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    42
    // for loader constraint errors, if the target method is an overpass method.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    43
    //
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    44
    // In this test, during vtable creation for class Task, the target method
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    45
    // "Task.m()LFoo;" is an overpass method (that throws an AME).  So, even
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    46
    // though it is inheriting the method from its super class C, and Task has
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    47
    // a different class Foo than C, no LinkageError exception should be thrown
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    48
    // because the loader constraint check that would cause the LinkageError
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    49
    // should not be done.
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    50
    public static void main(String args[]) throws Exception {
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    51
        Class<?> c = Foo.class; // forces standard class loader to load Foo
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    52
        ClassLoader l = new PreemptingClassLoader("Task", "Foo", "I", "J");
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    53
        l.loadClass("Foo");
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    54
        l.loadClass("Task").newInstance();
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    55
        Task t = new Task();
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    56
        try {
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    57
            t.m(); // Should get AME
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    58
            throw new RuntimeException("Missing AbstractMethodError exception");
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    59
        } catch (AbstractMethodError e) {
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    60
            if (!e.getMessage().contains("Method Task.m()LFoo; is abstract")) {
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    61
                throw new RuntimeException("Wrong AME exception thrown: " + e.getMessage());
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    62
            }
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    63
        }
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    64
    }
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    65
bc112140e089 8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff changeset
    66
}