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