test/hotspot/jtreg/runtime/InvocationTests/invokeinterface/Checker.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 55552 9bd13d6dea77
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55497
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     1
/*
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     2
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     4
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     8
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    13
 * accompanied this code).
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    14
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    18
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    21
 * questions.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    22
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    23
 */
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    24
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    25
package invokeinterface;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    26
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    27
import java.lang.reflect.Method;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    28
import java.lang.reflect.Modifier;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    29
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    30
public class Checker extends shared.Checker {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    31
    private Class interfaceClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    32
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    33
    public Checker(Class interfaceClass, Class dynamicTargetClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    34
        super(interfaceClass, dynamicTargetClass);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    35
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    36
        if (staticTargetClass.isInterface()) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    37
            this.interfaceClass = staticTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    38
        } else {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    39
            throw new RuntimeException("Static target class should be an interface.");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    40
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    41
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    42
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    43
    public String check (Class callerClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    44
        // Check access rights to interface for caller
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    45
        if (!checkAccess(interfaceClass, callerClass)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    46
            return "java.lang.IllegalAccessError";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    47
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    48
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    49
        // NSME is thrown when interface doesn't declare the method
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    50
        if (getDeclaredMethod(interfaceClass) == null) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    51
            return "java.lang.NoSuchMethodError";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    52
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    53
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    54
        // 9.1.5 Access to Interface Member Names
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    55
        // "All interface members are implicitly public. They are
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    56
        // accessible outside the package where the interface is
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    57
        // declared if the interface is also declared public or
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    58
        // protected, in accordance with the rules of 6.6."
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    59
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    60
        // Search for method declaration in the hierarchy
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    61
        Class klass = dynamicTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    62
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    63
        while (klass != Object.class) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    64
            Method method = getDeclaredMethod(klass);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    65
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    66
            if (method != null) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    67
                int modifiers = method.getModifiers();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    68
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    69
                // Check whether obtained method is public and isn't abstract
55552
9bd13d6dea77 8226956: Add invocation tests for Graal and C1
hseigel
parents: 55497
diff changeset
    70
                if ( Modifier.isPublic(modifiers)) {
55497
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    71
                    if (Modifier.isAbstract(modifiers)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    72
                        return "java.lang.AbstractMethodError";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    73
                    } else {
55552
9bd13d6dea77 8226956: Add invocation tests for Graal and C1
hseigel
parents: 55497
diff changeset
    74
                        return String.format("%s.%s",
9bd13d6dea77 8226956: Add invocation tests for Graal and C1
hseigel
parents: 55497
diff changeset
    75
                            method.getDeclaringClass().getSimpleName(),
9bd13d6dea77 8226956: Add invocation tests for Graal and C1
hseigel
parents: 55497
diff changeset
    76
                            methodName);
55497
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    77
                    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    78
                } else {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    79
                    // IAE is thrown when located method isn't PUBLIC
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    80
                    // or private.  Private methods are skipped when
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    81
                    // looking for an interface method.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    82
                    if (!Modifier.isPrivate(modifiers)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    83
                        return "java.lang.IllegalAccessError";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    84
                    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    85
                }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    86
            }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    87
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    88
            klass = klass.getSuperclass();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    89
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    90
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    91
        // No method declaration is found
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    92
        return "java.lang.AbstractMethodError";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    93
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    94
}