19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.corba ;
27
28 import java.lang.reflect.Field ;
29 import java.lang.reflect.Method ;
30 import java.lang.reflect.Constructor ;
31 import java.lang.reflect.InvocationTargetException ;
32
33 import java.io.ObjectInputStream ;
34
35 import java.security.AccessController;
36 import java.security.Permission;
37 import java.security.PrivilegedAction;
38
39 import sun.misc.Unsafe ;
40 import sun.reflect.ReflectionFactory ;
41
42 /** This class provides the methods for fundamental JVM operations
43 * needed in the ORB that are not part of the public Java API. This includes:
44 * <ul>
45 * <li>throwException, which can throw undeclared checked exceptions.
46 * This is needed to handle throwing arbitrary exceptions across a standardized OMG interface that (incorrectly) does not specify appropriate exceptions.</li>
47 * <li>putXXX/getXXX methods that allow unchecked access to fields of objects.
48 * This is used for setting uninitialzed non-static final fields (which is
49 * impossible with reflection) and for speed.</li>
50 * <li>objectFieldOffset to obtain the field offsets for use in the putXXX/getXXX methods</li>
51 * <li>newConstructorForSerialization to get the special constructor required for a
52 * Serializable class</li>
53 * <li>latestUserDefinedLoader to get the latest user defined class loader from
54 * the call stack as required by the RMI-IIOP specification (really from the
55 * JDK 1.1 days)</li>
56 * </ul>
57 * The code that calls Bridge.get() must have the following Permissions:
58 * <ul>
59 * <li>RuntimePermission "reflectionFactoryAccess"</li>
103 " latestUserDefinedLoader " + nsme );
104 err.initCause(nsme) ;
105 throw err ;
106 }
107
108 return result;
109 }
110 }
111 );
112 }
113
114 private Unsafe getUnsafe() {
115 Field fld = (Field)AccessController.doPrivileged(
116 new PrivilegedAction()
117 {
118 public Object run()
119 {
120 Field fld = null ;
121
122 try {
123 Class unsafeClass = sun.misc.Unsafe.class ;
124 fld = unsafeClass.getDeclaredField( "theUnsafe" ) ;
125 fld.setAccessible( true ) ;
126 return fld ;
127 } catch (NoSuchFieldException exc) {
128 Error err = new Error( "Could not access Unsafe" ) ;
129 err.initCause( exc ) ;
130 throw err ;
131 }
132 }
133 }
134 ) ;
135
136 Unsafe unsafe = null;
137
138 try {
139 unsafe = (Unsafe)(fld.get( null )) ;
140 } catch (Throwable t) {
141 Error err = new Error( "Could not access Unsafe" ) ;
142 err.initCause( t ) ;
143 throw err ;
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.corba ;
27
28 import java.lang.reflect.Field ;
29 import java.lang.reflect.Method ;
30 import java.lang.reflect.Constructor ;
31 import java.lang.reflect.InvocationTargetException ;
32
33 import java.io.ObjectInputStream ;
34
35 import java.security.AccessController;
36 import java.security.Permission;
37 import java.security.PrivilegedAction;
38
39 import jdk.internal.misc.Unsafe ;
40 import sun.reflect.ReflectionFactory ;
41
42 /** This class provides the methods for fundamental JVM operations
43 * needed in the ORB that are not part of the public Java API. This includes:
44 * <ul>
45 * <li>throwException, which can throw undeclared checked exceptions.
46 * This is needed to handle throwing arbitrary exceptions across a standardized OMG interface that (incorrectly) does not specify appropriate exceptions.</li>
47 * <li>putXXX/getXXX methods that allow unchecked access to fields of objects.
48 * This is used for setting uninitialzed non-static final fields (which is
49 * impossible with reflection) and for speed.</li>
50 * <li>objectFieldOffset to obtain the field offsets for use in the putXXX/getXXX methods</li>
51 * <li>newConstructorForSerialization to get the special constructor required for a
52 * Serializable class</li>
53 * <li>latestUserDefinedLoader to get the latest user defined class loader from
54 * the call stack as required by the RMI-IIOP specification (really from the
55 * JDK 1.1 days)</li>
56 * </ul>
57 * The code that calls Bridge.get() must have the following Permissions:
58 * <ul>
59 * <li>RuntimePermission "reflectionFactoryAccess"</li>
103 " latestUserDefinedLoader " + nsme );
104 err.initCause(nsme) ;
105 throw err ;
106 }
107
108 return result;
109 }
110 }
111 );
112 }
113
114 private Unsafe getUnsafe() {
115 Field fld = (Field)AccessController.doPrivileged(
116 new PrivilegedAction()
117 {
118 public Object run()
119 {
120 Field fld = null ;
121
122 try {
123 Class unsafeClass = jdk.internal.misc.Unsafe.class ;
124 fld = unsafeClass.getDeclaredField( "theUnsafe" ) ;
125 fld.setAccessible( true ) ;
126 return fld ;
127 } catch (NoSuchFieldException exc) {
128 Error err = new Error( "Could not access Unsafe" ) ;
129 err.initCause( exc ) ;
130 throw err ;
131 }
132 }
133 }
134 ) ;
135
136 Unsafe unsafe = null;
137
138 try {
139 unsafe = (Unsafe)(fld.get( null )) ;
140 } catch (Throwable t) {
141 Error err = new Error( "Could not access Unsafe" ) ;
142 err.initCause( t ) ;
143 throw err ;
|