src/java.base/share/classes/jdk/internal/access/JavaLangReflectAccess.java
author mchung
Tue, 23 Jul 2019 20:03:03 -0700
changeset 57503 042dfb697624
parent 52020 src/java.base/share/classes/jdk/internal/reflect/LangReflectAccess.java@4c247dde38ed
permissions -rw-r--r--
8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit> Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57503
042dfb697624 8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents: 52020
diff changeset
     2
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
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: 3959
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
57503
042dfb697624 8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents: 52020
diff changeset
    26
package jdk.internal.access;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.*;
57503
042dfb697624 8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents: 52020
diff changeset
    29
import jdk.internal.reflect.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/** An interface which gives privileged packages Java-level access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    internals of java.lang.reflect. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
57503
042dfb697624 8219774: Reexamine the initialization of LangReflectAccess shared secret at AccessibleObject::<clinit>
mchung
parents: 52020
diff changeset
    34
public interface JavaLangReflectAccess {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    /** Creates a new java.lang.reflect.Constructor. Access checks as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
      per java.lang.reflect.AccessibleObject are not overridden. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public <T> Constructor<T> newConstructor(Class<T> declaringClass,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    38
                                             Class<?>[] parameterTypes,
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    39
                                             Class<?>[] checkedExceptions,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                             int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                                             int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                                             String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                                             byte[] annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                                             byte[] parameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /** Gets the MethodAccessor object for a java.lang.reflect.Method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public MethodAccessor getMethodAccessor(Method m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /** Sets the MethodAccessor object for a java.lang.reflect.Method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public void setMethodAccessor(Method m, MethodAccessor accessor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /** Gets the ConstructorAccessor object for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        java.lang.reflect.Constructor */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    54
    public ConstructorAccessor getConstructorAccessor(Constructor<?> c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /** Sets the ConstructorAccessor object for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        java.lang.reflect.Constructor */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    58
    public void setConstructorAccessor(Constructor<?> c,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                       ConstructorAccessor accessor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
15510
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 5506
diff changeset
    61
    /** Gets the byte[] that encodes TypeAnnotations on an Executable. */
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 5506
diff changeset
    62
    public byte[] getExecutableTypeAnnotationBytes(Executable ex);
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 5506
diff changeset
    63
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /** Gets the "slot" field from a Constructor (used for serialization) */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    65
    public int getConstructorSlot(Constructor<?> c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /** Gets the "signature" field from a Constructor (used for serialization) */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    68
    public String getConstructorSignature(Constructor<?> c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /** Gets the "annotations" field from a Constructor (used for serialization) */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    71
    public byte[] getConstructorAnnotations(Constructor<?> c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    74
    public byte[] getConstructorParameterAnnotations(Constructor<?> c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
42997
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
    76
    /** Gets the shared array of parameter types of an Executable. */
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
    77
    public Class<?>[] getExecutableSharedParameterTypes(Executable ex);
5f83f2054eca 8172190: Re-apply the fix for bugs 8062389, 8029459, 8061950
plevart
parents: 42948
diff changeset
    78
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // Copying routines, needed to quickly fabricate new Field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // Method, and Constructor objects from templates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /** Makes a "child" copy of a Method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public Method      copyMethod(Method arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
32268
9fe7ee60d49d 8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents: 25859
diff changeset
    87
    /** Makes a copy of this non-root a Method */
9fe7ee60d49d 8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents: 25859
diff changeset
    88
    public Method      leafCopyMethod(Method arg);
9fe7ee60d49d 8073056: Repeating annotations throws java.security.AccessControlException with a SecurityManager
jfranck
parents: 25859
diff changeset
    89
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /** Makes a "child" copy of a Field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public Field       copyField(Field arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /** Makes a "child" copy of a Constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public <T> Constructor<T> copyConstructor(Constructor<T> arg);
50091
05979f6ba560 8202113: Reflection API is causing caller classes to leak
mchung
parents: 47216
diff changeset
    95
05979f6ba560 8202113: Reflection API is causing caller classes to leak
mchung
parents: 47216
diff changeset
    96
    /** Gets the root of the given AccessibleObject object; null if arg is the root */
05979f6ba560 8202113: Reflection API is causing caller classes to leak
mchung
parents: 47216
diff changeset
    97
    public <T extends AccessibleObject> T getRoot(T obj);
52020
4c247dde38ed 8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents: 50091
diff changeset
    98
4c247dde38ed 8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents: 50091
diff changeset
    99
    /** Returns a new instance created by the given constructor with access check */
4c247dde38ed 8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents: 50091
diff changeset
   100
    public <T> T newInstance(Constructor<T> ctor, Object[] args, Class<?> caller)
4c247dde38ed 8206240: java.lang.Class.newInstance() is causing caller to leak
mchung
parents: 50091
diff changeset
   101
        throws IllegalAccessException, InstantiationException, InvocationTargetException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}