< prev index next >

src/java.base/share/classes/jdk/internal/misc/Unsafe.java

Print this page
rev 55127 : 8223351: [lworld] Primary mirror and nullable mirror for inline type
Reviewed-by: tbd


 161      * {@link #getInt(Object, long)} to refer to a specific
 162      * Java variable (field or array element).  The given value
 163      * is stored into that variable.
 164      * <p>
 165      * The variable must be of the same type as the method
 166      * parameter {@code x}.
 167      *
 168      * @param o Java heap object in which the variable resides, if any, else
 169      *        null
 170      * @param offset indication of where the variable resides in a Java heap
 171      *        object, if any, else a memory address locating the variable
 172      *        statically
 173      * @param x the value to store into the indicated Java variable
 174      * @throws RuntimeException No defined exceptions are thrown, not even
 175      *         {@link NullPointerException}
 176      */
 177     @HotSpotIntrinsicCandidate
 178     public native void putInt(Object o, long offset, int x);
 179 
 180     /**
 181      * Returns true if the given class is a regular value type.
 182      */
 183     public boolean isValueType(Class<?> c) {
 184         return c.isValue() && c == c.asValueType();
 185     }
 186 
 187     private static final int JVM_ACC_FLATTENED = 0x00008000; // HotSpot-specific bit
 188 
 189     /**
 190      * Returns true if the given field is flattened.
 191      */
 192     public boolean isFlattened(Field f) {
 193         return (f.getModifiers() & JVM_ACC_FLATTENED) == JVM_ACC_FLATTENED;
 194     }
 195 
 196     /**
 197      * Returns true if the given class is a flattened array.
 198      */
 199     public native boolean isFlattenedArray(Class<?> arrayClass);
 200 
 201     /**
 202      * Fetches a reference value from a given Java variable.
 203      * This method can return a reference to either an object or value
 204      * or a null reference.


 217      * or matches the field type, the results are undefined.
 218      * If the reference {@code o} is non-null, card marks or
 219      * other store barriers for that object (if the VM requires them)
 220      * are updated.
 221      * @see #putInt(Object, long, int)
 222      */
 223     @HotSpotIntrinsicCandidate
 224     public native void putReference(Object o, long offset, Object x);
 225 
 226     /**
 227      * Fetches a value of type {@code <V>} from a given Java variable.
 228      * More specifically, fetches a field or array element within the given
 229      * {@code o} object at the given offset, or (if {@code o} is null)
 230      * from the memory address whose numerical value is the given offset.
 231      *
 232      * @param o Java heap object in which the variable resides, if any, else
 233      *        null
 234      * @param offset indication of where the variable resides in a Java heap
 235      *        object, if any, else a memory address locating the variable
 236      *        statically
 237      * @param vc value class
 238      * @param <V> the type of a value
 239      * @return the value fetched from the indicated Java variable
 240      * @throws RuntimeException No defined exceptions are thrown, not even
 241      *         {@link NullPointerException}
 242      */
 243     @HotSpotIntrinsicCandidate
 244     public native <V> V getValue(Object o, long offset, Class<?> vc);
 245 
 246     /**
 247      * Stores the given value into a given Java variable.
 248      *
 249      * Unless the reference {@code o} being stored is either null
 250      * or matches the field type, the results are undefined.
 251      *
 252      * @param o Java heap object in which the variable resides, if any, else
 253      *        null
 254      * @param offset indication of where the variable resides in a Java heap
 255      *        object, if any, else a memory address locating the variable
 256      *        statically
 257      * @param vc value class
 258      * @param v the value to store into the indicated Java variable
 259      * @param <V> the type of a value
 260      * @throws RuntimeException No defined exceptions are thrown, not even
 261      *         {@link NullPointerException}
 262      */
 263     @HotSpotIntrinsicCandidate
 264     public native <V> void putValue(Object o, long offset, Class<?> vc, V v);
 265 
 266     /**
 267      * Fetches a reference value of type {@code vc} from a given Java variable.
 268      * This method can return a reference to a value or a null reference
 269      * for a boxed value type.
 270      *
 271      * @param vc value class
 272      */
 273     public Object getReference(Object o, long offset, Class<?> vc) {
 274         Object ref = getReference(o, offset);
 275         if (ref == null && isValueType(vc)) {
 276             // If the type of the returned reference is a normal value type
 277             // return an uninitialized default value if null
 278             ref = uninitializedDefaultValue(vc);
 279         }
 280         return ref;
 281     }
 282 
 283     public Object getReferenceVolatile(Object o, long offset, Class<?> vc) {
 284         Object ref = getReferenceVolatile(o, offset);
 285         if (ref == null && isValueType(vc)) {
 286             // If the type of the returned reference is a normal value type
 287             // return an uninitialized default value if null
 288             ref = uninitializedDefaultValue(vc);
 289         }
 290         return ref;
 291     }
 292 
 293     /**
 294      * Returns an uninitialized default value of the given value class.
 295      */
 296     public native <V> V uninitializedDefaultValue(Class<?> vc);
 297 
 298     /**
 299      * Returns an object instance with a private buffered value whose layout
 300      * and contents is exactly the given value instance.  The return object
 301      * is in the larval state that can be updated using the unsafe put operation.
 302      *
 303      * @param value a value instance
 304      * @param <V> the type of the given value instance
 305      */
 306     @HotSpotIntrinsicCandidate
 307     public native <V> V makePrivateBuffer(V value);
 308 
 309     /**
 310      * Exits the larval state and returns a value instance.
 311      *
 312      * @param value a value instance
 313      * @param <V> the type of the given value instance
 314      */
 315     @HotSpotIntrinsicCandidate
 316     public native <V> V finishPrivateBuffer(V value);
 317 
 318     /**
 319      * Returns the header size of the given value class
 320      *
 321      * @param vc Value class
 322      * @param <V> value clas
 323      * @return the header size of the value class
 324      */
 325     public native <V> long valueHeaderSize(Class<V> vc);
 326 
 327     /** @see #getInt(Object, long) */
 328     @HotSpotIntrinsicCandidate
 329     public native boolean getBoolean(Object o, long offset);
 330 
 331     /** @see #putInt(Object, long, int) */
 332     @HotSpotIntrinsicCandidate
 333     public native void    putBoolean(Object o, long offset, boolean x);
 334 
 335     /** @see #getInt(Object, long) */
 336     @HotSpotIntrinsicCandidate
 337     public native byte    getByte(Object o, long offset);
 338 
 339     /** @see #putInt(Object, long, int) */
 340     @HotSpotIntrinsicCandidate
 341     public native void    putByte(Object o, long offset, byte x);
 342 
 343     /** @see #getInt(Object, long) */


2155                                                       long x) {
2156         return compareAndSetLong(o, offset, expected, x);
2157     }
2158 
2159     @HotSpotIntrinsicCandidate
2160     public final boolean weakCompareAndSetLong(Object o, long offset,
2161                                                long expected,
2162                                                long x) {
2163         return compareAndSetLong(o, offset, expected, x);
2164     }
2165 
2166     /**
2167      * Fetches a reference value from a given Java variable, with volatile
2168      * load semantics. Otherwise identical to {@link #getReference(Object, long)}
2169      */
2170     @HotSpotIntrinsicCandidate
2171     public native Object getReferenceVolatile(Object o, long offset);
2172 
2173     /**
2174      * Global lock for atomic and volatile strength access to any value of
2175      * a value type.  This is a temporary workaround until better localized
2176      * atomic access mechanisms are supported for value types.
2177      */
2178     private static final Object valueLock = new Object();
2179 
2180     public final <V> Object getValueVolatile(Object base, long offset, Class<?> valueType) {
2181         synchronized (valueLock) {
2182             return getValue(base, offset, valueType);
2183         }
2184     }
2185 
2186     /**
2187      * Stores a reference value into a given Java variable, with
2188      * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
2189      */
2190     @HotSpotIntrinsicCandidate
2191     public native void putReferenceVolatile(Object o, long offset, Object x);
2192 
2193     public final <V> void putValueVolatile(Object o, long offset, Class<?> valueType, V x) {
2194         synchronized (valueLock) {
2195             putValue(o, offset, valueType, x);
2196         }




 161      * {@link #getInt(Object, long)} to refer to a specific
 162      * Java variable (field or array element).  The given value
 163      * is stored into that variable.
 164      * <p>
 165      * The variable must be of the same type as the method
 166      * parameter {@code x}.
 167      *
 168      * @param o Java heap object in which the variable resides, if any, else
 169      *        null
 170      * @param offset indication of where the variable resides in a Java heap
 171      *        object, if any, else a memory address locating the variable
 172      *        statically
 173      * @param x the value to store into the indicated Java variable
 174      * @throws RuntimeException No defined exceptions are thrown, not even
 175      *         {@link NullPointerException}
 176      */
 177     @HotSpotIntrinsicCandidate
 178     public native void putInt(Object o, long offset, int x);
 179 
 180     /**
 181      * Returns true if the given class is a regular inline type.
 182      */
 183     public boolean isInlineType(Class<?> c) {
 184         return c.isInlineClass() && c == c.asPrimaryType();
 185     }
 186 
 187     private static final int JVM_ACC_FLATTENED = 0x00008000; // HotSpot-specific bit
 188 
 189     /**
 190      * Returns true if the given field is flattened.
 191      */
 192     public boolean isFlattened(Field f) {
 193         return (f.getModifiers() & JVM_ACC_FLATTENED) == JVM_ACC_FLATTENED;
 194     }
 195 
 196     /**
 197      * Returns true if the given class is a flattened array.
 198      */
 199     public native boolean isFlattenedArray(Class<?> arrayClass);
 200 
 201     /**
 202      * Fetches a reference value from a given Java variable.
 203      * This method can return a reference to either an object or value
 204      * or a null reference.


 217      * or matches the field type, the results are undefined.
 218      * If the reference {@code o} is non-null, card marks or
 219      * other store barriers for that object (if the VM requires them)
 220      * are updated.
 221      * @see #putInt(Object, long, int)
 222      */
 223     @HotSpotIntrinsicCandidate
 224     public native void putReference(Object o, long offset, Object x);
 225 
 226     /**
 227      * Fetches a value of type {@code <V>} from a given Java variable.
 228      * More specifically, fetches a field or array element within the given
 229      * {@code o} object at the given offset, or (if {@code o} is null)
 230      * from the memory address whose numerical value is the given offset.
 231      *
 232      * @param o Java heap object in which the variable resides, if any, else
 233      *        null
 234      * @param offset indication of where the variable resides in a Java heap
 235      *        object, if any, else a memory address locating the variable
 236      *        statically
 237      * @param vc inline class
 238      * @param <V> the type of a value
 239      * @return the value fetched from the indicated Java variable
 240      * @throws RuntimeException No defined exceptions are thrown, not even
 241      *         {@link NullPointerException}
 242      */
 243     @HotSpotIntrinsicCandidate
 244     public native <V> V getValue(Object o, long offset, Class<?> vc);
 245 
 246     /**
 247      * Stores the given value into a given Java variable.
 248      *
 249      * Unless the reference {@code o} being stored is either null
 250      * or matches the field type, the results are undefined.
 251      *
 252      * @param o Java heap object in which the variable resides, if any, else
 253      *        null
 254      * @param offset indication of where the variable resides in a Java heap
 255      *        object, if any, else a memory address locating the variable
 256      *        statically
 257      * @param vc inline class
 258      * @param v the value to store into the indicated Java variable
 259      * @param <V> the type of a value
 260      * @throws RuntimeException No defined exceptions are thrown, not even
 261      *         {@link NullPointerException}
 262      */
 263     @HotSpotIntrinsicCandidate
 264     public native <V> void putValue(Object o, long offset, Class<?> vc, V v);
 265 
 266     /**
 267      * Fetches a reference value of type {@code vc} from a given Java variable.
 268      * This method can return a reference to a value or a null reference
 269      * for a nullable-projection of an inline type.
 270      *
 271      * @param vc inline class
 272      */
 273     public Object getReference(Object o, long offset, Class<?> vc) {
 274         Object ref = getReference(o, offset);
 275         if (ref == null && isInlineType(vc)) {
 276             // If the type of the returned reference is a regular inline type
 277             // return an uninitialized default value if null
 278             ref = uninitializedDefaultValue(vc);
 279         }
 280         return ref;
 281     }
 282 
 283     public Object getReferenceVolatile(Object o, long offset, Class<?> vc) {
 284         Object ref = getReferenceVolatile(o, offset);
 285         if (ref == null && isInlineType(vc)) {
 286             // If the type of the returned reference is a regular inline type
 287             // return an uninitialized default value if null
 288             ref = uninitializedDefaultValue(vc);
 289         }
 290         return ref;
 291     }
 292 
 293     /**
 294      * Returns an uninitialized default value of the given inline class.
 295      */
 296     public native <V> V uninitializedDefaultValue(Class<?> vc);
 297 
 298     /**
 299      * Returns an object instance with a private buffered value whose layout
 300      * and contents is exactly the given value instance.  The return object
 301      * is in the larval state that can be updated using the unsafe put operation.
 302      *
 303      * @param value a value instance
 304      * @param <V> the type of the given value instance
 305      */
 306     @HotSpotIntrinsicCandidate
 307     public native <V> V makePrivateBuffer(V value);
 308 
 309     /**
 310      * Exits the larval state and returns a value instance.
 311      *
 312      * @param value a value instance
 313      * @param <V> the type of the given value instance
 314      */
 315     @HotSpotIntrinsicCandidate
 316     public native <V> V finishPrivateBuffer(V value);
 317 
 318     /**
 319      * Returns the header size of the given inline class
 320      *
 321      * @param vc inline class
 322      * @param <V> value clas
 323      * @return the header size of the inline class
 324      */
 325     public native <V> long valueHeaderSize(Class<V> vc);
 326 
 327     /** @see #getInt(Object, long) */
 328     @HotSpotIntrinsicCandidate
 329     public native boolean getBoolean(Object o, long offset);
 330 
 331     /** @see #putInt(Object, long, int) */
 332     @HotSpotIntrinsicCandidate
 333     public native void    putBoolean(Object o, long offset, boolean x);
 334 
 335     /** @see #getInt(Object, long) */
 336     @HotSpotIntrinsicCandidate
 337     public native byte    getByte(Object o, long offset);
 338 
 339     /** @see #putInt(Object, long, int) */
 340     @HotSpotIntrinsicCandidate
 341     public native void    putByte(Object o, long offset, byte x);
 342 
 343     /** @see #getInt(Object, long) */


2155                                                       long x) {
2156         return compareAndSetLong(o, offset, expected, x);
2157     }
2158 
2159     @HotSpotIntrinsicCandidate
2160     public final boolean weakCompareAndSetLong(Object o, long offset,
2161                                                long expected,
2162                                                long x) {
2163         return compareAndSetLong(o, offset, expected, x);
2164     }
2165 
2166     /**
2167      * Fetches a reference value from a given Java variable, with volatile
2168      * load semantics. Otherwise identical to {@link #getReference(Object, long)}
2169      */
2170     @HotSpotIntrinsicCandidate
2171     public native Object getReferenceVolatile(Object o, long offset);
2172 
2173     /**
2174      * Global lock for atomic and volatile strength access to any value of
2175      * an inline type.  This is a temporary workaround until better localized
2176      * atomic access mechanisms are supported for inline types.
2177      */
2178     private static final Object valueLock = new Object();
2179 
2180     public final <V> Object getValueVolatile(Object base, long offset, Class<?> valueType) {
2181         synchronized (valueLock) {
2182             return getValue(base, offset, valueType);
2183         }
2184     }
2185 
2186     /**
2187      * Stores a reference value into a given Java variable, with
2188      * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
2189      */
2190     @HotSpotIntrinsicCandidate
2191     public native void putReferenceVolatile(Object o, long offset, Object x);
2192 
2193     public final <V> void putValueVolatile(Object o, long offset, Class<?> valueType, V x) {
2194         synchronized (valueLock) {
2195             putValue(o, offset, valueType, x);
2196         }


< prev index next >