corba/src/java.corba/share/classes/sun/corba/Bridge.java
author chegar
Wed, 11 Nov 2015 11:31:21 +0000
changeset 33680 56aa0b79bf5a
parent 25862 a5e25d68f971
child 37376 5daa5fbad3ce
permissions -rw-r--r--
8140606: Update library code to use internal Unsafe Reviewed-by: alanb, mchung, psandoz, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
7672
aec650969dd5 6962318: Update copyright year
ohair
parents: 5823
diff changeset
     2
 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package sun.corba ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.Field ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Constructor ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.InvocationTargetException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectInputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.security.Permission;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
33680
56aa0b79bf5a 8140606: Update library code to use internal Unsafe
chegar
parents: 25862
diff changeset
    39
import jdk.internal.misc.Unsafe ;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import sun.reflect.ReflectionFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
/** This class provides the methods for fundamental JVM operations
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
 * needed in the ORB that are not part of the public Java API.  This includes:
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 * <ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 * <li>throwException, which can throw undeclared checked exceptions.
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 * This is needed to handle throwing arbitrary exceptions across a standardized OMG interface that (incorrectly) does not specify appropriate exceptions.</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 * <li>putXXX/getXXX methods that allow unchecked access to fields of objects.
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 * This is used for setting uninitialzed non-static final fields (which is
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * impossible with reflection) and for speed.</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 * <li>objectFieldOffset to obtain the field offsets for use in the putXXX/getXXX methods</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * <li>newConstructorForSerialization to get the special constructor required for a
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * Serializable class</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * <li>latestUserDefinedLoader to get the latest user defined class loader from
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * the call stack as required by the RMI-IIOP specification (really from the
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * JDK 1.1 days)</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 * </ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * The code that calls Bridge.get() must have the following Permissions:
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 * <ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
 * <li>RuntimePermission "reflectionFactoryAccess"</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
 * <li>BridgePermission "getBridge"</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 * <li>ReflectPermission "suppressAccessChecks"</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
 * </ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
 * All of these permissions are required to obtain and correctly initialize
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
 * the instance of Bridge.  No security checks are performed on calls
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
 * made to Bridge instance methods, so access to the Bridge instance
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
 * must be protected.
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
 * This class is a singleton (per ClassLoader of course).  Access to the
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
 * instance is obtained through the Bridge.get() method.
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
public final class Bridge
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    private static final Class[] NO_ARGS = new Class[] {};
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    private static final Permission getBridgePermission =
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        new BridgePermission( "getBridge" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    private static Bridge bridge = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    // latestUserDefinedLoader() is a private static method
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    // in ObjectInputStream in JDK 1.3 through 1.5.
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    // We use reflection in a doPrivileged block to get a
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    // Method reference and make it accessible.
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    private final Method latestUserDefinedLoaderMethod ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    private final Unsafe unsafe ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    private final ReflectionFactory reflectionFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    private Method getLatestUserDefinedLoaderMethod()
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        return (Method) AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
            new PrivilegedAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
                public Object run()
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
                    Method result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
                        Class io = ObjectInputStream.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
                        result = io.getDeclaredMethod(
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
                            "latestUserDefinedLoader", NO_ARGS);
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
                        result.setAccessible(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
                    } catch (NoSuchMethodException nsme) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
                        Error err = new Error( "java.io.ObjectInputStream" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
                            " latestUserDefinedLoader " + nsme );
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
                        err.initCause(nsme) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
                        throw err ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
                    return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        );
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    private Unsafe getUnsafe() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        Field fld = (Field)AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
            new PrivilegedAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
                public Object run()
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
                {
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
                    Field fld = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                    try {
33680
56aa0b79bf5a 8140606: Update library code to use internal Unsafe
chegar
parents: 25862
diff changeset
   123
                        Class unsafeClass = jdk.internal.misc.Unsafe.class ;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                        fld = unsafeClass.getDeclaredField( "theUnsafe" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
                        fld.setAccessible( true ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
                        return fld ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                    } catch (NoSuchFieldException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                        Error err = new Error( "Could not access Unsafe" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
                        err.initCause( exc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
                        throw err ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        Unsafe unsafe = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
            unsafe = (Unsafe)(fld.get( null )) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            Error err = new Error( "Could not access Unsafe" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            err.initCause( t ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            throw err ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        return unsafe ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    private Bridge()
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        latestUserDefinedLoaderMethod = getLatestUserDefinedLoaderMethod();
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        unsafe = getUnsafe() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        reflectionFactory = (ReflectionFactory)AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
            new ReflectionFactory.GetReflectionFactoryAction());
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    /** Fetch the Bridge singleton.  This requires the following
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
     * permissions:
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * <ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * <li>RuntimePermission "reflectionFactoryAccess"</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     * <li>BridgePermission "getBridge"</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
     * <li>ReflectPermission "suppressAccessChecks"</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
     * </ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     * @return The singleton instance of the Bridge class
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
     * @throws SecurityException if the caller does not have the
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
     * required permissions and the caller has a non-null security manager.
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    public static final synchronized Bridge get()
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        SecurityManager sman = System.getSecurityManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        if (sman != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
            sman.checkPermission( getBridgePermission ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        if (bridge == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
            bridge = new Bridge() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        return bridge ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    /** Obtain the latest user defined ClassLoader from the call stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
     * This is required by the RMI-IIOP specification.
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    public final ClassLoader getLatestUserDefinedLoader()
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            // Invoke the ObjectInputStream.latestUserDefinedLoader method
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
            return (ClassLoader)latestUserDefinedLoaderMethod.invoke(null,
5823
3ed9d501bfd8 6960831: fix CORBA build warnings
jjg
parents: 5555
diff changeset
   190
                                                                     (Object[])NO_ARGS);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        } catch (InvocationTargetException ite) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
            Error err = new Error(
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                "sun.corba.Bridge.latestUserDefinedLoader: " + ite ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            err.initCause( ite ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
            throw err ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        } catch (IllegalAccessException iae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            Error err = new Error(
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                "sun.corba.Bridge.latestUserDefinedLoader: " + iae ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            err.initCause( iae ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            throw err ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     * Fetches a field element within the given
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
     * object <code>o</code> at the given offset.
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
     * The result is undefined unless the offset was obtained from
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
     * {@link #objectFieldOffset} on the {@link java.lang.reflect.Field}
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
     * of some Java field and the object referred to by <code>o</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
     * is of a class compatible with that field's class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
     * @param o Java heap object in which the field from which the offset
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
     * was obtained resides
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
     * @param offset indication of where the field resides in a Java heap
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
     *        object
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
     * @return the value fetched from the indicated Java field
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
     * @throws RuntimeException No defined exceptions are thrown, not even
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
     *         {@link NullPointerException}
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    public final int getInt(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        return unsafe.getInt( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
     * Stores a value into a given Java field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
     * The first two parameters are interpreted exactly as with
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
     * {@link #getInt(Object, long)} to refer to a specific
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
     * Java field.  The given value is stored into that field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
     * The field must be of the same type as the method
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
     * parameter <code>x</code>.
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
     * @param o Java heap object in which the field resides, if any, else
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
     *        null
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
     * @param offset indication of where the field resides in a Java heap
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
     *        object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
     * @param x the value to store into the indicated Java field
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
     * @throws RuntimeException No defined exceptions are thrown, not even
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
     *         {@link NullPointerException}
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    public final void putInt(Object o, long offset, int x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        unsafe.putInt( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
     * @see #getInt(Object, long)
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    public final Object getObject(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
        return unsafe.getObject( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
     * @see #putInt(Object, long, int)
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    public final void putObject(Object o, long offset, Object x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        unsafe.putObject( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    public final boolean getBoolean(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
        return unsafe.getBoolean( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
    public final void    putBoolean(Object o, long offset, boolean x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        unsafe.putBoolean( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    public final byte    getByte(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
        return unsafe.getByte( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    public final void    putByte(Object o, long offset, byte x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        unsafe.putByte( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    public final short   getShort(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        return unsafe.getShort( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
    public final void    putShort(Object o, long offset, short x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        unsafe.putShort( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    public final char    getChar(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        return unsafe.getChar( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    public final void    putChar(Object o, long offset, char x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        unsafe.putChar( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    public final long    getLong(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        return unsafe.getLong( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
    public final void    putLong(Object o, long offset, long x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        unsafe.putLong( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    public final float   getFloat(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        return unsafe.getFloat( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    public final void    putFloat(Object o, long offset, float x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
        unsafe.putFloat( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    /** @see #getInt(Object, long) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    public final double  getDouble(Object o, long offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        return unsafe.getDouble( o, offset ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    /** @see #putInt(Object, long, int) */
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
    public final void    putDouble(Object o, long offset, double x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        unsafe.putDouble( o, offset, x ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
     * This constant differs from all results that will ever be returned from
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
     * {@link #objectFieldOffset}.
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    public static final long INVALID_FIELD_OFFSET   = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
     * Returns the offset of a non-static field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    public final long objectFieldOffset(Field f)
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        return unsafe.objectFieldOffset( f ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    /** Throw the exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
     * The exception may be an undeclared checked exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    public final void throwException(Throwable ee)
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        unsafe.throwException( ee ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
    /** Obtain a constructor for Class cl using constructor cons which
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
     * may be the constructor defined in a superclass of cl.  This is
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
     * used to create a constructor for Serializable classes that
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
     * constructs an instance of the Serializable class using the
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
     * no args constructor of the first non-Serializable superclass
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
     * of the Serializable class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    public final Constructor newConstructorForSerialization( Class cl,
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
        Constructor cons )
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        return reflectionFactory.newConstructorForSerialization( cl, cons ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
}