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