jdk/src/share/classes/sun/reflect/package.html
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
<HTML>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
<HEAD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
<!--
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
</HEAD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
<BODY BGCOLOR="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
<B> Licensee impact of JDK 1.4 reflection changes </B>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
</P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
Sun's JDK 1.4 contains a new implementation of java.lang.reflect which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
offers substantially higher performance than previous JDKs' native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
code. Licensees can at their discretion port these changes. There are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
no public API or documentation changes associated with the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
reflection implementation aside from a few minor clarifications in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
specifications of Method.invoke(), Constructor.newInstance(), and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
few methods in java.lang.reflect.Field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
</P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
The bulk of the new implementation is Java programming language code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
which generates bytecodes, and is therefore portable. If licensees
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
desire to port it, the following JVM changes are required:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
<OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
<LI> The following four new JVM entry points must be added:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 <LI> JVM_GetClassDeclaredConstructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 <LI> JVM_GetClassDeclaredFields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 <LI> JVM_GetClassDeclaredMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 <LI> JVM_GetClassAccessFlags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
The first three return the declared constructors, fields, and methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
for a given class, with an option to return only the public ones. They
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
are similar in functionality to the earlier GetClassConstructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
GetClassFields, and GetClassMethods.  JVM_GetClassDeclaredFields and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
JVM_GetClassDeclaredMethods must intern the Strings for the names of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
the Field and Method objects returned. The fouth returns the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
flags for a given class as marked in the class file, as opposed to in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
the InnerClasses attribute if the class is an inner class, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
therefore differs from JVM_GetClassModifiers for inner classes (most
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
importantly, protected inner classes; see 4471811.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
<LI> The JVM's link resolver must be modified to allow all field and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
method references from subclasses of sun.reflect.MagicAccessorImpl to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
any other class (even to private members of other classes) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
succeed. This allows setAccessible() and its associated checks to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
implemented in Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
<LI> The code which calls the verifier must skip verification for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
subclasses of sun.reflect.MagicAccessorImpl. (It was originally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
intended that only a subset of the stub classes used for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
would not pass the verifier, specifically, those subclassing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
SerializationConstructorAccessorImpl; see 4486457 for a case where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
this does not work.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
<LI> The stack walker for security checks must be modified to skip not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
only all Method.invoke() frames, but also any frames for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
class is a subclass of sun.reflect.MethodAccessorImpl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
<LI> The JVM entry points JVM_InvokeMethod and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
JVM_NewInstanceFromConstructor are currently still used because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
first invocation of the bytecode-based reflection is currently slower
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
than the original native code. The security checks they perform can,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
however, be disabled, as they are now performed by Java programming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
language code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
</OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
</P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
The following changes were discovered to be necessary for backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
compatibility with certain applications (see bug 4474172):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
<OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
<LI> The existing JVM entry point JVM_LatestUserDefinedLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
(typically used in applications which rely on the 1.1 security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
framework) must skip reflection-related frames in its stack walk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
specifically all frames associated with subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
sun.reflect.MethodAccessorImpl and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
sun.reflect.ConstructorAccessorImpl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
<LI> The new reflection implementation can cause class loading to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
occur in previously-unexpected places (namely during reflective
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
calls).  This can cause class loaders which contain subtle bugs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
break.  In general it is not possible to guarantee complete backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
bug compatibility, but one kind of bug has been observed more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
once: the inability of a user-defined loader to handle delegation to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
it for a class it has already loaded. The new reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
implementation is predicated on delegation working properly, as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
loads stub classes into newly-fabricated class loaders of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
sun.reflect.DelegatingClassLoader, one stub class per loader, to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
unloading of the stub classes to occur more quickly. To handle this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
kind of bug, the JVM's internal class lookup mechanism must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
slightly modified to check for instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
sun.reflect.DelegatingClassLoader as the incoming class loader and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
silently traverse the "parent" field once for such loaders before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
entering the bulk of the resolution code. This avoids an upcall to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
Java programming language code which certain loaders can not handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
</OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
</P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
The following JVM entry points may be deleted:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
<UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
<LI> JVM_GetClassFields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
<LI> JVM_GetClassMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
<LI> JVM_GetClassConstructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
<LI> JVM_GetClassField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
<LI> JVM_GetClassMethod
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
<LI> JVM_GetClassConstructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
<LI> JVM_NewInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
<LI> JVM_GetField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
<LI> JVM_GetPrimitiveField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
<LI> JVM_SetField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
<LI> JVM_SetPrimitiveField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
</UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
</P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
To keep using the previous reflection implementation, licensees should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
not take changes from Sun's JDK 1.4 relating specifically to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
implementation of reflection in the following classes/methods and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
any associated native code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
<UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
<LI> java.lang.Class.newInstance0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
<LI> java.lang.Class.getClassLoader0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
<LI> java.lang.Class.getFields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
<LI> java.lang.Class.getMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
<LI> java.lang.Class.getDeclaredFields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
<LI> java.lang.Class.getDeclaredMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
<LI> java.lang.Class.getFields0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
<LI> java.lang.Class.getMethods0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
<LI> java.lang.Class.getConstructors0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
<LI> java.lang.Class.getField0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
<LI> java.lang.Class.getMethod0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
<LI> java.lang.Class.getConstructor0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
<LI> java.lang.ClassLoader.getCallerClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
<LI> java.lang.System.getCallerClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
<LI> java.lang.reflect.AccessibleObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
<LI> java.lang.reflect.Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
<LI> java.lang.reflect.Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
<LI> java.lang.reflect.Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
<LI> java.lang.reflect.Modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
<LI> sun.misc.ClassReflector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
</UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
</P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
</HTML>