author | stuefe |
Thu, 10 May 2018 07:26:18 +0200 | |
changeset 50074 | 26ac622a4cab |
parent 49267 | 6889f13694c6 |
child 51798 | f55a4bc91ef4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49267
6889f13694c6
8193033: remove terminally deprecated sun.misc.Unsafe.defineClass
psandoz
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.misc; |
|
27 |
||
36628 | 28 |
import jdk.internal.vm.annotation.ForceInline; |
35271 | 29 |
import jdk.internal.misc.VM; |
42707 | 30 |
import jdk.internal.ref.Cleaner; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36966
diff
changeset
|
31 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36966
diff
changeset
|
32 |
import jdk.internal.reflect.Reflection; |
42707 | 33 |
import sun.nio.ch.DirectBuffer; |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14853
diff
changeset
|
34 |
|
35253
ed92ce9fac46
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33656
diff
changeset
|
35 |
import java.lang.reflect.Field; |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
30655
diff
changeset
|
36 |
|
2 | 37 |
|
38 |
/** |
|
39 |
* A collection of methods for performing low-level, unsafe operations. |
|
40 |
* Although the class and all methods are public, use of this class is |
|
41 |
* limited because only trusted code can obtain instances of it. |
|
42 |
* |
|
36628 | 43 |
* <em>Note:</em> It is the resposibility of the caller to make sure |
44 |
* arguments are checked before methods of this class are |
|
45 |
* called. While some rudimentary checks are performed on the input, |
|
46 |
* the checks are best effort and when performance is an overriding |
|
47 |
* priority, as when methods of this class are optimized by the |
|
48 |
* runtime compiler, some or all checks (if any) may be elided. Hence, |
|
49 |
* the caller must not rely on the checks and corresponding |
|
50 |
* exceptions! |
|
51 |
* |
|
2 | 52 |
* @author John R. Rose |
53 |
* @see #getUnsafe |
|
54 |
*/ |
|
55 |
||
56 |
public final class Unsafe { |
|
57 |
||
58 |
static { |
|
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36966
diff
changeset
|
59 |
Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe"); |
2 | 60 |
} |
61 |
||
62 |
private Unsafe() {} |
|
63 |
||
64 |
private static final Unsafe theUnsafe = new Unsafe(); |
|
36628 | 65 |
private static final jdk.internal.misc.Unsafe theInternalUnsafe = jdk.internal.misc.Unsafe.getUnsafe(); |
2 | 66 |
|
67 |
/** |
|
68 |
* Provides the caller with the capability of performing unsafe |
|
69 |
* operations. |
|
70 |
* |
|
29388 | 71 |
* <p>The returned {@code Unsafe} object should be carefully guarded |
2 | 72 |
* by the caller, since it can be used to read and write data at arbitrary |
73 |
* memory addresses. It must never be passed to untrusted code. |
|
74 |
* |
|
29388 | 75 |
* <p>Most methods in this class are very low-level, and correspond to a |
2 | 76 |
* small number of hardware instructions (on typical machines). Compilers |
77 |
* are encouraged to optimize these methods accordingly. |
|
78 |
* |
|
29388 | 79 |
* <p>Here is a suggested idiom for using unsafe operations: |
2 | 80 |
* |
29388 | 81 |
* <pre> {@code |
2 | 82 |
* class MyTrustedClass { |
83 |
* private static final Unsafe unsafe = Unsafe.getUnsafe(); |
|
84 |
* ... |
|
85 |
* private long myCountAddress = ...; |
|
86 |
* public int getCount() { return unsafe.getByte(myCountAddress); } |
|
29388 | 87 |
* }}</pre> |
88 |
* |
|
89 |
* (It may assist compilers to make the local variable {@code final}.) |
|
2 | 90 |
* |
38774 | 91 |
* @throws SecurityException if the class loader of the caller |
92 |
* class is not in the system domain in which all permissions |
|
93 |
* are granted. |
|
2 | 94 |
*/ |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14853
diff
changeset
|
95 |
@CallerSensitive |
2 | 96 |
public static Unsafe getUnsafe() { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14853
diff
changeset
|
97 |
Class<?> caller = Reflection.getCallerClass(); |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14853
diff
changeset
|
98 |
if (!VM.isSystemDomainLoader(caller.getClassLoader())) |
2 | 99 |
throw new SecurityException("Unsafe"); |
100 |
return theUnsafe; |
|
101 |
} |
|
102 |
||
103 |
/// peek and poke operations |
|
104 |
/// (compilers should optimize these to memory ops) |
|
105 |
||
106 |
// These work on object fields in the Java heap. |
|
107 |
// They will not work on elements of packed arrays. |
|
108 |
||
109 |
/** |
|
110 |
* Fetches a value from a given Java variable. |
|
111 |
* More specifically, fetches a field or array element within the given |
|
29388 | 112 |
* object {@code o} at the given offset, or (if {@code o} is null) |
113 |
* from the memory address whose numerical value is the given offset. |
|
2 | 114 |
* <p> |
115 |
* The results are undefined unless one of the following cases is true: |
|
116 |
* <ul> |
|
117 |
* <li>The offset was obtained from {@link #objectFieldOffset} on |
|
118 |
* the {@link java.lang.reflect.Field} of some Java field and the object |
|
29388 | 119 |
* referred to by {@code o} is of a class compatible with that |
2 | 120 |
* field's class. |
121 |
* |
|
29388 | 122 |
* <li>The offset and object reference {@code o} (either null or |
2 | 123 |
* non-null) were both obtained via {@link #staticFieldOffset} |
124 |
* and {@link #staticFieldBase} (respectively) from the |
|
125 |
* reflective {@link Field} representation of some Java field. |
|
126 |
* |
|
29388 | 127 |
* <li>The object referred to by {@code o} is an array, and the offset |
128 |
* is an integer of the form {@code B+N*S}, where {@code N} is |
|
129 |
* a valid index into the array, and {@code B} and {@code S} are |
|
2 | 130 |
* the values obtained by {@link #arrayBaseOffset} and {@link |
131 |
* #arrayIndexScale} (respectively) from the array's class. The value |
|
29388 | 132 |
* referred to is the {@code N}<em>th</em> element of the array. |
2 | 133 |
* |
134 |
* </ul> |
|
135 |
* <p> |
|
136 |
* If one of the above cases is true, the call references a specific Java |
|
137 |
* variable (field or array element). However, the results are undefined |
|
138 |
* if that variable is not in fact of the type returned by this method. |
|
139 |
* <p> |
|
140 |
* This method refers to a variable by means of two parameters, and so |
|
141 |
* it provides (in effect) a <em>double-register</em> addressing mode |
|
142 |
* for Java variables. When the object reference is null, this method |
|
143 |
* uses its offset as an absolute address. This is similar in operation |
|
144 |
* to methods such as {@link #getInt(long)}, which provide (in effect) a |
|
145 |
* <em>single-register</em> addressing mode for non-Java variables. |
|
146 |
* However, because Java variables may have a different layout in memory |
|
147 |
* from non-Java variables, programmers should not assume that these |
|
148 |
* two addressing modes are ever equivalent. Also, programmers should |
|
149 |
* remember that offsets from the double-register addressing mode cannot |
|
150 |
* be portably confused with longs used in the single-register addressing |
|
151 |
* mode. |
|
152 |
* |
|
153 |
* @param o Java heap object in which the variable resides, if any, else |
|
154 |
* null |
|
155 |
* @param offset indication of where the variable resides in a Java heap |
|
156 |
* object, if any, else a memory address locating the variable |
|
157 |
* statically |
|
158 |
* @return the value fetched from the indicated Java variable |
|
159 |
* @throws RuntimeException No defined exceptions are thrown, not even |
|
160 |
* {@link NullPointerException} |
|
161 |
*/ |
|
36628 | 162 |
@ForceInline |
163 |
public int getInt(Object o, long offset) { |
|
164 |
return theInternalUnsafe.getInt(o, offset); |
|
165 |
} |
|
2 | 166 |
|
167 |
/** |
|
168 |
* Stores a value into a given Java variable. |
|
169 |
* <p> |
|
170 |
* The first two parameters are interpreted exactly as with |
|
171 |
* {@link #getInt(Object, long)} to refer to a specific |
|
172 |
* Java variable (field or array element). The given value |
|
173 |
* is stored into that variable. |
|
174 |
* <p> |
|
175 |
* The variable must be of the same type as the method |
|
29388 | 176 |
* parameter {@code x}. |
2 | 177 |
* |
178 |
* @param o Java heap object in which the variable resides, if any, else |
|
179 |
* null |
|
180 |
* @param offset indication of where the variable resides in a Java heap |
|
181 |
* object, if any, else a memory address locating the variable |
|
182 |
* statically |
|
183 |
* @param x the value to store into the indicated Java variable |
|
184 |
* @throws RuntimeException No defined exceptions are thrown, not even |
|
185 |
* {@link NullPointerException} |
|
186 |
*/ |
|
36628 | 187 |
@ForceInline |
188 |
public void putInt(Object o, long offset, int x) { |
|
189 |
theInternalUnsafe.putInt(o, offset, x); |
|
190 |
} |
|
2 | 191 |
|
192 |
/** |
|
193 |
* Fetches a reference value from a given Java variable. |
|
194 |
* @see #getInt(Object, long) |
|
195 |
*/ |
|
36628 | 196 |
@ForceInline |
197 |
public Object getObject(Object o, long offset) { |
|
198 |
return theInternalUnsafe.getObject(o, offset); |
|
199 |
} |
|
2 | 200 |
|
201 |
/** |
|
202 |
* Stores a reference value into a given Java variable. |
|
203 |
* <p> |
|
29388 | 204 |
* Unless the reference {@code x} being stored is either null |
2 | 205 |
* or matches the field type, the results are undefined. |
30361
76bb3472a9dd
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30338
diff
changeset
|
206 |
* If the reference {@code o} is non-null, card marks or |
2 | 207 |
* other store barriers for that object (if the VM requires them) |
208 |
* are updated. |
|
29028
f97d41a21983
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28671
diff
changeset
|
209 |
* @see #putInt(Object, long, int) |
2 | 210 |
*/ |
36628 | 211 |
@ForceInline |
212 |
public void putObject(Object o, long offset, Object x) { |
|
213 |
theInternalUnsafe.putObject(o, offset, x); |
|
214 |
} |
|
215 |
||
216 |
/** @see #getInt(Object, long) */ |
|
217 |
@ForceInline |
|
218 |
public boolean getBoolean(Object o, long offset) { |
|
219 |
return theInternalUnsafe.getBoolean(o, offset); |
|
220 |
} |
|
221 |
||
222 |
/** @see #putInt(Object, long, int) */ |
|
223 |
@ForceInline |
|
224 |
public void putBoolean(Object o, long offset, boolean x) { |
|
225 |
theInternalUnsafe.putBoolean(o, offset, x); |
|
226 |
} |
|
227 |
||
228 |
/** @see #getInt(Object, long) */ |
|
229 |
@ForceInline |
|
230 |
public byte getByte(Object o, long offset) { |
|
231 |
return theInternalUnsafe.getByte(o, offset); |
|
232 |
} |
|
233 |
||
234 |
/** @see #putInt(Object, long, int) */ |
|
235 |
@ForceInline |
|
236 |
public void putByte(Object o, long offset, byte x) { |
|
237 |
theInternalUnsafe.putByte(o, offset, x); |
|
238 |
} |
|
239 |
||
240 |
/** @see #getInt(Object, long) */ |
|
241 |
@ForceInline |
|
242 |
public short getShort(Object o, long offset) { |
|
243 |
return theInternalUnsafe.getShort(o, offset); |
|
244 |
} |
|
245 |
||
246 |
/** @see #putInt(Object, long, int) */ |
|
247 |
@ForceInline |
|
248 |
public void putShort(Object o, long offset, short x) { |
|
249 |
theInternalUnsafe.putShort(o, offset, x); |
|
250 |
} |
|
2 | 251 |
|
252 |
/** @see #getInt(Object, long) */ |
|
36628 | 253 |
@ForceInline |
254 |
public char getChar(Object o, long offset) { |
|
255 |
return theInternalUnsafe.getChar(o, offset); |
|
256 |
} |
|
257 |
||
29028
f97d41a21983
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28671
diff
changeset
|
258 |
/** @see #putInt(Object, long, int) */ |
36628 | 259 |
@ForceInline |
260 |
public void putChar(Object o, long offset, char x) { |
|
261 |
theInternalUnsafe.putChar(o, offset, x); |
|
262 |
} |
|
263 |
||
2 | 264 |
/** @see #getInt(Object, long) */ |
36628 | 265 |
@ForceInline |
266 |
public long getLong(Object o, long offset) { |
|
267 |
return theInternalUnsafe.getLong(o, offset); |
|
268 |
} |
|
269 |
||
29028
f97d41a21983
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28671
diff
changeset
|
270 |
/** @see #putInt(Object, long, int) */ |
36628 | 271 |
@ForceInline |
272 |
public void putLong(Object o, long offset, long x) { |
|
273 |
theInternalUnsafe.putLong(o, offset, x); |
|
274 |
} |
|
275 |
||
2 | 276 |
/** @see #getInt(Object, long) */ |
36628 | 277 |
@ForceInline |
278 |
public float getFloat(Object o, long offset) { |
|
279 |
return theInternalUnsafe.getFloat(o, offset); |
|
280 |
} |
|
281 |
||
29028
f97d41a21983
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28671
diff
changeset
|
282 |
/** @see #putInt(Object, long, int) */ |
36628 | 283 |
@ForceInline |
284 |
public void putFloat(Object o, long offset, float x) { |
|
285 |
theInternalUnsafe.putFloat(o, offset, x); |
|
286 |
} |
|
287 |
||
2 | 288 |
/** @see #getInt(Object, long) */ |
36628 | 289 |
@ForceInline |
290 |
public double getDouble(Object o, long offset) { |
|
291 |
return theInternalUnsafe.getDouble(o, offset); |
|
292 |
} |
|
293 |
||
29028
f97d41a21983
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28671
diff
changeset
|
294 |
/** @see #putInt(Object, long, int) */ |
36628 | 295 |
@ForceInline |
296 |
public void putDouble(Object o, long offset, double x) { |
|
297 |
theInternalUnsafe.putDouble(o, offset, x); |
|
298 |
} |
|
299 |
||
2 | 300 |
// These work on values in the C heap. |
301 |
||
302 |
/** |
|
303 |
* Fetches a value from a given memory address. If the address is zero, or |
|
304 |
* does not point into a block obtained from {@link #allocateMemory}, the |
|
305 |
* results are undefined. |
|
306 |
* |
|
307 |
* @see #allocateMemory |
|
308 |
*/ |
|
36628 | 309 |
@ForceInline |
310 |
public byte getByte(long address) { |
|
311 |
return theInternalUnsafe.getByte(address); |
|
312 |
} |
|
2 | 313 |
|
314 |
/** |
|
315 |
* Stores a value into a given memory address. If the address is zero, or |
|
316 |
* does not point into a block obtained from {@link #allocateMemory}, the |
|
317 |
* results are undefined. |
|
318 |
* |
|
319 |
* @see #getByte(long) |
|
320 |
*/ |
|
36628 | 321 |
@ForceInline |
322 |
public void putByte(long address, byte x) { |
|
323 |
theInternalUnsafe.putByte(address, x); |
|
324 |
} |
|
325 |
||
326 |
/** @see #getByte(long) */ |
|
327 |
@ForceInline |
|
328 |
public short getShort(long address) { |
|
329 |
return theInternalUnsafe.getShort(address); |
|
330 |
} |
|
331 |
||
332 |
/** @see #putByte(long, byte) */ |
|
333 |
@ForceInline |
|
334 |
public void putShort(long address, short x) { |
|
335 |
theInternalUnsafe.putShort(address, x); |
|
336 |
} |
|
337 |
||
338 |
/** @see #getByte(long) */ |
|
339 |
@ForceInline |
|
340 |
public char getChar(long address) { |
|
341 |
return theInternalUnsafe.getChar(address); |
|
342 |
} |
|
343 |
||
344 |
/** @see #putByte(long, byte) */ |
|
345 |
@ForceInline |
|
346 |
public void putChar(long address, char x) { |
|
347 |
theInternalUnsafe.putChar(address, x); |
|
348 |
} |
|
2 | 349 |
|
350 |
/** @see #getByte(long) */ |
|
36628 | 351 |
@ForceInline |
352 |
public int getInt(long address) { |
|
353 |
return theInternalUnsafe.getInt(address); |
|
354 |
} |
|
355 |
||
2 | 356 |
/** @see #putByte(long, byte) */ |
36628 | 357 |
@ForceInline |
358 |
public void putInt(long address, int x) { |
|
359 |
theInternalUnsafe.putInt(address, x); |
|
360 |
} |
|
361 |
||
2 | 362 |
/** @see #getByte(long) */ |
36628 | 363 |
@ForceInline |
364 |
public long getLong(long address) { |
|
365 |
return theInternalUnsafe.getLong(address); |
|
366 |
} |
|
367 |
||
2 | 368 |
/** @see #putByte(long, byte) */ |
36628 | 369 |
@ForceInline |
370 |
public void putLong(long address, long x) { |
|
371 |
theInternalUnsafe.putLong(address, x); |
|
372 |
} |
|
373 |
||
2 | 374 |
/** @see #getByte(long) */ |
36628 | 375 |
@ForceInline |
376 |
public float getFloat(long address) { |
|
377 |
return theInternalUnsafe.getFloat(address); |
|
378 |
} |
|
379 |
||
2 | 380 |
/** @see #putByte(long, byte) */ |
36628 | 381 |
@ForceInline |
382 |
public void putFloat(long address, float x) { |
|
383 |
theInternalUnsafe.putFloat(address, x); |
|
384 |
} |
|
385 |
||
2 | 386 |
/** @see #getByte(long) */ |
36628 | 387 |
@ForceInline |
388 |
public double getDouble(long address) { |
|
389 |
return theInternalUnsafe.getDouble(address); |
|
390 |
} |
|
391 |
||
2 | 392 |
/** @see #putByte(long, byte) */ |
36628 | 393 |
@ForceInline |
394 |
public void putDouble(long address, double x) { |
|
395 |
theInternalUnsafe.putDouble(address, x); |
|
396 |
} |
|
397 |
||
2 | 398 |
|
399 |
/** |
|
400 |
* Fetches a native pointer from a given memory address. If the address is |
|
401 |
* zero, or does not point into a block obtained from {@link |
|
402 |
* #allocateMemory}, the results are undefined. |
|
403 |
* |
|
29388 | 404 |
* <p>If the native pointer is less than 64 bits wide, it is extended as |
2 | 405 |
* an unsigned number to a Java long. The pointer may be indexed by any |
406 |
* given byte offset, simply by adding that offset (as a simple integer) to |
|
407 |
* the long representing the pointer. The number of bytes actually read |
|
29388 | 408 |
* from the target address may be determined by consulting {@link |
2 | 409 |
* #addressSize}. |
410 |
* |
|
411 |
* @see #allocateMemory |
|
412 |
*/ |
|
36628 | 413 |
@ForceInline |
414 |
public long getAddress(long address) { |
|
415 |
return theInternalUnsafe.getAddress(address); |
|
416 |
} |
|
2 | 417 |
|
418 |
/** |
|
419 |
* Stores a native pointer into a given memory address. If the address is |
|
420 |
* zero, or does not point into a block obtained from {@link |
|
421 |
* #allocateMemory}, the results are undefined. |
|
422 |
* |
|
29388 | 423 |
* <p>The number of bytes actually written at the target address may be |
2 | 424 |
* determined by consulting {@link #addressSize}. |
425 |
* |
|
426 |
* @see #getAddress(long) |
|
427 |
*/ |
|
36628 | 428 |
@ForceInline |
429 |
public void putAddress(long address, long x) { |
|
430 |
theInternalUnsafe.putAddress(address, x); |
|
431 |
} |
|
432 |
||
2 | 433 |
|
434 |
/// wrappers for malloc, realloc, free: |
|
435 |
||
436 |
/** |
|
437 |
* Allocates a new block of native memory, of the given size in bytes. The |
|
438 |
* contents of the memory are uninitialized; they will generally be |
|
439 |
* garbage. The resulting native pointer will never be zero, and will be |
|
440 |
* aligned for all value types. Dispose of this memory by calling {@link |
|
441 |
* #freeMemory}, or resize it with {@link #reallocateMemory}. |
|
442 |
* |
|
36628 | 443 |
* <em>Note:</em> It is the resposibility of the caller to make |
444 |
* sure arguments are checked before the methods are called. While |
|
445 |
* some rudimentary checks are performed on the input, the checks |
|
446 |
* are best effort and when performance is an overriding priority, |
|
447 |
* as when methods of this class are optimized by the runtime |
|
448 |
* compiler, some or all checks (if any) may be elided. Hence, the |
|
449 |
* caller must not rely on the checks and corresponding |
|
450 |
* exceptions! |
|
451 |
* |
|
452 |
* @throws RuntimeException if the size is negative or too large |
|
2 | 453 |
* for the native size_t type |
454 |
* |
|
455 |
* @throws OutOfMemoryError if the allocation is refused by the system |
|
456 |
* |
|
457 |
* @see #getByte(long) |
|
458 |
* @see #putByte(long, byte) |
|
459 |
*/ |
|
36628 | 460 |
@ForceInline |
461 |
public long allocateMemory(long bytes) { |
|
462 |
return theInternalUnsafe.allocateMemory(bytes); |
|
463 |
} |
|
2 | 464 |
|
465 |
/** |
|
466 |
* Resizes a new block of native memory, to the given size in bytes. The |
|
467 |
* contents of the new block past the size of the old block are |
|
468 |
* uninitialized; they will generally be garbage. The resulting native |
|
469 |
* pointer will be zero if and only if the requested size is zero. The |
|
470 |
* resulting native pointer will be aligned for all value types. Dispose |
|
471 |
* of this memory by calling {@link #freeMemory}, or resize it with {@link |
|
472 |
* #reallocateMemory}. The address passed to this method may be null, in |
|
473 |
* which case an allocation will be performed. |
|
474 |
* |
|
36628 | 475 |
* <em>Note:</em> It is the resposibility of the caller to make |
476 |
* sure arguments are checked before the methods are called. While |
|
477 |
* some rudimentary checks are performed on the input, the checks |
|
478 |
* are best effort and when performance is an overriding priority, |
|
479 |
* as when methods of this class are optimized by the runtime |
|
480 |
* compiler, some or all checks (if any) may be elided. Hence, the |
|
481 |
* caller must not rely on the checks and corresponding |
|
482 |
* exceptions! |
|
483 |
* |
|
484 |
* @throws RuntimeException if the size is negative or too large |
|
2 | 485 |
* for the native size_t type |
486 |
* |
|
487 |
* @throws OutOfMemoryError if the allocation is refused by the system |
|
488 |
* |
|
489 |
* @see #allocateMemory |
|
490 |
*/ |
|
36628 | 491 |
@ForceInline |
492 |
public long reallocateMemory(long address, long bytes) { |
|
493 |
return theInternalUnsafe.reallocateMemory(address, bytes); |
|
494 |
} |
|
2 | 495 |
|
496 |
/** |
|
497 |
* Sets all bytes in a given block of memory to a fixed value |
|
498 |
* (usually zero). |
|
499 |
* |
|
500 |
* <p>This method determines a block's base address by means of two parameters, |
|
501 |
* and so it provides (in effect) a <em>double-register</em> addressing mode, |
|
502 |
* as discussed in {@link #getInt(Object,long)}. When the object reference is null, |
|
503 |
* the offset supplies an absolute base address. |
|
504 |
* |
|
505 |
* <p>The stores are in coherent (atomic) units of a size determined |
|
506 |
* by the address and length parameters. If the effective address and |
|
507 |
* length are all even modulo 8, the stores take place in 'long' units. |
|
508 |
* If the effective address and length are (resp.) even modulo 4 or 2, |
|
509 |
* the stores take place in units of 'int' or 'short'. |
|
510 |
* |
|
36628 | 511 |
* <em>Note:</em> It is the resposibility of the caller to make |
512 |
* sure arguments are checked before the methods are called. While |
|
513 |
* some rudimentary checks are performed on the input, the checks |
|
514 |
* are best effort and when performance is an overriding priority, |
|
515 |
* as when methods of this class are optimized by the runtime |
|
516 |
* compiler, some or all checks (if any) may be elided. Hence, the |
|
517 |
* caller must not rely on the checks and corresponding |
|
518 |
* exceptions! |
|
519 |
* |
|
520 |
* @throws RuntimeException if any of the arguments is invalid |
|
521 |
* |
|
2 | 522 |
* @since 1.7 |
523 |
*/ |
|
36628 | 524 |
@ForceInline |
525 |
public void setMemory(Object o, long offset, long bytes, byte value) { |
|
526 |
theInternalUnsafe.setMemory(o, offset, bytes, value); |
|
527 |
} |
|
2 | 528 |
|
529 |
/** |
|
530 |
* Sets all bytes in a given block of memory to a fixed value |
|
531 |
* (usually zero). This provides a <em>single-register</em> addressing mode, |
|
532 |
* as discussed in {@link #getInt(Object,long)}. |
|
533 |
* |
|
29388 | 534 |
* <p>Equivalent to {@code setMemory(null, address, bytes, value)}. |
2 | 535 |
*/ |
36628 | 536 |
@ForceInline |
2 | 537 |
public void setMemory(long address, long bytes, byte value) { |
36628 | 538 |
theInternalUnsafe.setMemory(address, bytes, value); |
2 | 539 |
} |
540 |
||
541 |
/** |
|
542 |
* Sets all bytes in a given block of memory to a copy of another |
|
543 |
* block. |
|
544 |
* |
|
545 |
* <p>This method determines each block's base address by means of two parameters, |
|
546 |
* and so it provides (in effect) a <em>double-register</em> addressing mode, |
|
547 |
* as discussed in {@link #getInt(Object,long)}. When the object reference is null, |
|
548 |
* the offset supplies an absolute base address. |
|
549 |
* |
|
550 |
* <p>The transfers are in coherent (atomic) units of a size determined |
|
551 |
* by the address and length parameters. If the effective addresses and |
|
552 |
* length are all even modulo 8, the transfer takes place in 'long' units. |
|
553 |
* If the effective addresses and length are (resp.) even modulo 4 or 2, |
|
554 |
* the transfer takes place in units of 'int' or 'short'. |
|
555 |
* |
|
36628 | 556 |
* <em>Note:</em> It is the resposibility of the caller to make |
557 |
* sure arguments are checked before the methods are called. While |
|
558 |
* some rudimentary checks are performed on the input, the checks |
|
559 |
* are best effort and when performance is an overriding priority, |
|
560 |
* as when methods of this class are optimized by the runtime |
|
561 |
* compiler, some or all checks (if any) may be elided. Hence, the |
|
562 |
* caller must not rely on the checks and corresponding |
|
563 |
* exceptions! |
|
564 |
* |
|
565 |
* @throws RuntimeException if any of the arguments is invalid |
|
566 |
* |
|
2 | 567 |
* @since 1.7 |
568 |
*/ |
|
36628 | 569 |
@ForceInline |
570 |
public void copyMemory(Object srcBase, long srcOffset, |
|
571 |
Object destBase, long destOffset, |
|
572 |
long bytes) { |
|
573 |
theInternalUnsafe.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes); |
|
574 |
} |
|
575 |
||
2 | 576 |
/** |
577 |
* Sets all bytes in a given block of memory to a copy of another |
|
578 |
* block. This provides a <em>single-register</em> addressing mode, |
|
579 |
* as discussed in {@link #getInt(Object,long)}. |
|
580 |
* |
|
29388 | 581 |
* Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}. |
2 | 582 |
*/ |
36628 | 583 |
@ForceInline |
2 | 584 |
public void copyMemory(long srcAddress, long destAddress, long bytes) { |
36628 | 585 |
theInternalUnsafe.copyMemory(srcAddress, destAddress, bytes); |
2 | 586 |
} |
587 |
||
588 |
/** |
|
589 |
* Disposes of a block of native memory, as obtained from {@link |
|
590 |
* #allocateMemory} or {@link #reallocateMemory}. The address passed to |
|
591 |
* this method may be null, in which case no action is taken. |
|
592 |
* |
|
36628 | 593 |
* <em>Note:</em> It is the resposibility of the caller to make |
594 |
* sure arguments are checked before the methods are called. While |
|
595 |
* some rudimentary checks are performed on the input, the checks |
|
596 |
* are best effort and when performance is an overriding priority, |
|
597 |
* as when methods of this class are optimized by the runtime |
|
598 |
* compiler, some or all checks (if any) may be elided. Hence, the |
|
599 |
* caller must not rely on the checks and corresponding |
|
600 |
* exceptions! |
|
601 |
* |
|
602 |
* @throws RuntimeException if any of the arguments is invalid |
|
603 |
* |
|
2 | 604 |
* @see #allocateMemory |
605 |
*/ |
|
36628 | 606 |
@ForceInline |
607 |
public void freeMemory(long address) { |
|
608 |
theInternalUnsafe.freeMemory(address); |
|
609 |
} |
|
2 | 610 |
|
611 |
/// random queries |
|
612 |
||
613 |
/** |
|
614 |
* This constant differs from all results that will ever be returned from |
|
615 |
* {@link #staticFieldOffset}, {@link #objectFieldOffset}, |
|
616 |
* or {@link #arrayBaseOffset}. |
|
617 |
*/ |
|
36628 | 618 |
public static final int INVALID_FIELD_OFFSET = jdk.internal.misc.Unsafe.INVALID_FIELD_OFFSET; |
2 | 619 |
|
620 |
/** |
|
29388 | 621 |
* Reports the location of a given field in the storage allocation of its |
2 | 622 |
* class. Do not expect to perform any sort of arithmetic on this offset; |
623 |
* it is just a cookie which is passed to the unsafe heap memory accessors. |
|
624 |
* |
|
625 |
* <p>Any given field will always have the same offset and base, and no |
|
626 |
* two distinct fields of the same class will ever have the same offset |
|
627 |
* and base. |
|
628 |
* |
|
629 |
* <p>As of 1.4.1, offsets for fields are represented as long values, |
|
630 |
* although the Sun JVM does not use the most significant 32 bits. |
|
631 |
* However, JVM implementations which store static fields at absolute |
|
632 |
* addresses can use long offsets and null base pointers to express |
|
633 |
* the field locations in a form usable by {@link #getInt(Object,long)}. |
|
634 |
* Therefore, code which will be ported to such JVMs on 64-bit platforms |
|
635 |
* must preserve all bits of static field offsets. |
|
636 |
* @see #getInt(Object, long) |
|
637 |
*/ |
|
36628 | 638 |
@ForceInline |
639 |
public long objectFieldOffset(Field f) { |
|
640 |
return theInternalUnsafe.objectFieldOffset(f); |
|
641 |
} |
|
2 | 642 |
|
643 |
/** |
|
29388 | 644 |
* Reports the location of a given static field, in conjunction with {@link |
2 | 645 |
* #staticFieldBase}. |
646 |
* <p>Do not expect to perform any sort of arithmetic on this offset; |
|
647 |
* it is just a cookie which is passed to the unsafe heap memory accessors. |
|
648 |
* |
|
649 |
* <p>Any given field will always have the same offset, and no two distinct |
|
650 |
* fields of the same class will ever have the same offset. |
|
651 |
* |
|
652 |
* <p>As of 1.4.1, offsets for fields are represented as long values, |
|
653 |
* although the Sun JVM does not use the most significant 32 bits. |
|
654 |
* It is hard to imagine a JVM technology which needs more than |
|
655 |
* a few bits to encode an offset within a non-array object, |
|
656 |
* However, for consistency with other methods in this class, |
|
657 |
* this method reports its result as a long value. |
|
658 |
* @see #getInt(Object, long) |
|
659 |
*/ |
|
36628 | 660 |
@ForceInline |
661 |
public long staticFieldOffset(Field f) { |
|
662 |
return theInternalUnsafe.staticFieldOffset(f); |
|
663 |
} |
|
2 | 664 |
|
665 |
/** |
|
29388 | 666 |
* Reports the location of a given static field, in conjunction with {@link |
2 | 667 |
* #staticFieldOffset}. |
668 |
* <p>Fetch the base "Object", if any, with which static fields of the |
|
669 |
* given class can be accessed via methods like {@link #getInt(Object, |
|
670 |
* long)}. This value may be null. This value may refer to an object |
|
671 |
* which is a "cookie", not guaranteed to be a real Object, and it should |
|
672 |
* not be used in any way except as argument to the get and put routines in |
|
673 |
* this class. |
|
674 |
*/ |
|
36628 | 675 |
@ForceInline |
676 |
public Object staticFieldBase(Field f) { |
|
677 |
return theInternalUnsafe.staticFieldBase(f); |
|
678 |
} |
|
2 | 679 |
|
680 |
/** |
|
29388 | 681 |
* Detects if the given class may need to be initialized. This is often |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11117
diff
changeset
|
682 |
* needed in conjunction with obtaining the static field base of a |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11117
diff
changeset
|
683 |
* class. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11117
diff
changeset
|
684 |
* @return false only if a call to {@code ensureClassInitialized} would have no effect |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11117
diff
changeset
|
685 |
*/ |
36628 | 686 |
@ForceInline |
687 |
public boolean shouldBeInitialized(Class<?> c) { |
|
688 |
return theInternalUnsafe.shouldBeInitialized(c); |
|
689 |
} |
|
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11117
diff
changeset
|
690 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
11117
diff
changeset
|
691 |
/** |
29388 | 692 |
* Ensures the given class has been initialized. This is often |
2 | 693 |
* needed in conjunction with obtaining the static field base of a |
694 |
* class. |
|
695 |
*/ |
|
36628 | 696 |
@ForceInline |
697 |
public void ensureClassInitialized(Class<?> c) { |
|
698 |
theInternalUnsafe.ensureClassInitialized(c); |
|
699 |
} |
|
2 | 700 |
|
701 |
/** |
|
29388 | 702 |
* Reports the offset of the first element in the storage allocation of a |
2 | 703 |
* given array class. If {@link #arrayIndexScale} returns a non-zero value |
704 |
* for the same class, you may use that scale factor, together with this |
|
705 |
* base offset, to form new offsets to access elements of arrays of the |
|
706 |
* given class. |
|
707 |
* |
|
708 |
* @see #getInt(Object, long) |
|
709 |
* @see #putInt(Object, long, int) |
|
710 |
*/ |
|
36628 | 711 |
@ForceInline |
712 |
public int arrayBaseOffset(Class<?> arrayClass) { |
|
713 |
return theInternalUnsafe.arrayBaseOffset(arrayClass); |
|
714 |
} |
|
2 | 715 |
|
716 |
/** The value of {@code arrayBaseOffset(boolean[].class)} */ |
|
36628 | 717 |
public static final int ARRAY_BOOLEAN_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_BASE_OFFSET; |
2 | 718 |
|
719 |
/** The value of {@code arrayBaseOffset(byte[].class)} */ |
|
36628 | 720 |
public static final int ARRAY_BYTE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET; |
2 | 721 |
|
722 |
/** The value of {@code arrayBaseOffset(short[].class)} */ |
|
36628 | 723 |
public static final int ARRAY_SHORT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_SHORT_BASE_OFFSET; |
2 | 724 |
|
725 |
/** The value of {@code arrayBaseOffset(char[].class)} */ |
|
36628 | 726 |
public static final int ARRAY_CHAR_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_CHAR_BASE_OFFSET; |
2 | 727 |
|
728 |
/** The value of {@code arrayBaseOffset(int[].class)} */ |
|
36628 | 729 |
public static final int ARRAY_INT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_INT_BASE_OFFSET; |
2 | 730 |
|
731 |
/** The value of {@code arrayBaseOffset(long[].class)} */ |
|
36628 | 732 |
public static final int ARRAY_LONG_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_LONG_BASE_OFFSET; |
2 | 733 |
|
734 |
/** The value of {@code arrayBaseOffset(float[].class)} */ |
|
36628 | 735 |
public static final int ARRAY_FLOAT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_FLOAT_BASE_OFFSET; |
2 | 736 |
|
737 |
/** The value of {@code arrayBaseOffset(double[].class)} */ |
|
36628 | 738 |
public static final int ARRAY_DOUBLE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_BASE_OFFSET; |
2 | 739 |
|
740 |
/** The value of {@code arrayBaseOffset(Object[].class)} */ |
|
36628 | 741 |
public static final int ARRAY_OBJECT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_OBJECT_BASE_OFFSET; |
2 | 742 |
|
743 |
/** |
|
29388 | 744 |
* Reports the scale factor for addressing elements in the storage |
2 | 745 |
* allocation of a given array class. However, arrays of "narrow" types |
746 |
* will generally not work properly with accessors like {@link |
|
29028
f97d41a21983
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28671
diff
changeset
|
747 |
* #getByte(Object, long)}, so the scale factor for such classes is reported |
2 | 748 |
* as zero. |
749 |
* |
|
750 |
* @see #arrayBaseOffset |
|
751 |
* @see #getInt(Object, long) |
|
752 |
* @see #putInt(Object, long, int) |
|
753 |
*/ |
|
36628 | 754 |
@ForceInline |
755 |
public int arrayIndexScale(Class<?> arrayClass) { |
|
756 |
return theInternalUnsafe.arrayIndexScale(arrayClass); |
|
757 |
} |
|
2 | 758 |
|
759 |
/** The value of {@code arrayIndexScale(boolean[].class)} */ |
|
36628 | 760 |
public static final int ARRAY_BOOLEAN_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_INDEX_SCALE; |
2 | 761 |
|
762 |
/** The value of {@code arrayIndexScale(byte[].class)} */ |
|
36628 | 763 |
public static final int ARRAY_BYTE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BYTE_INDEX_SCALE; |
2 | 764 |
|
765 |
/** The value of {@code arrayIndexScale(short[].class)} */ |
|
36628 | 766 |
public static final int ARRAY_SHORT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_SHORT_INDEX_SCALE; |
2 | 767 |
|
768 |
/** The value of {@code arrayIndexScale(char[].class)} */ |
|
36628 | 769 |
public static final int ARRAY_CHAR_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_CHAR_INDEX_SCALE; |
2 | 770 |
|
771 |
/** The value of {@code arrayIndexScale(int[].class)} */ |
|
36628 | 772 |
public static final int ARRAY_INT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_INT_INDEX_SCALE; |
2 | 773 |
|
774 |
/** The value of {@code arrayIndexScale(long[].class)} */ |
|
36628 | 775 |
public static final int ARRAY_LONG_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_LONG_INDEX_SCALE; |
2 | 776 |
|
777 |
/** The value of {@code arrayIndexScale(float[].class)} */ |
|
36628 | 778 |
public static final int ARRAY_FLOAT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_FLOAT_INDEX_SCALE; |
2 | 779 |
|
780 |
/** The value of {@code arrayIndexScale(double[].class)} */ |
|
36628 | 781 |
public static final int ARRAY_DOUBLE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_INDEX_SCALE; |
2 | 782 |
|
783 |
/** The value of {@code arrayIndexScale(Object[].class)} */ |
|
36628 | 784 |
public static final int ARRAY_OBJECT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE; |
2 | 785 |
|
786 |
/** |
|
29388 | 787 |
* Reports the size in bytes of a native pointer, as stored via {@link |
2 | 788 |
* #putAddress}. This value will be either 4 or 8. Note that the sizes of |
789 |
* other primitive types (as stored in native memory blocks) is determined |
|
790 |
* fully by their information content. |
|
791 |
*/ |
|
36628 | 792 |
@ForceInline |
793 |
public int addressSize() { |
|
794 |
return theInternalUnsafe.addressSize(); |
|
795 |
} |
|
2 | 796 |
|
797 |
/** The value of {@code addressSize()} */ |
|
36628 | 798 |
public static final int ADDRESS_SIZE = theInternalUnsafe.addressSize(); |
2 | 799 |
|
800 |
/** |
|
29388 | 801 |
* Reports the size in bytes of a native memory page (whatever that is). |
2 | 802 |
* This value will always be a power of two. |
803 |
*/ |
|
36628 | 804 |
@ForceInline |
805 |
public int pageSize() { |
|
806 |
return theInternalUnsafe.pageSize(); |
|
807 |
} |
|
2 | 808 |
|
809 |
||
810 |
/// random trusted operations from JNI: |
|
811 |
||
812 |
/** |
|
29388 | 813 |
* Defines a class but does not make it known to the class loader or system dictionary. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
814 |
* <p> |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
815 |
* For each CP entry, the corresponding CP patch must either be null or have |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
816 |
* the a format that matches its tag: |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
817 |
* <ul> |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
818 |
* <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
819 |
* <li>Utf8: a string (must have suitable syntax if used as signature or name) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
820 |
* <li>Class: any java.lang.Class object |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
821 |
* <li>String: any object (not just a java.lang.String) |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
822 |
* <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
823 |
* </ul> |
30655 | 824 |
* @param hostClass context for linkage, access control, protection domain, and class loader |
825 |
* @param data bytes of a class file |
|
826 |
* @param cpPatches where non-null entries exist, they replace corresponding CP entries in data |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
827 |
*/ |
36628 | 828 |
@ForceInline |
829 |
public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) { |
|
830 |
return theInternalUnsafe.defineAnonymousClass(hostClass, data, cpPatches); |
|
831 |
} |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
2
diff
changeset
|
832 |
|
29388 | 833 |
/** |
834 |
* Allocates an instance but does not run any constructor. |
|
835 |
* Initializes the class if it has not yet been. |
|
836 |
*/ |
|
36628 | 837 |
@ForceInline |
838 |
public Object allocateInstance(Class<?> cls) |
|
839 |
throws InstantiationException { |
|
840 |
return theInternalUnsafe.allocateInstance(cls); |
|
841 |
} |
|
2 | 842 |
|
29388 | 843 |
/** Throws the exception without telling the verifier. */ |
36628 | 844 |
@ForceInline |
845 |
public void throwException(Throwable ee) { |
|
846 |
theInternalUnsafe.throwException(ee); |
|
847 |
} |
|
2 | 848 |
|
849 |
/** |
|
29388 | 850 |
* Atomically updates Java variable to {@code x} if it is currently |
851 |
* holding {@code expected}. |
|
29715
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
852 |
* |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
853 |
* <p>This operation has memory semantics of a {@code volatile} read |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
854 |
* and write. Corresponds to C11 atomic_compare_exchange_strong. |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
855 |
* |
29388 | 856 |
* @return {@code true} if successful |
2 | 857 |
*/ |
36628 | 858 |
@ForceInline |
859 |
public final boolean compareAndSwapObject(Object o, long offset, |
|
860 |
Object expected, |
|
861 |
Object x) { |
|
45518
4a116dd82fb5
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
44359
diff
changeset
|
862 |
return theInternalUnsafe.compareAndSetObject(o, offset, expected, x); |
36628 | 863 |
} |
2 | 864 |
|
865 |
/** |
|
29388 | 866 |
* Atomically updates Java variable to {@code x} if it is currently |
867 |
* holding {@code expected}. |
|
29715
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
868 |
* |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
869 |
* <p>This operation has memory semantics of a {@code volatile} read |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
870 |
* and write. Corresponds to C11 atomic_compare_exchange_strong. |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
871 |
* |
29388 | 872 |
* @return {@code true} if successful |
2 | 873 |
*/ |
36628 | 874 |
@ForceInline |
875 |
public final boolean compareAndSwapInt(Object o, long offset, |
|
876 |
int expected, |
|
877 |
int x) { |
|
45518
4a116dd82fb5
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
44359
diff
changeset
|
878 |
return theInternalUnsafe.compareAndSetInt(o, offset, expected, x); |
36628 | 879 |
} |
2 | 880 |
|
881 |
/** |
|
29388 | 882 |
* Atomically updates Java variable to {@code x} if it is currently |
883 |
* holding {@code expected}. |
|
29715
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
884 |
* |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
885 |
* <p>This operation has memory semantics of a {@code volatile} read |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
886 |
* and write. Corresponds to C11 atomic_compare_exchange_strong. |
ca3f43a932cf
8074578: Document memory visibility effects of Unsafe compareAndSwap methods
martin
parents:
29388
diff
changeset
|
887 |
* |
29388 | 888 |
* @return {@code true} if successful |
2 | 889 |
*/ |
36628 | 890 |
@ForceInline |
891 |
public final boolean compareAndSwapLong(Object o, long offset, |
|
892 |
long expected, |
|
893 |
long x) { |
|
45518
4a116dd82fb5
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
44359
diff
changeset
|
894 |
return theInternalUnsafe.compareAndSetLong(o, offset, expected, x); |
36628 | 895 |
} |
2 | 896 |
|
897 |
/** |
|
898 |
* Fetches a reference value from a given Java variable, with volatile |
|
899 |
* load semantics. Otherwise identical to {@link #getObject(Object, long)} |
|
900 |
*/ |
|
36628 | 901 |
@ForceInline |
902 |
public Object getObjectVolatile(Object o, long offset) { |
|
903 |
return theInternalUnsafe.getObjectVolatile(o, offset); |
|
904 |
} |
|
2 | 905 |
|
906 |
/** |
|
907 |
* Stores a reference value into a given Java variable, with |
|
908 |
* volatile store semantics. Otherwise identical to {@link #putObject(Object, long, Object)} |
|
909 |
*/ |
|
36628 | 910 |
@ForceInline |
911 |
public void putObjectVolatile(Object o, long offset, Object x) { |
|
912 |
theInternalUnsafe.putObjectVolatile(o, offset, x); |
|
913 |
} |
|
2 | 914 |
|
915 |
/** Volatile version of {@link #getInt(Object, long)} */ |
|
36628 | 916 |
@ForceInline |
917 |
public int getIntVolatile(Object o, long offset) { |
|
918 |
return theInternalUnsafe.getIntVolatile(o, offset); |
|
919 |
} |
|
2 | 920 |
|
921 |
/** Volatile version of {@link #putInt(Object, long, int)} */ |
|
36628 | 922 |
@ForceInline |
923 |
public void putIntVolatile(Object o, long offset, int x) { |
|
924 |
theInternalUnsafe.putIntVolatile(o, offset, x); |
|
925 |
} |
|
2 | 926 |
|
927 |
/** Volatile version of {@link #getBoolean(Object, long)} */ |
|
36628 | 928 |
@ForceInline |
929 |
public boolean getBooleanVolatile(Object o, long offset) { |
|
930 |
return theInternalUnsafe.getBooleanVolatile(o, offset); |
|
931 |
} |
|
2 | 932 |
|
933 |
/** Volatile version of {@link #putBoolean(Object, long, boolean)} */ |
|
36628 | 934 |
@ForceInline |
935 |
public void putBooleanVolatile(Object o, long offset, boolean x) { |
|
936 |
theInternalUnsafe.putBooleanVolatile(o, offset, x); |
|
937 |
} |
|
2 | 938 |
|
939 |
/** Volatile version of {@link #getByte(Object, long)} */ |
|
36628 | 940 |
@ForceInline |
941 |
public byte getByteVolatile(Object o, long offset) { |
|
942 |
return theInternalUnsafe.getByteVolatile(o, offset); |
|
943 |
} |
|
2 | 944 |
|
945 |
/** Volatile version of {@link #putByte(Object, long, byte)} */ |
|
36628 | 946 |
@ForceInline |
947 |
public void putByteVolatile(Object o, long offset, byte x) { |
|
948 |
theInternalUnsafe.putByteVolatile(o, offset, x); |
|
949 |
} |
|
2 | 950 |
|
951 |
/** Volatile version of {@link #getShort(Object, long)} */ |
|
36628 | 952 |
@ForceInline |
953 |
public short getShortVolatile(Object o, long offset) { |
|
954 |
return theInternalUnsafe.getShortVolatile(o, offset); |
|
955 |
} |
|
2 | 956 |
|
957 |
/** Volatile version of {@link #putShort(Object, long, short)} */ |
|
36628 | 958 |
@ForceInline |
959 |
public void putShortVolatile(Object o, long offset, short x) { |
|
960 |
theInternalUnsafe.putShortVolatile(o, offset, x); |
|
961 |
} |
|
2 | 962 |
|
963 |
/** Volatile version of {@link #getChar(Object, long)} */ |
|
36628 | 964 |
@ForceInline |
965 |
public char getCharVolatile(Object o, long offset) { |
|
966 |
return theInternalUnsafe.getCharVolatile(o, offset); |
|
967 |
} |
|
2 | 968 |
|
969 |
/** Volatile version of {@link #putChar(Object, long, char)} */ |
|
36628 | 970 |
@ForceInline |
971 |
public void putCharVolatile(Object o, long offset, char x) { |
|
972 |
theInternalUnsafe.putCharVolatile(o, offset, x); |
|
973 |
} |
|
2 | 974 |
|
975 |
/** Volatile version of {@link #getLong(Object, long)} */ |
|
36628 | 976 |
@ForceInline |
977 |
public long getLongVolatile(Object o, long offset) { |
|
978 |
return theInternalUnsafe.getLongVolatile(o, offset); |
|
979 |
} |
|
2 | 980 |
|
981 |
/** Volatile version of {@link #putLong(Object, long, long)} */ |
|
36628 | 982 |
@ForceInline |
983 |
public void putLongVolatile(Object o, long offset, long x) { |
|
984 |
theInternalUnsafe.putLongVolatile(o, offset, x); |
|
985 |
} |
|
2 | 986 |
|
987 |
/** Volatile version of {@link #getFloat(Object, long)} */ |
|
36628 | 988 |
@ForceInline |
989 |
public float getFloatVolatile(Object o, long offset) { |
|
990 |
return theInternalUnsafe.getFloatVolatile(o, offset); |
|
991 |
} |
|
2 | 992 |
|
993 |
/** Volatile version of {@link #putFloat(Object, long, float)} */ |
|
36628 | 994 |
@ForceInline |
995 |
public void putFloatVolatile(Object o, long offset, float x) { |
|
996 |
theInternalUnsafe.putFloatVolatile(o, offset, x); |
|
997 |
} |
|
2 | 998 |
|
999 |
/** Volatile version of {@link #getDouble(Object, long)} */ |
|
36628 | 1000 |
@ForceInline |
1001 |
public double getDoubleVolatile(Object o, long offset) { |
|
1002 |
return theInternalUnsafe.getDoubleVolatile(o, offset); |
|
1003 |
} |
|
2 | 1004 |
|
1005 |
/** Volatile version of {@link #putDouble(Object, long, double)} */ |
|
36628 | 1006 |
@ForceInline |
1007 |
public void putDoubleVolatile(Object o, long offset, double x) { |
|
1008 |
theInternalUnsafe.putDoubleVolatile(o, offset, x); |
|
1009 |
} |
|
2 | 1010 |
|
1011 |
/** |
|
1012 |
* Version of {@link #putObjectVolatile(Object, long, Object)} |
|
1013 |
* that does not guarantee immediate visibility of the store to |
|
1014 |
* other threads. This method is generally only useful if the |
|
1015 |
* underlying field is a Java volatile (or if an array cell, one |
|
1016 |
* that is otherwise only accessed using volatile accesses). |
|
28057
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1017 |
* |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1018 |
* Corresponds to C11 atomic_store_explicit(..., memory_order_release). |
2 | 1019 |
*/ |
36628 | 1020 |
@ForceInline |
1021 |
public void putOrderedObject(Object o, long offset, Object x) { |
|
36936
bfcdf736a998
8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents:
36628
diff
changeset
|
1022 |
theInternalUnsafe.putObjectRelease(o, offset, x); |
36628 | 1023 |
} |
2 | 1024 |
|
1025 |
/** Ordered/Lazy version of {@link #putIntVolatile(Object, long, int)} */ |
|
36628 | 1026 |
@ForceInline |
1027 |
public void putOrderedInt(Object o, long offset, int x) { |
|
36936
bfcdf736a998
8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents:
36628
diff
changeset
|
1028 |
theInternalUnsafe.putIntRelease(o, offset, x); |
36628 | 1029 |
} |
2 | 1030 |
|
1031 |
/** Ordered/Lazy version of {@link #putLongVolatile(Object, long, long)} */ |
|
36628 | 1032 |
@ForceInline |
1033 |
public void putOrderedLong(Object o, long offset, long x) { |
|
36936
bfcdf736a998
8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents:
36628
diff
changeset
|
1034 |
theInternalUnsafe.putLongRelease(o, offset, x); |
36628 | 1035 |
} |
2 | 1036 |
|
1037 |
/** |
|
29388 | 1038 |
* Unblocks the given thread blocked on {@code park}, or, if it is |
1039 |
* not blocked, causes the subsequent call to {@code park} not to |
|
2 | 1040 |
* block. Note: this operation is "unsafe" solely because the |
1041 |
* caller must somehow ensure that the thread has not been |
|
1042 |
* destroyed. Nothing special is usually required to ensure this |
|
1043 |
* when called from Java (in which there will ordinarily be a live |
|
1044 |
* reference to the thread) but this is not nearly-automatically |
|
1045 |
* so when calling from native code. |
|
29388 | 1046 |
* |
2 | 1047 |
* @param thread the thread to unpark. |
1048 |
*/ |
|
36628 | 1049 |
@ForceInline |
1050 |
public void unpark(Object thread) { |
|
1051 |
theInternalUnsafe.unpark(thread); |
|
1052 |
} |
|
2 | 1053 |
|
1054 |
/** |
|
29388 | 1055 |
* Blocks current thread, returning when a balancing |
1056 |
* {@code unpark} occurs, or a balancing {@code unpark} has |
|
2 | 1057 |
* already occurred, or the thread is interrupted, or, if not |
1058 |
* absolute and time is not zero, the given time nanoseconds have |
|
1059 |
* elapsed, or if absolute, the given deadline in milliseconds |
|
1060 |
* since Epoch has passed, or spuriously (i.e., returning for no |
|
1061 |
* "reason"). Note: This operation is in the Unsafe class only |
|
29388 | 1062 |
* because {@code unpark} is, so it would be strange to place it |
2 | 1063 |
* elsewhere. |
1064 |
*/ |
|
36628 | 1065 |
@ForceInline |
1066 |
public void park(boolean isAbsolute, long time) { |
|
1067 |
theInternalUnsafe.park(isAbsolute, time); |
|
1068 |
} |
|
2 | 1069 |
|
1070 |
/** |
|
1071 |
* Gets the load average in the system run queue assigned |
|
1072 |
* to the available processors averaged over various periods of time. |
|
29388 | 1073 |
* This method retrieves the given {@code nelem} samples and |
1074 |
* assigns to the elements of the given {@code loadavg} array. |
|
2 | 1075 |
* The system imposes a maximum of 3 samples, representing |
1076 |
* averages over the last 1, 5, and 15 minutes, respectively. |
|
1077 |
* |
|
30655 | 1078 |
* @param loadavg an array of double of size nelems |
1079 |
* @param nelems the number of samples to be retrieved and |
|
1080 |
* must be 1 to 3. |
|
2 | 1081 |
* |
1082 |
* @return the number of samples actually retrieved; or -1 |
|
1083 |
* if the load average is unobtainable. |
|
1084 |
*/ |
|
36628 | 1085 |
@ForceInline |
1086 |
public int getLoadAverage(double[] loadavg, int nelems) { |
|
1087 |
return theInternalUnsafe.getLoadAverage(loadavg, nelems); |
|
1088 |
} |
|
14851 | 1089 |
|
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1090 |
// The following contain CAS-based Java implementations used on |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1091 |
// platforms not supporting native instructions |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1092 |
|
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1093 |
/** |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1094 |
* Atomically adds the given value to the current value of a field |
29388 | 1095 |
* or array element within the given object {@code o} |
1096 |
* at the given {@code offset}. |
|
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1097 |
* |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1098 |
* @param o object/array to update the field/element in |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1099 |
* @param offset field/element offset |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1100 |
* @param delta the value to add |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1101 |
* @return the previous value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1102 |
* @since 1.8 |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1103 |
*/ |
36628 | 1104 |
@ForceInline |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1105 |
public final int getAndAddInt(Object o, long offset, int delta) { |
36628 | 1106 |
return theInternalUnsafe.getAndAddInt(o, offset, delta); |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1107 |
} |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1108 |
|
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1109 |
/** |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1110 |
* Atomically adds the given value to the current value of a field |
29388 | 1111 |
* or array element within the given object {@code o} |
1112 |
* at the given {@code offset}. |
|
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1113 |
* |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1114 |
* @param o object/array to update the field/element in |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1115 |
* @param offset field/element offset |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1116 |
* @param delta the value to add |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1117 |
* @return the previous value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1118 |
* @since 1.8 |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1119 |
*/ |
36628 | 1120 |
@ForceInline |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1121 |
public final long getAndAddLong(Object o, long offset, long delta) { |
36628 | 1122 |
return theInternalUnsafe.getAndAddLong(o, offset, delta); |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1123 |
} |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1124 |
|
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1125 |
/** |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1126 |
* Atomically exchanges the given value with the current value of |
29388 | 1127 |
* a field or array element within the given object {@code o} |
1128 |
* at the given {@code offset}. |
|
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1129 |
* |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1130 |
* @param o object/array to update the field/element in |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1131 |
* @param offset field/element offset |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1132 |
* @param newValue new value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1133 |
* @return the previous value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1134 |
* @since 1.8 |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1135 |
*/ |
36628 | 1136 |
@ForceInline |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1137 |
public final int getAndSetInt(Object o, long offset, int newValue) { |
36628 | 1138 |
return theInternalUnsafe.getAndSetInt(o, offset, newValue); |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1139 |
} |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1140 |
|
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1141 |
/** |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1142 |
* Atomically exchanges the given value with the current value of |
29388 | 1143 |
* a field or array element within the given object {@code o} |
1144 |
* at the given {@code offset}. |
|
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1145 |
* |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1146 |
* @param o object/array to update the field/element in |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1147 |
* @param offset field/element offset |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1148 |
* @param newValue new value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1149 |
* @return the previous value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1150 |
* @since 1.8 |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1151 |
*/ |
36628 | 1152 |
@ForceInline |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1153 |
public final long getAndSetLong(Object o, long offset, long newValue) { |
36628 | 1154 |
return theInternalUnsafe.getAndSetLong(o, offset, newValue); |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1155 |
} |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1156 |
|
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1157 |
/** |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1158 |
* Atomically exchanges the given reference value with the current |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1159 |
* reference value of a field or array element within the given |
29388 | 1160 |
* object {@code o} at the given {@code offset}. |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1161 |
* |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1162 |
* @param o object/array to update the field/element in |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1163 |
* @param offset field/element offset |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1164 |
* @param newValue new value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1165 |
* @return the previous value |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1166 |
* @since 1.8 |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1167 |
*/ |
36628 | 1168 |
@ForceInline |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1169 |
public final Object getAndSetObject(Object o, long offset, Object newValue) { |
36628 | 1170 |
return theInternalUnsafe.getAndSetObject(o, offset, newValue); |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1171 |
} |
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1172 |
|
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1173 |
|
14851 | 1174 |
/** |
28057
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1175 |
* Ensures that loads before the fence will not be reordered with loads and |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1176 |
* stores after the fence; a "LoadLoad plus LoadStore barrier". |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1177 |
* |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1178 |
* Corresponds to C11 atomic_thread_fence(memory_order_acquire) |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1179 |
* (an "acquire fence"). |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1180 |
* |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1181 |
* A pure LoadLoad fence is not provided, since the addition of LoadStore |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1182 |
* is almost always desired, and most current hardware instructions that |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1183 |
* provide a LoadLoad barrier also provide a LoadStore barrier for free. |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1184 |
* @since 1.8 |
14851 | 1185 |
*/ |
36628 | 1186 |
@ForceInline |
1187 |
public void loadFence() { |
|
1188 |
theInternalUnsafe.loadFence(); |
|
1189 |
} |
|
14851 | 1190 |
|
1191 |
/** |
|
28057
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1192 |
* Ensures that loads and stores before the fence will not be reordered with |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1193 |
* stores after the fence; a "StoreStore plus LoadStore barrier". |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1194 |
* |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1195 |
* Corresponds to C11 atomic_thread_fence(memory_order_release) |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1196 |
* (a "release fence"). |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1197 |
* |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1198 |
* A pure StoreStore fence is not provided, since the addition of LoadStore |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1199 |
* is almost always desired, and most current hardware instructions that |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1200 |
* provide a StoreStore barrier also provide a LoadStore barrier for free. |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1201 |
* @since 1.8 |
14851 | 1202 |
*/ |
36628 | 1203 |
@ForceInline |
1204 |
public void storeFence() { |
|
1205 |
theInternalUnsafe.storeFence(); |
|
1206 |
} |
|
14851 | 1207 |
|
1208 |
/** |
|
28057
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1209 |
* Ensures that loads and stores before the fence will not be reordered |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1210 |
* with loads and stores after the fence. Implies the effects of both |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1211 |
* loadFence() and storeFence(), and in addition, the effect of a StoreLoad |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1212 |
* barrier. |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1213 |
* |
1a47ceecdba5
8065804: JEP 171: Clarifications/corrections for fence intrinsics
martin
parents:
25859
diff
changeset
|
1214 |
* Corresponds to C11 atomic_thread_fence(memory_order_seq_cst). |
14853
72f0bc58bb95
8004330: Add missing Unsafe entry points for addAndGet() family
dl
parents:
14851
diff
changeset
|
1215 |
* @since 1.8 |
14851 | 1216 |
*/ |
36628 | 1217 |
@ForceInline |
1218 |
public void fullFence() { |
|
1219 |
theInternalUnsafe.fullFence(); |
|
21851
f21f49c7c265
8016839: JSR292: AME instead of IAE when calling a method
jrose
parents:
16906
diff
changeset
|
1220 |
} |
42707 | 1221 |
|
1222 |
/** |
|
1223 |
* Invokes the given direct byte buffer's cleaner, if any. |
|
1224 |
* |
|
1225 |
* @param directBuffer a direct byte buffer |
|
1226 |
* @throws NullPointerException if {@code directBuffer} is null |
|
1227 |
* @throws IllegalArgumentException if {@code directBuffer} is non-direct, |
|
1228 |
* or is a {@link java.nio.Buffer#slice slice}, or is a |
|
1229 |
* {@link java.nio.Buffer#duplicate duplicate} |
|
1230 |
* @since 9 |
|
1231 |
*/ |
|
1232 |
public void invokeCleaner(java.nio.ByteBuffer directBuffer) { |
|
1233 |
if (!directBuffer.isDirect()) |
|
1234 |
throw new IllegalArgumentException("buffer is non-direct"); |
|
1235 |
||
1236 |
DirectBuffer db = (DirectBuffer)directBuffer; |
|
1237 |
if (db.attachment() != null) |
|
1238 |
throw new IllegalArgumentException("duplicate or slice"); |
|
1239 |
||
1240 |
Cleaner cleaner = db.cleaner(); |
|
1241 |
if (cleaner != null) { |
|
1242 |
cleaner.clean(); |
|
1243 |
} |
|
1244 |
} |
|
2 | 1245 |
} |