• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
39Sun's JDK 1.4 contains a new implementation of java.lang.reflect which
40offers substantially higher performance than previous JDKs' native
41code. Licensees can at their discretion port these changes. There are
42no public API or documentation changes associated with the new
43reflection implementation aside from a few minor clarifications in the
44specifications of Method.invoke(), Constructor.newInstance(), and a
45few methods in java.lang.reflect.Field.
46
47</P>
48<P>
49
50The bulk of the new implementation is Java programming language code
51which generates bytecodes, and is therefore portable. If licensees
52desire 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
64The first three return the declared constructors, fields, and methods
65for a given class, with an option to return only the public ones. They
66are similar in functionality to the earlier GetClassConstructors,
67GetClassFields, and GetClassMethods.  JVM_GetClassDeclaredFields and
68JVM_GetClassDeclaredMethods must intern the Strings for the names of
69the Field and Method objects returned. The fouth returns the access
70flags for a given class as marked in the class file, as opposed to in
71the InnerClasses attribute if the class is an inner class, and
72therefore differs from JVM_GetClassModifiers for inner classes (most
73importantly, protected inner classes; see 4471811.)
74
75<LI> The JVM's link resolver must be modified to allow all field and
76method references from subclasses of sun.reflect.MagicAccessorImpl to
77any other class (even to private members of other classes) to
78succeed. This allows setAccessible() and its associated checks to be
79implemented in Java.
80
81<LI> The code which calls the verifier must skip verification for all
82subclasses of sun.reflect.MagicAccessorImpl. (It was originally
83intended that only a subset of the stub classes used for serialization
84would not pass the verifier, specifically, those subclassing
85SerializationConstructorAccessorImpl; see 4486457 for a case where
86this does not work.)
87
88<LI> The stack walker for security checks must be modified to skip not
89only all Method.invoke() frames, but also any frames for which the
90class is a subclass of sun.reflect.MethodAccessorImpl.
91
92<LI> The JVM entry points JVM_InvokeMethod and
93JVM_NewInstanceFromConstructor are currently still used because the
94first invocation of the bytecode-based reflection is currently slower
95than the original native code. The security checks they perform can,
96however, be disabled, as they are now performed by Java programming
97language code.
98
99</OL>
100
101</P>
102<P>
103
104The following changes were discovered to be necessary for backward
105compatibility 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
111framework) must skip reflection-related frames in its stack walk:
112specifically all frames associated with subclasses of
113sun.reflect.MethodAccessorImpl and
114sun.reflect.ConstructorAccessorImpl.
115
116<LI> The new reflection implementation can cause class loading to
117occur in previously-unexpected places (namely during reflective
118calls).  This can cause class loaders which contain subtle bugs to
119break.  In general it is not possible to guarantee complete backward
120bug compatibility, but one kind of bug has been observed more than
121once: the inability of a user-defined loader to handle delegation to
122it for a class it has already loaded. The new reflection
123implementation is predicated on delegation working properly, as it
124loads stub classes into newly-fabricated class loaders of type
125sun.reflect.DelegatingClassLoader, one stub class per loader, to allow
126unloading of the stub classes to occur more quickly. To handle this
127kind of bug, the JVM's internal class lookup mechanism must be
128slightly modified to check for instances of
129sun.reflect.DelegatingClassLoader as the incoming class loader and
130silently traverse the "parent" field once for such loaders before
131entering the bulk of the resolution code. This avoids an upcall to
132Java programming language code which certain loaders can not handle.
133
134</OL>
135
136</P>
137<P>
138
139The 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
158To keep using the previous reflection implementation, licensees should
159not take changes from Sun's JDK 1.4 relating specifically to the
160implementation of reflection in the following classes/methods and
161any 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