jdk/src/share/classes/sun/invoke/util/VerifyAccess.java
author twisti
Tue, 24 Jul 2012 10:47:44 -0700
changeset 13423 17843fff200d
parent 13044 8411854afc2b
child 14342 8435a30053c1
permissions -rw-r--r--
7023639: JSR 292 method handle invocation needs a fast path for compiled code 6984705: JSR 292 method handle creation should not go through JNI Summary: remove assembly code for JDK 7 chained method handles Reviewed-by: jrose, twisti, mhaupt, forax Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     1
/*
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     4
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    10
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    15
 * accompanied this code).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    16
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    23
 * questions.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    24
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    25
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    26
package sun.invoke.util;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    28
import java.lang.reflect.Modifier;
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    29
import static java.lang.reflect.Modifier.*;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    30
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    31
/**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    32
 * This class centralizes information about the JVM's linkage access control.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    33
 * @author jrose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    34
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    35
public class VerifyAccess {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    36
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    37
    private VerifyAccess() { }  // cannot instantiate
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    38
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    39
    private static final int PACKAGE_ONLY = 0;
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    40
    private static final int PACKAGE_ALLOWED = java.lang.invoke.MethodHandles.Lookup.PACKAGE;
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    41
    private static final int PROTECTED_OR_PACKAGE_ALLOWED = (PACKAGE_ALLOWED|PROTECTED);
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    42
    private static final int ALL_ACCESS_MODES = (PUBLIC|PRIVATE|PROTECTED|PACKAGE_ONLY);
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 5725
diff changeset
    43
    private static final boolean ALLOW_NESTMATE_ACCESS = false;
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    44
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    45
    /**
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    46
     * Evaluate the JVM linkage rules for access to the given method
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    47
     * on behalf of a caller class which proposes to perform the access.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    48
     * Return true if the caller class has privileges to invoke a method
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    49
     * or access a field with the given properties.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    50
     * This requires an accessibility check of the referencing class,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    51
     * plus an accessibility check of the member within the class,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    52
     * which depends on the member's modifier flags.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    53
     * <p>
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    54
     * The relevant properties include the defining class ({@code defc})
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    55
     * of the member, and its modifier flags ({@code mods}).
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    56
     * Also relevant is the class used to make the initial symbolic reference
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    57
     * to the member ({@code refc}).  If this latter class is not distinguished,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    58
     * the defining class should be passed for both arguments ({@code defc == refc}).
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    59
     * <h3>JVM Specification, 5.4.4 "Access Control"</h3>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    60
     * A field or method R is accessible to a class or interface D if
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    61
     * and only if any of the following conditions is true:<ul>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    62
     * <li>R is public.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    63
     * <li>R is protected and is declared in a class C, and D is either
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    64
     *     a subclass of C or C itself.  Furthermore, if R is not
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    65
     *     static, then the symbolic reference to R must contain a
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    66
     *     symbolic reference to a class T, such that T is either a
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    67
     *     subclass of D, a superclass of D or D itself.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    68
     * <li>R is either protected or has default access (that is,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    69
     *     neither public nor protected nor private), and is declared
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    70
     *     by a class in the same runtime package as D.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    71
     * <li>R is private and is declared in D.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    72
     * </ul>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    73
     * This discussion of access control omits a related restriction
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    74
     * on the target of a protected field access or method invocation
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    75
     * (the target must be of class D or a subtype of D). That
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    76
     * requirement is checked as part of the verification process
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    77
     * (5.4.1); it is not part of link-time access control.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    78
     * @param refc the class used in the symbolic reference to the proposed member
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    79
     * @param defc the class in which the proposed member is actually defined
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    80
     * @param mods modifier flags for the proposed member
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    81
     * @param lookupClass the class for which the access check is being made
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    82
     * @return true iff the the accessing class can access such a member
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    83
     */
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    84
    public static boolean isMemberAccessible(Class<?> refc,  // symbolic ref class
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    85
                                             Class<?> defc,  // actual def class
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    86
                                             int      mods,  // actual member mods
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    87
                                             Class<?> lookupClass,
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    88
                                             int      allowedModes) {
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    89
        if (allowedModes == 0)  return false;
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    90
        assert((allowedModes & PUBLIC) != 0 &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    91
               (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED)) == 0);
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    92
        // Usually refc and defc are the same, but if they differ, verify them both.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    93
        if (refc != defc) {
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    94
            if (!isClassAccessible(refc, lookupClass, allowedModes)) {
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    95
                // Note that defc is verified in the switch below.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    96
                return false;
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    97
            }
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    98
            if ((mods & (ALL_ACCESS_MODES|STATIC)) == (PROTECTED|STATIC) &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
    99
                (allowedModes & PROTECTED_OR_PACKAGE_ALLOWED) != 0) {
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   100
                // Apply the special rules for refc here.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   101
                if (!isRelatedClass(refc, lookupClass))
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   102
                    return isSamePackage(defc, lookupClass);
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   103
                // If refc == defc, the call to isPublicSuperClass will do
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   104
                // the whole job, since in that case refc (as defc) will be
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   105
                // a superclass of the lookup class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   106
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   107
        }
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   108
        if (defc == lookupClass &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   109
            (allowedModes & PRIVATE) != 0)
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 5725
diff changeset
   110
            return true;        // easy check; all self-access is OK
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   111
        switch (mods & ALL_ACCESS_MODES) {
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   112
        case PUBLIC:
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   113
            if (refc != defc)  return true;  // already checked above
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   114
            return isClassAccessible(refc, lookupClass, allowedModes);
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   115
        case PROTECTED:
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   116
            if ((allowedModes & PROTECTED_OR_PACKAGE_ALLOWED) != 0 &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   117
                isSamePackage(defc, lookupClass))
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   118
                return true;
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   119
            if ((allowedModes & PROTECTED) != 0 &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   120
                isPublicSuperClass(defc, lookupClass))
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   121
                return true;
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   122
            return false;
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   123
        case PACKAGE_ONLY:  // That is, zero.  Unmarked member is package-only access.
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   124
            return ((allowedModes & PACKAGE_ALLOWED) != 0 &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   125
                    isSamePackage(defc, lookupClass));
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   126
        case PRIVATE:
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   127
            // Loosened rules for privates follows access rules for inner classes.
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 5725
diff changeset
   128
            return (ALLOW_NESTMATE_ACCESS &&
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   129
                    (allowedModes & PRIVATE) != 0 &&
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 5725
diff changeset
   130
                    isSamePackageMember(defc, lookupClass));
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   131
        default:
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   132
            throw new IllegalArgumentException("bad modifiers: "+Modifier.toString(mods));
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   133
        }
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   134
    }
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   135
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   136
    static boolean isRelatedClass(Class<?> refc, Class<?> lookupClass) {
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   137
        return (refc == lookupClass ||
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   138
                refc.isAssignableFrom(lookupClass) ||
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   139
                lookupClass.isAssignableFrom(refc));
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   140
    }
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   141
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   142
    static boolean isPublicSuperClass(Class<?> defc, Class<?> lookupClass) {
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   143
        return isPublic(defc.getModifiers()) && defc.isAssignableFrom(lookupClass);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   144
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   145
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   146
    /**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   147
     * Evaluate the JVM linkage rules for access to the given class on behalf of caller.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   148
     * <h3>JVM Specification, 5.4.4 "Access Control"</h3>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   149
     * A class or interface C is accessible to a class or interface D
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   150
     * if and only if either of the following conditions are true:<ul>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   151
     * <li>C is public.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   152
     * <li>C and D are members of the same runtime package.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   153
     * </ul>
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7668
diff changeset
   154
     * @param refc the symbolic reference class to which access is being checked (C)
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7668
diff changeset
   155
     * @param lookupClass the class performing the lookup (D)
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   156
     */
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   157
    public static boolean isClassAccessible(Class<?> refc, Class<?> lookupClass,
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   158
                                            int allowedModes) {
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   159
        if (allowedModes == 0)  return false;
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   160
        assert((allowedModes & PUBLIC) != 0 &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   161
               (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED)) == 0);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   162
        int mods = refc.getModifiers();
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   163
        if (isPublic(mods))
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   164
            return true;
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   165
        if ((allowedModes & PACKAGE_ALLOWED) != 0 &&
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   166
            isSamePackage(lookupClass, refc))
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   167
            return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   168
        return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   169
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   170
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   171
    /**
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   172
     * Decide if the given method type, attributed to a member or symbolic
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   173
     * reference of a given reference class, is really visible to that class.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   174
     * @param type the supposed type of a member or symbolic reference of refc
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   175
     * @param refc
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   176
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   177
    public static boolean isTypeVisible(Class<?> type, Class<?> refc) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   178
        if (type == refc)  return true;  // easy check
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   179
        while (type.isArray())  type = type.getComponentType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   180
        if (type.isPrimitive() || type == Object.class)  return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   181
        ClassLoader parent = type.getClassLoader();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   182
        if (parent == null)  return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   183
        ClassLoader child  = refc.getClassLoader();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   184
        if (child == null)  return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   185
        if (parent == child || loadersAreRelated(parent, child, true))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   186
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   187
        // Do it the hard way:  Look up the type name from the refc loader.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   188
        try {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   189
            Class<?> res = child.loadClass(type.getName());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   190
            return (type == res);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   191
        } catch (ClassNotFoundException ex) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   192
            return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   193
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   194
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   195
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   196
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   197
     * Decide if the given method type, attributed to a member or symbolic
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   198
     * reference of a given reference class, is really visible to that class.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   199
     * @param type the supposed type of a member or symbolic reference of refc
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   200
     * @param refc
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   201
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   202
    public static boolean isTypeVisible(java.lang.invoke.MethodType type, Class<?> refc) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   203
        for (int n = -1, max = type.parameterCount(); n < max; n++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   204
            Class<?> ptype = (n < 0 ? type.returnType() : type.parameterType(n));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   205
            if (!isTypeVisible(ptype, refc))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   206
                return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   207
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   208
        return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   209
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   210
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13044
diff changeset
   211
    /**
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   212
     * Test if two classes have the same class loader and package qualifier.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   213
     * @param class1
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   214
     * @param class2
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   215
     * @return whether they are in the same package
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   216
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   217
    public static boolean isSamePackage(Class<?> class1, Class<?> class2) {
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   218
        assert(!class1.isArray() && !class2.isArray());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   219
        if (class1 == class2)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   220
            return true;
13044
8411854afc2b 7165628: Issues with java.lang.invoke.MethodHandles.Lookup
jrose
parents: 9752
diff changeset
   221
        if (class1.getClassLoader() != class2.getClassLoader())
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   222
            return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   223
        String name1 = class1.getName(), name2 = class2.getName();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   224
        int dot = name1.lastIndexOf('.');
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   225
        if (dot != name2.lastIndexOf('.'))
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   226
            return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   227
        for (int i = 0; i < dot; i++) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   228
            if (name1.charAt(i) != name2.charAt(i))
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   229
                return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   230
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   231
        return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   232
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   233
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   234
    /** Return the package name for this class.
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   235
     */
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   236
    public static String getPackageName(Class<?> cls) {
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   237
        assert(!cls.isArray());
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   238
        String name = cls.getName();
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   239
        int dot = name.lastIndexOf('.');
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   240
        if (dot < 0)  return "";
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   241
        return name.substring(0, dot);
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   242
    }
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   243
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   244
    /**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   245
     * Test if two classes are defined as part of the same package member (top-level class).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   246
     * If this is true, they can share private access with each other.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   247
     * @param class1
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   248
     * @param class2
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   249
     * @return whether they are identical or nested together
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   250
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   251
    public static boolean isSamePackageMember(Class<?> class1, Class<?> class2) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   252
        if (class1 == class2)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   253
            return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   254
        if (!isSamePackage(class1, class2))
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   255
            return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   256
        if (getOutermostEnclosingClass(class1) != getOutermostEnclosingClass(class2))
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   257
            return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   258
        return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   259
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   260
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   261
    private static Class<?> getOutermostEnclosingClass(Class<?> c) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   262
        Class<?> pkgmem = c;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   263
        for (Class<?> enc = c; (enc = enc.getEnclosingClass()) != null; )
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   264
            pkgmem = enc;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   265
        return pkgmem;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   266
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   267
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   268
    private static boolean loadersAreRelated(ClassLoader loader1, ClassLoader loader2,
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   269
                                             boolean loader1MustBeParent) {
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   270
        if (loader1 == loader2 || loader1 == null
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   271
                || (loader2 == null && !loader1MustBeParent)) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   272
            return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   273
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   274
        for (ClassLoader scan2 = loader2;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   275
                scan2 != null; scan2 = scan2.getParent()) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   276
            if (scan2 == loader1)  return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   277
        }
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   278
        if (loader1MustBeParent)  return false;
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   279
        // see if loader2 is a parent of loader1:
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   280
        for (ClassLoader scan1 = loader1;
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   281
                scan1 != null; scan1 = scan1.getParent()) {
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   282
            if (scan1 == loader2)  return true;
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   283
        }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   284
        return false;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   285
    }
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   286
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   287
    /**
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   288
     * Is the class loader of parentClass identical to, or an ancestor of,
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   289
     * the class loader of childClass?
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   290
     * @param parentClass
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   291
     * @param childClass
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   292
     * @return whether parentClass precedes or equals childClass in class loader order
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   293
     */
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   294
    public static boolean classLoaderIsAncestor(Class<?> parentClass, Class<?> childClass) {
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   295
        return loadersAreRelated(parentClass.getClassLoader(), childClass.getClassLoader(), true);
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 8822
diff changeset
   296
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   297
}