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