test/hotspot/jtreg/runtime/InvocationTests/shared/Checker.java
author hseigel
Wed, 26 Jun 2019 09:06:32 -0400
changeset 55497 d3a33953b936
permissions -rw-r--r--
8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo Summary: Add JTReg compatible main programs to run tests for various invoke* instructions Reviewed-by: lfoltan, coleenp
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 shared;
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 abstract class Checker {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    31
    protected Class staticTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    32
    protected Class dynamicTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    33
    protected String methodName;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    34
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    35
    public abstract String check (Class callSite);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    36
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    37
    public Checker(Class staticTargetClass, Class dynamicTargetClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    38
        if (!staticTargetClass.isAssignableFrom(dynamicTargetClass)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    39
            throw new RuntimeException("Dynamic target class should be a subclass of the static target class.");
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
        // NB!!! All classes are assumed to be PUBLIC !!!
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    44
        // **********************************************
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    45
        Class klass = dynamicTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    46
        while (klass != Object.class) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    47
            if (!Modifier.isPublic(klass.getModifiers())) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    48
                throw new AssertionError("Class "+klass.getName()+" isn't public.");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    49
            }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    50
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    51
            klass = klass.getSuperclass();
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
        this.methodName = Utils.TARGET_METHOD_NAME;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    55
        this.staticTargetClass = staticTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    56
        this.dynamicTargetClass = dynamicTargetClass;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    57
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    58
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    59
    protected Method getMethodInHierarchy (Class klass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    60
        return getMethodInHierarchy(klass, methodName);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    61
    }
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
    protected Method getMethodInHierarchy (Class klass, String name) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    64
        while (klass != null) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    65
            Method method = getDeclaredMethod (klass, name);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    66
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    67
            if ( method != null) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    68
// TODO: why doesn't this check work in VM?
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    69
//                int modifiers = method.getModifiers();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    70
//
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    71
//                if (Modifier.isPrivate(modifiers)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    72
//                    if (klass == initialClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    73
//                        return method;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    74
//                    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    75
//                } else {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    76
//                    return method;
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
                return method;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    79
            }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    80
            klass = klass.getSuperclass();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    81
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    82
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    83
        return null;
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
    protected Method getMethod (Class klass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    87
        return getMethod (klass, methodName);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    88
    }
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
    protected Method getDeclaredMethod (Class klass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    91
        return getDeclaredMethod (klass, methodName);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    92
    }
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
    static protected Method getMethod (Class klass, String name) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    95
        return findMethod (klass.getMethods(), name);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    96
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    97
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    98
    static protected Method getDeclaredMethod (Class klass, String name) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    99
        return findMethod (klass.getDeclaredMethods(), name);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   100
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   101
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   102
    static protected Method findMethod (Method[] methods, String name) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   103
        for (Method method : methods) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   104
            if (name.equals(method.getName())) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   105
                return method;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   106
            }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   107
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   108
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   109
        return null;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   110
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   111
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   112
    static public String getClassPackageName(Class klass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   113
        String name = klass.getName();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   114
        return getClassPackageName(name);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   115
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   116
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   117
    static public String getClassPackageName(String name) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   118
        int lastDotIndex = name.lastIndexOf('.');
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   119
        if (lastDotIndex > -1) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   120
            return name.substring(0, lastDotIndex);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   121
        } else {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   122
            return "";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   123
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   124
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   125
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   126
    public static String abbreviateResult(String result) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   127
        // Abbreviate exception names
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   128
        result = result.replaceAll("java.lang.NullPointerException", "NPE");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   129
        result = result.replaceAll("java.lang.IllegalAccessError", "IAE");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   130
        result = result.replaceAll("java.lang.IllegalAccessException", "IAExc");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   131
        result = result.replaceAll("java.lang.NoSuchMethodError", "NSME");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   132
        result = result.replaceAll("java.lang.AbstractMethodError", "AME");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   133
        result = result.replaceAll("java.lang.IncompatibleClassChangeError", "ICCE");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   134
        result = result.replaceAll("java.lang.VerifyError", "VE");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   135
        result = result.replaceAll("java.lang.ClassFormatError", "CFE");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   136
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   137
        return result;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   138
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   139
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   140
    // Check access possibility from particular call site
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   141
    protected boolean checkAccess(Class klass, Class callerClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   142
        int modifiers = klass.getModifiers();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   143
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   144
        return checkAccess(modifiers, klass, callerClass);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   145
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   146
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   147
    protected boolean checkAccess(Method m, Class callerClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   148
        int modifiers = m.getModifiers();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   149
        Class declaringClass = m.getDeclaringClass();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   150
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   151
        return checkAccess(modifiers, declaringClass, callerClass);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   152
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   153
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   154
    protected boolean checkAccess(int modifiers, Class klass, Class callerClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   155
        if ( Modifier.isPublic(modifiers) ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   156
            return true;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   157
        } else if ( Modifier.isProtected(modifiers) ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   158
            if (klass.isAssignableFrom(callerClass)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   159
                return true;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   160
            } else if (getClassPackageName(klass).equals(getClassPackageName(callerClass))) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   161
                return true;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   162
            }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   163
        } else if ( Modifier.isPrivate(modifiers)) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   164
            if (klass == callerClass) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   165
                return true;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   166
            }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   167
        } else if (getClassPackageName(klass).equals(getClassPackageName(callerClass))) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   168
            return true;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   169
        } else {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   170
            // if method isn't accessible, IllegalAccessException is thrown
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   171
            return false;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   172
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   173
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   174
        return false;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   175
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   176
}