Mon, 15 Oct 2018 14:58:52 +0100
Merge
duke@435 | 1 | /* |
kevinw@8368 | 2 | * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/vmSymbols.hpp" |
jprovino@4542 | 27 | #include "utilities/macros.hpp" |
jprovino@4542 | 28 | #if INCLUDE_ALL_GCS |
johnc@2781 | 29 | #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
jprovino@4542 | 30 | #endif // INCLUDE_ALL_GCS |
stefank@2314 | 31 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 32 | #include "prims/jni.h" |
stefank@2314 | 33 | #include "prims/jvm.h" |
stefank@2314 | 34 | #include "runtime/globals.hpp" |
stefank@2314 | 35 | #include "runtime/interfaceSupport.hpp" |
goetz@6912 | 36 | #include "runtime/prefetch.inline.hpp" |
goetz@6911 | 37 | #include "runtime/orderAccess.inline.hpp" |
stefank@2314 | 38 | #include "runtime/reflection.hpp" |
stefank@2314 | 39 | #include "runtime/synchronizer.hpp" |
stefank@2314 | 40 | #include "services/threadService.hpp" |
sla@5237 | 41 | #include "trace/tracing.hpp" |
stefank@2314 | 42 | #include "utilities/copy.hpp" |
stefank@2314 | 43 | #include "utilities/dtrace.hpp" |
stefank@2314 | 44 | |
drchase@6680 | 45 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 46 | |
duke@435 | 47 | /* |
duke@435 | 48 | * Implementation of class sun.misc.Unsafe |
duke@435 | 49 | */ |
duke@435 | 50 | |
dcubed@3202 | 51 | #ifndef USDT2 |
fparain@1759 | 52 | HS_DTRACE_PROBE_DECL3(hotspot, thread__park__begin, uintptr_t, int, long long); |
fparain@1759 | 53 | HS_DTRACE_PROBE_DECL1(hotspot, thread__park__end, uintptr_t); |
fparain@1759 | 54 | HS_DTRACE_PROBE_DECL1(hotspot, thread__unpark, uintptr_t); |
dcubed@3202 | 55 | #endif /* !USDT2 */ |
fparain@1759 | 56 | |
duke@435 | 57 | #define MAX_OBJECT_SIZE \ |
duke@435 | 58 | ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \ |
duke@435 | 59 | + ((julong)max_jint * sizeof(double)) ) |
duke@435 | 60 | |
duke@435 | 61 | |
duke@435 | 62 | #define UNSAFE_ENTRY(result_type, header) \ |
duke@435 | 63 | JVM_ENTRY(result_type, header) |
duke@435 | 64 | |
duke@435 | 65 | // Can't use UNSAFE_LEAF because it has the signature of a straight |
duke@435 | 66 | // call into the runtime (just like JVM_LEAF, funny that) but it's |
duke@435 | 67 | // called like a Java Native and thus the wrapper built for it passes |
duke@435 | 68 | // arguments like a JNI call. It expects those arguments to be popped |
duke@435 | 69 | // from the stack on Intel like all good JNI args are, and adjusts the |
duke@435 | 70 | // stack according. Since the JVM_LEAF call expects no extra |
duke@435 | 71 | // arguments the stack isn't popped in the C code, is pushed by the |
duke@435 | 72 | // wrapper and we get sick. |
duke@435 | 73 | //#define UNSAFE_LEAF(result_type, header) \ |
duke@435 | 74 | // JVM_LEAF(result_type, header) |
duke@435 | 75 | |
duke@435 | 76 | #define UNSAFE_END JVM_END |
duke@435 | 77 | |
duke@435 | 78 | #define UnsafeWrapper(arg) /*nothing, for the present*/ |
duke@435 | 79 | |
duke@435 | 80 | |
duke@435 | 81 | inline void* addr_from_java(jlong addr) { |
duke@435 | 82 | // This assert fails in a variety of ways on 32-bit systems. |
duke@435 | 83 | // It is impossible to predict whether native code that converts |
duke@435 | 84 | // pointers to longs will sign-extend or zero-extend the addresses. |
duke@435 | 85 | //assert(addr == (uintptr_t)addr, "must not be odd high bits"); |
duke@435 | 86 | return (void*)(uintptr_t)addr; |
duke@435 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | inline jlong addr_to_java(void* p) { |
duke@435 | 90 | assert(p == (void*)(uintptr_t)p, "must not be odd high bits"); |
duke@435 | 91 | return (uintptr_t)p; |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | |
duke@435 | 95 | // Note: The VM's obj_field and related accessors use byte-scaled |
duke@435 | 96 | // ("unscaled") offsets, just as the unsafe methods do. |
duke@435 | 97 | |
duke@435 | 98 | // However, the method Unsafe.fieldOffset explicitly declines to |
duke@435 | 99 | // guarantee this. The field offset values manipulated by the Java user |
duke@435 | 100 | // through the Unsafe API are opaque cookies that just happen to be byte |
duke@435 | 101 | // offsets. We represent this state of affairs by passing the cookies |
duke@435 | 102 | // through conversion functions when going between the VM and the Unsafe API. |
duke@435 | 103 | // The conversion functions just happen to be no-ops at present. |
duke@435 | 104 | |
duke@435 | 105 | inline jlong field_offset_to_byte_offset(jlong field_offset) { |
duke@435 | 106 | return field_offset; |
duke@435 | 107 | } |
duke@435 | 108 | |
duke@435 | 109 | inline jlong field_offset_from_byte_offset(jlong byte_offset) { |
duke@435 | 110 | return byte_offset; |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | inline jint invocation_key_from_method_slot(jint slot) { |
duke@435 | 114 | return slot; |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | inline jint invocation_key_to_method_slot(jint key) { |
duke@435 | 118 | return key; |
duke@435 | 119 | } |
duke@435 | 120 | |
duke@435 | 121 | inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) { |
duke@435 | 122 | jlong byte_offset = field_offset_to_byte_offset(field_offset); |
duke@435 | 123 | #ifdef ASSERT |
duke@435 | 124 | if (p != NULL) { |
duke@435 | 125 | assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); |
duke@435 | 126 | if (byte_offset == (jint)byte_offset) { |
duke@435 | 127 | void* ptr_plus_disp = (address)p + byte_offset; |
coleenp@548 | 128 | assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp, |
duke@435 | 129 | "raw [ptr+disp] must be consistent with oop::field_base"); |
duke@435 | 130 | } |
kvn@4200 | 131 | jlong p_size = HeapWordSize * (jlong)(p->size()); |
kvn@4200 | 132 | assert(byte_offset < p_size, err_msg("Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, byte_offset, p_size)); |
duke@435 | 133 | } |
duke@435 | 134 | #endif |
duke@435 | 135 | if (sizeof(char*) == sizeof(jint)) // (this constant folds!) |
duke@435 | 136 | return (address)p + (jint) byte_offset; |
duke@435 | 137 | else |
duke@435 | 138 | return (address)p + byte_offset; |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | // Externally callable versions: |
duke@435 | 142 | // (Use these in compiler intrinsics which emulate unsafe primitives.) |
duke@435 | 143 | jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) { |
duke@435 | 144 | return field_offset; |
duke@435 | 145 | } |
duke@435 | 146 | jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) { |
duke@435 | 147 | return byte_offset; |
duke@435 | 148 | } |
duke@435 | 149 | jint Unsafe_invocation_key_from_method_slot(jint slot) { |
duke@435 | 150 | return invocation_key_from_method_slot(slot); |
duke@435 | 151 | } |
duke@435 | 152 | jint Unsafe_invocation_key_to_method_slot(jint key) { |
duke@435 | 153 | return invocation_key_to_method_slot(key); |
duke@435 | 154 | } |
duke@435 | 155 | |
duke@435 | 156 | |
duke@435 | 157 | ///// Data in the Java heap. |
duke@435 | 158 | |
kevinw@8368 | 159 | #define truncate_jboolean(x) ((x) & 1) |
kevinw@8368 | 160 | #define truncate_jbyte(x) (x) |
kevinw@8368 | 161 | #define truncate_jshort(x) (x) |
kevinw@8368 | 162 | #define truncate_jchar(x) (x) |
kevinw@8368 | 163 | #define truncate_jint(x) (x) |
kevinw@8368 | 164 | #define truncate_jlong(x) (x) |
kevinw@8368 | 165 | #define truncate_jfloat(x) (x) |
kevinw@8368 | 166 | #define truncate_jdouble(x) (x) |
kevinw@8368 | 167 | |
duke@435 | 168 | #define GET_FIELD(obj, offset, type_name, v) \ |
duke@435 | 169 | oop p = JNIHandles::resolve(obj); \ |
duke@435 | 170 | type_name v = *(type_name*)index_oop_from_field_offset_long(p, offset) |
duke@435 | 171 | |
duke@435 | 172 | #define SET_FIELD(obj, offset, type_name, x) \ |
duke@435 | 173 | oop p = JNIHandles::resolve(obj); \ |
kevinw@8368 | 174 | *(type_name*)index_oop_from_field_offset_long(p, offset) = truncate_##type_name(x) |
duke@435 | 175 | |
duke@435 | 176 | #define GET_FIELD_VOLATILE(obj, offset, type_name, v) \ |
duke@435 | 177 | oop p = JNIHandles::resolve(obj); \ |
goetz@6502 | 178 | if (support_IRIW_for_not_multiple_copy_atomic_cpu) { \ |
goetz@6502 | 179 | OrderAccess::fence(); \ |
goetz@6502 | 180 | } \ |
kvn@2434 | 181 | volatile type_name v = OrderAccess::load_acquire((volatile type_name*)index_oop_from_field_offset_long(p, offset)); |
duke@435 | 182 | |
duke@435 | 183 | #define SET_FIELD_VOLATILE(obj, offset, type_name, x) \ |
duke@435 | 184 | oop p = JNIHandles::resolve(obj); \ |
kevinw@8368 | 185 | OrderAccess::release_store_fence((volatile type_name*)index_oop_from_field_offset_long(p, offset), truncate_##type_name(x)); |
duke@435 | 186 | |
coleenp@548 | 187 | // Macros for oops that check UseCompressedOops |
coleenp@548 | 188 | |
coleenp@548 | 189 | #define GET_OOP_FIELD(obj, offset, v) \ |
coleenp@548 | 190 | oop p = JNIHandles::resolve(obj); \ |
coleenp@548 | 191 | oop v; \ |
coleenp@548 | 192 | if (UseCompressedOops) { \ |
coleenp@548 | 193 | narrowOop n = *(narrowOop*)index_oop_from_field_offset_long(p, offset); \ |
coleenp@548 | 194 | v = oopDesc::decode_heap_oop(n); \ |
coleenp@548 | 195 | } else { \ |
coleenp@548 | 196 | v = *(oop*)index_oop_from_field_offset_long(p, offset); \ |
coleenp@548 | 197 | } |
coleenp@548 | 198 | |
coleenp@548 | 199 | |
duke@435 | 200 | // Get/SetObject must be special-cased, since it works with handles. |
duke@435 | 201 | |
mdoerr@9318 | 202 | // We could be accessing the referent field in a reference |
mdoerr@9318 | 203 | // object. If G1 is enabled then we need to register non-null |
mdoerr@9318 | 204 | // referent with the SATB barrier. |
mdoerr@9318 | 205 | |
mdoerr@9318 | 206 | #if INCLUDE_ALL_GCS |
mdoerr@9318 | 207 | static bool is_java_lang_ref_Reference_access(oop o, jlong offset) { |
mdoerr@9318 | 208 | if (offset == java_lang_ref_Reference::referent_offset && o != NULL) { |
mdoerr@9318 | 209 | Klass* k = o->klass(); |
mdoerr@9318 | 210 | if (InstanceKlass::cast(k)->reference_type() != REF_NONE) { |
mdoerr@9318 | 211 | assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); |
mdoerr@9318 | 212 | return true; |
mdoerr@9318 | 213 | } |
mdoerr@9318 | 214 | } |
mdoerr@9318 | 215 | return false; |
mdoerr@9318 | 216 | } |
mdoerr@9318 | 217 | #endif |
mdoerr@9318 | 218 | |
mdoerr@9318 | 219 | static void ensure_satb_referent_alive(oop o, jlong offset, oop v) { |
mdoerr@9318 | 220 | #if INCLUDE_ALL_GCS |
mdoerr@9318 | 221 | if (UseG1GC && v != NULL && is_java_lang_ref_Reference_access(o, offset)) { |
mdoerr@9318 | 222 | G1SATBCardTableModRefBS::enqueue(v); |
mdoerr@9318 | 223 | } |
mdoerr@9318 | 224 | #endif |
mdoerr@9318 | 225 | } |
mdoerr@9318 | 226 | |
duke@435 | 227 | // The xxx140 variants for backward compatibility do not allow a full-width offset. |
duke@435 | 228 | UNSAFE_ENTRY(jobject, Unsafe_GetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) |
duke@435 | 229 | UnsafeWrapper("Unsafe_GetObject"); |
duke@435 | 230 | if (obj == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); |
coleenp@548 | 231 | GET_OOP_FIELD(obj, offset, v) |
johnc@2781 | 232 | |
mdoerr@9318 | 233 | ensure_satb_referent_alive(p, offset, v); |
johnc@2781 | 234 | |
mdoerr@9318 | 235 | return JNIHandles::make_local(env, v); |
duke@435 | 236 | UNSAFE_END |
duke@435 | 237 | |
duke@435 | 238 | UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h)) |
duke@435 | 239 | UnsafeWrapper("Unsafe_SetObject"); |
duke@435 | 240 | if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 241 | oop x = JNIHandles::resolve(x_h); |
duke@435 | 242 | //SET_FIELD(obj, offset, oop, x); |
duke@435 | 243 | oop p = JNIHandles::resolve(obj); |
coleenp@548 | 244 | if (UseCompressedOops) { |
coleenp@548 | 245 | if (x != NULL) { |
coleenp@548 | 246 | // If there is a heap base pointer, we are obliged to emit a store barrier. |
coleenp@548 | 247 | oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); |
coleenp@548 | 248 | } else { |
coleenp@548 | 249 | narrowOop n = oopDesc::encode_heap_oop_not_null(x); |
coleenp@548 | 250 | *(narrowOop*)index_oop_from_field_offset_long(p, offset) = n; |
coleenp@548 | 251 | } |
duke@435 | 252 | } else { |
coleenp@548 | 253 | if (x != NULL) { |
coleenp@548 | 254 | // If there is a heap base pointer, we are obliged to emit a store barrier. |
coleenp@548 | 255 | oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); |
coleenp@548 | 256 | } else { |
coleenp@548 | 257 | *(oop*)index_oop_from_field_offset_long(p, offset) = x; |
coleenp@548 | 258 | } |
duke@435 | 259 | } |
duke@435 | 260 | UNSAFE_END |
duke@435 | 261 | |
duke@435 | 262 | // The normal variants allow a null base pointer with an arbitrary address. |
duke@435 | 263 | // But if the base pointer is non-null, the offset should make some sense. |
duke@435 | 264 | // That is, it should be in the range [0, MAX_OBJECT_SIZE]. |
duke@435 | 265 | UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) |
duke@435 | 266 | UnsafeWrapper("Unsafe_GetObject"); |
coleenp@548 | 267 | GET_OOP_FIELD(obj, offset, v) |
johnc@2781 | 268 | |
mdoerr@9318 | 269 | ensure_satb_referent_alive(p, offset, v); |
johnc@2781 | 270 | |
mdoerr@9318 | 271 | return JNIHandles::make_local(env, v); |
duke@435 | 272 | UNSAFE_END |
duke@435 | 273 | |
duke@435 | 274 | UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) |
duke@435 | 275 | UnsafeWrapper("Unsafe_SetObject"); |
duke@435 | 276 | oop x = JNIHandles::resolve(x_h); |
duke@435 | 277 | oop p = JNIHandles::resolve(obj); |
coleenp@548 | 278 | if (UseCompressedOops) { |
coleenp@548 | 279 | oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); |
coleenp@548 | 280 | } else { |
coleenp@548 | 281 | oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); |
coleenp@548 | 282 | } |
duke@435 | 283 | UNSAFE_END |
duke@435 | 284 | |
duke@435 | 285 | UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) |
duke@435 | 286 | UnsafeWrapper("Unsafe_GetObjectVolatile"); |
twisti@3928 | 287 | oop p = JNIHandles::resolve(obj); |
twisti@3928 | 288 | void* addr = index_oop_from_field_offset_long(p, offset); |
twisti@3928 | 289 | volatile oop v; |
twisti@3928 | 290 | if (UseCompressedOops) { |
twisti@3928 | 291 | volatile narrowOop n = *(volatile narrowOop*) addr; |
hseigel@5784 | 292 | (void)const_cast<oop&>(v = oopDesc::decode_heap_oop(n)); |
twisti@3928 | 293 | } else { |
hseigel@5784 | 294 | (void)const_cast<oop&>(v = *(volatile oop*) addr); |
twisti@3928 | 295 | } |
mdoerr@9318 | 296 | |
mdoerr@9318 | 297 | ensure_satb_referent_alive(p, offset, v); |
mdoerr@9318 | 298 | |
twisti@3928 | 299 | OrderAccess::acquire(); |
duke@435 | 300 | return JNIHandles::make_local(env, v); |
duke@435 | 301 | UNSAFE_END |
duke@435 | 302 | |
duke@435 | 303 | UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) |
duke@435 | 304 | UnsafeWrapper("Unsafe_SetObjectVolatile"); |
duke@435 | 305 | oop x = JNIHandles::resolve(x_h); |
duke@435 | 306 | oop p = JNIHandles::resolve(obj); |
kvn@2434 | 307 | void* addr = index_oop_from_field_offset_long(p, offset); |
kvn@2434 | 308 | OrderAccess::release(); |
coleenp@548 | 309 | if (UseCompressedOops) { |
kvn@2434 | 310 | oop_store((narrowOop*)addr, x); |
coleenp@548 | 311 | } else { |
kvn@2434 | 312 | oop_store((oop*)addr, x); |
coleenp@548 | 313 | } |
duke@435 | 314 | OrderAccess::fence(); |
duke@435 | 315 | UNSAFE_END |
duke@435 | 316 | |
bpittore@5067 | 317 | #ifndef SUPPORTS_NATIVE_CX8 |
kvn@2434 | 318 | |
dholmes@7547 | 319 | // VM_Version::supports_cx8() is a surrogate for 'supports atomic long memory ops'. |
dholmes@7547 | 320 | // |
dholmes@7547 | 321 | // On platforms which do not support atomic compare-and-swap of jlong (8 byte) |
dholmes@7547 | 322 | // values we have to use a lock-based scheme to enforce atomicity. This has to be |
dholmes@7547 | 323 | // applied to all Unsafe operations that set the value of a jlong field. Even so |
dholmes@7547 | 324 | // the compareAndSwapLong operation will not be atomic with respect to direct stores |
dholmes@7547 | 325 | // to the field from Java code. It is important therefore that any Java code that |
dholmes@7547 | 326 | // utilizes these Unsafe jlong operations does not perform direct stores. To permit |
dholmes@7547 | 327 | // direct loads of the field from Java code we must also use Atomic::store within the |
dholmes@7547 | 328 | // locked regions. And for good measure, in case there are direct stores, we also |
dholmes@7547 | 329 | // employ Atomic::load within those regions. Note that the field in question must be |
dholmes@7547 | 330 | // volatile and so must have atomic load/store accesses applied at the Java level. |
dholmes@7547 | 331 | // |
dholmes@7547 | 332 | // The locking scheme could utilize a range of strategies for controlling the locking |
dholmes@7547 | 333 | // granularity: from a lock per-field through to a single global lock. The latter is |
dholmes@7547 | 334 | // the simplest and is used for the current implementation. Note that the Java object |
dholmes@7547 | 335 | // that contains the field, can not, in general, be used for locking. To do so can lead |
dholmes@7547 | 336 | // to deadlocks as we may introduce locking into what appears to the Java code to be a |
dholmes@7547 | 337 | // lock-free path. |
dholmes@7547 | 338 | // |
dholmes@7547 | 339 | // As all the locked-regions are very short and themselves non-blocking we can treat |
dholmes@7547 | 340 | // them as leaf routines and elide safepoint checks (ie we don't perform any thread |
dholmes@7547 | 341 | // state transitions even when blocking for the lock). Note that if we do choose to |
dholmes@7547 | 342 | // add safepoint checks and thread state transitions, we must ensure that we calculate |
dholmes@7547 | 343 | // the address of the field _after_ we have acquired the lock, else the object may have |
dholmes@7547 | 344 | // been moved by the GC |
duke@435 | 345 | |
duke@435 | 346 | UNSAFE_ENTRY(jlong, Unsafe_GetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) |
duke@435 | 347 | UnsafeWrapper("Unsafe_GetLongVolatile"); |
duke@435 | 348 | { |
duke@435 | 349 | if (VM_Version::supports_cx8()) { |
duke@435 | 350 | GET_FIELD_VOLATILE(obj, offset, jlong, v); |
duke@435 | 351 | return v; |
duke@435 | 352 | } |
duke@435 | 353 | else { |
duke@435 | 354 | Handle p (THREAD, JNIHandles::resolve(obj)); |
duke@435 | 355 | jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
dholmes@7547 | 356 | MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
dholmes@7547 | 357 | jlong value = Atomic::load(addr); |
duke@435 | 358 | return value; |
duke@435 | 359 | } |
duke@435 | 360 | } |
duke@435 | 361 | UNSAFE_END |
duke@435 | 362 | |
duke@435 | 363 | UNSAFE_ENTRY(void, Unsafe_SetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) |
duke@435 | 364 | UnsafeWrapper("Unsafe_SetLongVolatile"); |
duke@435 | 365 | { |
duke@435 | 366 | if (VM_Version::supports_cx8()) { |
duke@435 | 367 | SET_FIELD_VOLATILE(obj, offset, jlong, x); |
duke@435 | 368 | } |
duke@435 | 369 | else { |
duke@435 | 370 | Handle p (THREAD, JNIHandles::resolve(obj)); |
duke@435 | 371 | jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
dholmes@7547 | 372 | MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
dholmes@7547 | 373 | Atomic::store(x, addr); |
duke@435 | 374 | } |
duke@435 | 375 | } |
duke@435 | 376 | UNSAFE_END |
duke@435 | 377 | |
bpittore@5067 | 378 | #endif // not SUPPORTS_NATIVE_CX8 |
duke@435 | 379 | |
duke@435 | 380 | #define DEFINE_GETSETOOP(jboolean, Boolean) \ |
duke@435 | 381 | \ |
duke@435 | 382 | UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) \ |
duke@435 | 383 | UnsafeWrapper("Unsafe_Get"#Boolean); \ |
duke@435 | 384 | if (obj == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); \ |
duke@435 | 385 | GET_FIELD(obj, offset, jboolean, v); \ |
duke@435 | 386 | return v; \ |
duke@435 | 387 | UNSAFE_END \ |
duke@435 | 388 | \ |
duke@435 | 389 | UNSAFE_ENTRY(void, Unsafe_Set##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jboolean x)) \ |
duke@435 | 390 | UnsafeWrapper("Unsafe_Set"#Boolean); \ |
duke@435 | 391 | if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); \ |
duke@435 | 392 | SET_FIELD(obj, offset, jboolean, x); \ |
duke@435 | 393 | UNSAFE_END \ |
duke@435 | 394 | \ |
duke@435 | 395 | UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \ |
duke@435 | 396 | UnsafeWrapper("Unsafe_Get"#Boolean); \ |
duke@435 | 397 | GET_FIELD(obj, offset, jboolean, v); \ |
duke@435 | 398 | return v; \ |
duke@435 | 399 | UNSAFE_END \ |
duke@435 | 400 | \ |
duke@435 | 401 | UNSAFE_ENTRY(void, Unsafe_Set##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \ |
duke@435 | 402 | UnsafeWrapper("Unsafe_Set"#Boolean); \ |
duke@435 | 403 | SET_FIELD(obj, offset, jboolean, x); \ |
duke@435 | 404 | UNSAFE_END \ |
duke@435 | 405 | \ |
duke@435 | 406 | // END DEFINE_GETSETOOP. |
duke@435 | 407 | |
kvn@2434 | 408 | DEFINE_GETSETOOP(jboolean, Boolean) |
kvn@2434 | 409 | DEFINE_GETSETOOP(jbyte, Byte) |
kvn@2434 | 410 | DEFINE_GETSETOOP(jshort, Short); |
kvn@2434 | 411 | DEFINE_GETSETOOP(jchar, Char); |
kvn@2434 | 412 | DEFINE_GETSETOOP(jint, Int); |
kvn@2434 | 413 | DEFINE_GETSETOOP(jlong, Long); |
kvn@2434 | 414 | DEFINE_GETSETOOP(jfloat, Float); |
kvn@2434 | 415 | DEFINE_GETSETOOP(jdouble, Double); |
kvn@2434 | 416 | |
kvn@2434 | 417 | #undef DEFINE_GETSETOOP |
duke@435 | 418 | |
duke@435 | 419 | #define DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) \ |
duke@435 | 420 | \ |
duke@435 | 421 | UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \ |
duke@435 | 422 | UnsafeWrapper("Unsafe_Get"#Boolean); \ |
duke@435 | 423 | GET_FIELD_VOLATILE(obj, offset, jboolean, v); \ |
duke@435 | 424 | return v; \ |
duke@435 | 425 | UNSAFE_END \ |
duke@435 | 426 | \ |
duke@435 | 427 | UNSAFE_ENTRY(void, Unsafe_Set##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \ |
duke@435 | 428 | UnsafeWrapper("Unsafe_Set"#Boolean); \ |
duke@435 | 429 | SET_FIELD_VOLATILE(obj, offset, jboolean, x); \ |
duke@435 | 430 | UNSAFE_END \ |
duke@435 | 431 | \ |
duke@435 | 432 | // END DEFINE_GETSETOOP_VOLATILE. |
duke@435 | 433 | |
duke@435 | 434 | DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) |
duke@435 | 435 | DEFINE_GETSETOOP_VOLATILE(jbyte, Byte) |
duke@435 | 436 | DEFINE_GETSETOOP_VOLATILE(jshort, Short); |
duke@435 | 437 | DEFINE_GETSETOOP_VOLATILE(jchar, Char); |
duke@435 | 438 | DEFINE_GETSETOOP_VOLATILE(jint, Int); |
duke@435 | 439 | DEFINE_GETSETOOP_VOLATILE(jfloat, Float); |
duke@435 | 440 | DEFINE_GETSETOOP_VOLATILE(jdouble, Double); |
duke@435 | 441 | |
bpittore@5067 | 442 | #ifdef SUPPORTS_NATIVE_CX8 |
kvn@2434 | 443 | DEFINE_GETSETOOP_VOLATILE(jlong, Long); |
kvn@2434 | 444 | #endif |
kvn@2434 | 445 | |
kvn@2434 | 446 | #undef DEFINE_GETSETOOP_VOLATILE |
duke@435 | 447 | |
duke@435 | 448 | // The non-intrinsified versions of setOrdered just use setVolatile |
duke@435 | 449 | |
kvn@2434 | 450 | UNSAFE_ENTRY(void, Unsafe_SetOrderedInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint x)) |
kvn@2434 | 451 | UnsafeWrapper("Unsafe_SetOrderedInt"); |
kvn@2434 | 452 | SET_FIELD_VOLATILE(obj, offset, jint, x); |
duke@435 | 453 | UNSAFE_END |
duke@435 | 454 | |
duke@435 | 455 | UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) |
duke@435 | 456 | UnsafeWrapper("Unsafe_SetOrderedObject"); |
duke@435 | 457 | oop x = JNIHandles::resolve(x_h); |
duke@435 | 458 | oop p = JNIHandles::resolve(obj); |
kvn@2434 | 459 | void* addr = index_oop_from_field_offset_long(p, offset); |
kvn@2434 | 460 | OrderAccess::release(); |
coleenp@548 | 461 | if (UseCompressedOops) { |
kvn@2434 | 462 | oop_store((narrowOop*)addr, x); |
coleenp@548 | 463 | } else { |
kvn@2434 | 464 | oop_store((oop*)addr, x); |
coleenp@548 | 465 | } |
duke@435 | 466 | OrderAccess::fence(); |
duke@435 | 467 | UNSAFE_END |
duke@435 | 468 | |
duke@435 | 469 | UNSAFE_ENTRY(void, Unsafe_SetOrderedLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) |
duke@435 | 470 | UnsafeWrapper("Unsafe_SetOrderedLong"); |
bpittore@5067 | 471 | #ifdef SUPPORTS_NATIVE_CX8 |
kvn@2434 | 472 | SET_FIELD_VOLATILE(obj, offset, jlong, x); |
kvn@2434 | 473 | #else |
kvn@2434 | 474 | // Keep old code for platforms which may not have atomic long (8 bytes) instructions |
duke@435 | 475 | { |
duke@435 | 476 | if (VM_Version::supports_cx8()) { |
duke@435 | 477 | SET_FIELD_VOLATILE(obj, offset, jlong, x); |
duke@435 | 478 | } |
duke@435 | 479 | else { |
duke@435 | 480 | Handle p (THREAD, JNIHandles::resolve(obj)); |
duke@435 | 481 | jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
dholmes@7547 | 482 | MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
dholmes@7547 | 483 | Atomic::store(x, addr); |
duke@435 | 484 | } |
duke@435 | 485 | } |
kvn@2434 | 486 | #endif |
duke@435 | 487 | UNSAFE_END |
duke@435 | 488 | |
kvn@4361 | 489 | UNSAFE_ENTRY(void, Unsafe_LoadFence(JNIEnv *env, jobject unsafe)) |
kvn@4361 | 490 | UnsafeWrapper("Unsafe_LoadFence"); |
kvn@4361 | 491 | OrderAccess::acquire(); |
kvn@4361 | 492 | UNSAFE_END |
kvn@4361 | 493 | |
kvn@4361 | 494 | UNSAFE_ENTRY(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) |
kvn@4361 | 495 | UnsafeWrapper("Unsafe_StoreFence"); |
kvn@4361 | 496 | OrderAccess::release(); |
kvn@4361 | 497 | UNSAFE_END |
kvn@4361 | 498 | |
kvn@4361 | 499 | UNSAFE_ENTRY(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) |
kvn@4361 | 500 | UnsafeWrapper("Unsafe_FullFence"); |
kvn@4361 | 501 | OrderAccess::fence(); |
kvn@4361 | 502 | UNSAFE_END |
kvn@4361 | 503 | |
duke@435 | 504 | ////// Data in the C heap. |
duke@435 | 505 | |
duke@435 | 506 | // Note: These do not throw NullPointerException for bad pointers. |
duke@435 | 507 | // They just crash. Only a oop base pointer can generate a NullPointerException. |
duke@435 | 508 | // |
duke@435 | 509 | #define DEFINE_GETSETNATIVE(java_type, Type, native_type) \ |
duke@435 | 510 | \ |
duke@435 | 511 | UNSAFE_ENTRY(java_type, Unsafe_GetNative##Type(JNIEnv *env, jobject unsafe, jlong addr)) \ |
duke@435 | 512 | UnsafeWrapper("Unsafe_GetNative"#Type); \ |
duke@435 | 513 | void* p = addr_from_java(addr); \ |
duke@435 | 514 | JavaThread* t = JavaThread::current(); \ |
duke@435 | 515 | t->set_doing_unsafe_access(true); \ |
duke@435 | 516 | java_type x = *(volatile native_type*)p; \ |
duke@435 | 517 | t->set_doing_unsafe_access(false); \ |
duke@435 | 518 | return x; \ |
duke@435 | 519 | UNSAFE_END \ |
duke@435 | 520 | \ |
duke@435 | 521 | UNSAFE_ENTRY(void, Unsafe_SetNative##Type(JNIEnv *env, jobject unsafe, jlong addr, java_type x)) \ |
duke@435 | 522 | UnsafeWrapper("Unsafe_SetNative"#Type); \ |
duke@435 | 523 | JavaThread* t = JavaThread::current(); \ |
duke@435 | 524 | t->set_doing_unsafe_access(true); \ |
duke@435 | 525 | void* p = addr_from_java(addr); \ |
duke@435 | 526 | *(volatile native_type*)p = x; \ |
duke@435 | 527 | t->set_doing_unsafe_access(false); \ |
duke@435 | 528 | UNSAFE_END \ |
duke@435 | 529 | \ |
duke@435 | 530 | // END DEFINE_GETSETNATIVE. |
duke@435 | 531 | |
duke@435 | 532 | DEFINE_GETSETNATIVE(jbyte, Byte, signed char) |
duke@435 | 533 | DEFINE_GETSETNATIVE(jshort, Short, signed short); |
duke@435 | 534 | DEFINE_GETSETNATIVE(jchar, Char, unsigned short); |
duke@435 | 535 | DEFINE_GETSETNATIVE(jint, Int, jint); |
duke@435 | 536 | // no long -- handled specially |
duke@435 | 537 | DEFINE_GETSETNATIVE(jfloat, Float, float); |
duke@435 | 538 | DEFINE_GETSETNATIVE(jdouble, Double, double); |
duke@435 | 539 | |
duke@435 | 540 | #undef DEFINE_GETSETNATIVE |
duke@435 | 541 | |
duke@435 | 542 | UNSAFE_ENTRY(jlong, Unsafe_GetNativeLong(JNIEnv *env, jobject unsafe, jlong addr)) |
duke@435 | 543 | UnsafeWrapper("Unsafe_GetNativeLong"); |
duke@435 | 544 | JavaThread* t = JavaThread::current(); |
duke@435 | 545 | // We do it this way to avoid problems with access to heap using 64 |
duke@435 | 546 | // bit loads, as jlong in heap could be not 64-bit aligned, and on |
duke@435 | 547 | // some CPUs (SPARC) it leads to SIGBUS. |
duke@435 | 548 | t->set_doing_unsafe_access(true); |
duke@435 | 549 | void* p = addr_from_java(addr); |
duke@435 | 550 | jlong x; |
duke@435 | 551 | if (((intptr_t)p & 7) == 0) { |
duke@435 | 552 | // jlong is aligned, do a volatile access |
duke@435 | 553 | x = *(volatile jlong*)p; |
duke@435 | 554 | } else { |
duke@435 | 555 | jlong_accessor acc; |
duke@435 | 556 | acc.words[0] = ((volatile jint*)p)[0]; |
duke@435 | 557 | acc.words[1] = ((volatile jint*)p)[1]; |
duke@435 | 558 | x = acc.long_value; |
duke@435 | 559 | } |
duke@435 | 560 | t->set_doing_unsafe_access(false); |
duke@435 | 561 | return x; |
duke@435 | 562 | UNSAFE_END |
duke@435 | 563 | |
duke@435 | 564 | UNSAFE_ENTRY(void, Unsafe_SetNativeLong(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) |
duke@435 | 565 | UnsafeWrapper("Unsafe_SetNativeLong"); |
duke@435 | 566 | JavaThread* t = JavaThread::current(); |
duke@435 | 567 | // see comment for Unsafe_GetNativeLong |
duke@435 | 568 | t->set_doing_unsafe_access(true); |
duke@435 | 569 | void* p = addr_from_java(addr); |
duke@435 | 570 | if (((intptr_t)p & 7) == 0) { |
duke@435 | 571 | // jlong is aligned, do a volatile access |
duke@435 | 572 | *(volatile jlong*)p = x; |
duke@435 | 573 | } else { |
duke@435 | 574 | jlong_accessor acc; |
duke@435 | 575 | acc.long_value = x; |
duke@435 | 576 | ((volatile jint*)p)[0] = acc.words[0]; |
duke@435 | 577 | ((volatile jint*)p)[1] = acc.words[1]; |
duke@435 | 578 | } |
duke@435 | 579 | t->set_doing_unsafe_access(false); |
duke@435 | 580 | UNSAFE_END |
duke@435 | 581 | |
duke@435 | 582 | |
duke@435 | 583 | UNSAFE_ENTRY(jlong, Unsafe_GetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr)) |
duke@435 | 584 | UnsafeWrapper("Unsafe_GetNativeAddress"); |
duke@435 | 585 | void* p = addr_from_java(addr); |
duke@435 | 586 | return addr_to_java(*(void**)p); |
duke@435 | 587 | UNSAFE_END |
duke@435 | 588 | |
duke@435 | 589 | UNSAFE_ENTRY(void, Unsafe_SetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) |
duke@435 | 590 | UnsafeWrapper("Unsafe_SetNativeAddress"); |
duke@435 | 591 | void* p = addr_from_java(addr); |
duke@435 | 592 | *(void**)p = addr_from_java(x); |
duke@435 | 593 | UNSAFE_END |
duke@435 | 594 | |
duke@435 | 595 | |
duke@435 | 596 | ////// Allocation requests |
duke@435 | 597 | |
duke@435 | 598 | UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) |
duke@435 | 599 | UnsafeWrapper("Unsafe_AllocateInstance"); |
duke@435 | 600 | { |
duke@435 | 601 | ThreadToNativeFromVM ttnfv(thread); |
duke@435 | 602 | return env->AllocObject(cls); |
duke@435 | 603 | } |
duke@435 | 604 | UNSAFE_END |
duke@435 | 605 | |
duke@435 | 606 | UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory(JNIEnv *env, jobject unsafe, jlong size)) |
duke@435 | 607 | UnsafeWrapper("Unsafe_AllocateMemory"); |
duke@435 | 608 | size_t sz = (size_t)size; |
duke@435 | 609 | if (sz != (julong)size || size < 0) { |
duke@435 | 610 | THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 611 | } |
duke@435 | 612 | if (sz == 0) { |
duke@435 | 613 | return 0; |
duke@435 | 614 | } |
duke@435 | 615 | sz = round_to(sz, HeapWordSize); |
zgu@3900 | 616 | void* x = os::malloc(sz, mtInternal); |
duke@435 | 617 | if (x == NULL) { |
duke@435 | 618 | THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
duke@435 | 619 | } |
duke@435 | 620 | //Copy::fill_to_words((HeapWord*)x, sz / HeapWordSize); |
duke@435 | 621 | return addr_to_java(x); |
duke@435 | 622 | UNSAFE_END |
duke@435 | 623 | |
duke@435 | 624 | UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) |
duke@435 | 625 | UnsafeWrapper("Unsafe_ReallocateMemory"); |
duke@435 | 626 | void* p = addr_from_java(addr); |
duke@435 | 627 | size_t sz = (size_t)size; |
duke@435 | 628 | if (sz != (julong)size || size < 0) { |
duke@435 | 629 | THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 630 | } |
duke@435 | 631 | if (sz == 0) { |
duke@435 | 632 | os::free(p); |
duke@435 | 633 | return 0; |
duke@435 | 634 | } |
duke@435 | 635 | sz = round_to(sz, HeapWordSize); |
zgu@3900 | 636 | void* x = (p == NULL) ? os::malloc(sz, mtInternal) : os::realloc(p, sz, mtInternal); |
duke@435 | 637 | if (x == NULL) { |
duke@435 | 638 | THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
duke@435 | 639 | } |
duke@435 | 640 | return addr_to_java(x); |
duke@435 | 641 | UNSAFE_END |
duke@435 | 642 | |
duke@435 | 643 | UNSAFE_ENTRY(void, Unsafe_FreeMemory(JNIEnv *env, jobject unsafe, jlong addr)) |
duke@435 | 644 | UnsafeWrapper("Unsafe_FreeMemory"); |
duke@435 | 645 | void* p = addr_from_java(addr); |
duke@435 | 646 | if (p == NULL) { |
duke@435 | 647 | return; |
duke@435 | 648 | } |
duke@435 | 649 | os::free(p); |
duke@435 | 650 | UNSAFE_END |
duke@435 | 651 | |
duke@435 | 652 | UNSAFE_ENTRY(void, Unsafe_SetMemory(JNIEnv *env, jobject unsafe, jlong addr, jlong size, jbyte value)) |
duke@435 | 653 | UnsafeWrapper("Unsafe_SetMemory"); |
duke@435 | 654 | size_t sz = (size_t)size; |
duke@435 | 655 | if (sz != (julong)size || size < 0) { |
duke@435 | 656 | THROW(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 657 | } |
duke@435 | 658 | char* p = (char*) addr_from_java(addr); |
duke@435 | 659 | Copy::fill_to_memory_atomic(p, sz, value); |
duke@435 | 660 | UNSAFE_END |
duke@435 | 661 | |
duke@435 | 662 | UNSAFE_ENTRY(void, Unsafe_SetMemory2(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) |
duke@435 | 663 | UnsafeWrapper("Unsafe_SetMemory"); |
duke@435 | 664 | size_t sz = (size_t)size; |
duke@435 | 665 | if (sz != (julong)size || size < 0) { |
duke@435 | 666 | THROW(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 667 | } |
duke@435 | 668 | oop base = JNIHandles::resolve(obj); |
duke@435 | 669 | void* p = index_oop_from_field_offset_long(base, offset); |
duke@435 | 670 | Copy::fill_to_memory_atomic(p, sz, value); |
duke@435 | 671 | UNSAFE_END |
duke@435 | 672 | |
duke@435 | 673 | UNSAFE_ENTRY(void, Unsafe_CopyMemory(JNIEnv *env, jobject unsafe, jlong srcAddr, jlong dstAddr, jlong size)) |
duke@435 | 674 | UnsafeWrapper("Unsafe_CopyMemory"); |
duke@435 | 675 | if (size == 0) { |
duke@435 | 676 | return; |
duke@435 | 677 | } |
duke@435 | 678 | size_t sz = (size_t)size; |
duke@435 | 679 | if (sz != (julong)size || size < 0) { |
duke@435 | 680 | THROW(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 681 | } |
duke@435 | 682 | void* src = addr_from_java(srcAddr); |
duke@435 | 683 | void* dst = addr_from_java(dstAddr); |
duke@435 | 684 | Copy::conjoint_memory_atomic(src, dst, sz); |
duke@435 | 685 | UNSAFE_END |
duke@435 | 686 | |
duke@435 | 687 | UNSAFE_ENTRY(void, Unsafe_CopyMemory2(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) |
duke@435 | 688 | UnsafeWrapper("Unsafe_CopyMemory"); |
duke@435 | 689 | if (size == 0) { |
duke@435 | 690 | return; |
duke@435 | 691 | } |
duke@435 | 692 | size_t sz = (size_t)size; |
duke@435 | 693 | if (sz != (julong)size || size < 0) { |
duke@435 | 694 | THROW(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 695 | } |
duke@435 | 696 | oop srcp = JNIHandles::resolve(srcObj); |
duke@435 | 697 | oop dstp = JNIHandles::resolve(dstObj); |
duke@435 | 698 | if (dstp != NULL && !dstp->is_typeArray()) { |
duke@435 | 699 | // NYI: This works only for non-oop arrays at present. |
duke@435 | 700 | // Generalizing it would be reasonable, but requires card marking. |
duke@435 | 701 | // Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad. |
duke@435 | 702 | THROW(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 703 | } |
duke@435 | 704 | void* src = index_oop_from_field_offset_long(srcp, srcOffset); |
duke@435 | 705 | void* dst = index_oop_from_field_offset_long(dstp, dstOffset); |
duke@435 | 706 | Copy::conjoint_memory_atomic(src, dst, sz); |
duke@435 | 707 | UNSAFE_END |
duke@435 | 708 | |
duke@435 | 709 | |
duke@435 | 710 | ////// Random queries |
duke@435 | 711 | |
duke@435 | 712 | // See comment at file start about UNSAFE_LEAF |
duke@435 | 713 | //UNSAFE_LEAF(jint, Unsafe_AddressSize()) |
duke@435 | 714 | UNSAFE_ENTRY(jint, Unsafe_AddressSize(JNIEnv *env, jobject unsafe)) |
duke@435 | 715 | UnsafeWrapper("Unsafe_AddressSize"); |
duke@435 | 716 | return sizeof(void*); |
duke@435 | 717 | UNSAFE_END |
duke@435 | 718 | |
duke@435 | 719 | // See comment at file start about UNSAFE_LEAF |
duke@435 | 720 | //UNSAFE_LEAF(jint, Unsafe_PageSize()) |
duke@435 | 721 | UNSAFE_ENTRY(jint, Unsafe_PageSize(JNIEnv *env, jobject unsafe)) |
duke@435 | 722 | UnsafeWrapper("Unsafe_PageSize"); |
duke@435 | 723 | return os::vm_page_size(); |
duke@435 | 724 | UNSAFE_END |
duke@435 | 725 | |
duke@435 | 726 | jint find_field_offset(jobject field, int must_be_static, TRAPS) { |
duke@435 | 727 | if (field == NULL) { |
duke@435 | 728 | THROW_0(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 729 | } |
duke@435 | 730 | |
duke@435 | 731 | oop reflected = JNIHandles::resolve_non_null(field); |
duke@435 | 732 | oop mirror = java_lang_reflect_Field::clazz(reflected); |
coleenp@4037 | 733 | Klass* k = java_lang_Class::as_Klass(mirror); |
duke@435 | 734 | int slot = java_lang_reflect_Field::slot(reflected); |
duke@435 | 735 | int modifiers = java_lang_reflect_Field::modifiers(reflected); |
duke@435 | 736 | |
duke@435 | 737 | if (must_be_static >= 0) { |
duke@435 | 738 | int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0); |
duke@435 | 739 | if (must_be_static != really_is_static) { |
duke@435 | 740 | THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 741 | } |
duke@435 | 742 | } |
duke@435 | 743 | |
coleenp@4037 | 744 | int offset = InstanceKlass::cast(k)->field_offset(slot); |
duke@435 | 745 | return field_offset_from_byte_offset(offset); |
duke@435 | 746 | } |
duke@435 | 747 | |
duke@435 | 748 | UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset(JNIEnv *env, jobject unsafe, jobject field)) |
duke@435 | 749 | UnsafeWrapper("Unsafe_ObjectFieldOffset"); |
duke@435 | 750 | return find_field_offset(field, 0, THREAD); |
duke@435 | 751 | UNSAFE_END |
duke@435 | 752 | |
duke@435 | 753 | UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset(JNIEnv *env, jobject unsafe, jobject field)) |
duke@435 | 754 | UnsafeWrapper("Unsafe_StaticFieldOffset"); |
duke@435 | 755 | return find_field_offset(field, 1, THREAD); |
duke@435 | 756 | UNSAFE_END |
duke@435 | 757 | |
duke@435 | 758 | UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBaseFromField(JNIEnv *env, jobject unsafe, jobject field)) |
duke@435 | 759 | UnsafeWrapper("Unsafe_StaticFieldBase"); |
duke@435 | 760 | // Note: In this VM implementation, a field address is always a short |
duke@435 | 761 | // offset from the base of a a klass metaobject. Thus, the full dynamic |
duke@435 | 762 | // range of the return type is never used. However, some implementations |
duke@435 | 763 | // might put the static field inside an array shared by many classes, |
duke@435 | 764 | // or even at a fixed address, in which case the address could be quite |
duke@435 | 765 | // large. In that last case, this function would return NULL, since |
duke@435 | 766 | // the address would operate alone, without any base pointer. |
duke@435 | 767 | |
duke@435 | 768 | if (field == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 769 | |
duke@435 | 770 | oop reflected = JNIHandles::resolve_non_null(field); |
duke@435 | 771 | oop mirror = java_lang_reflect_Field::clazz(reflected); |
duke@435 | 772 | int modifiers = java_lang_reflect_Field::modifiers(reflected); |
duke@435 | 773 | |
duke@435 | 774 | if ((modifiers & JVM_ACC_STATIC) == 0) { |
duke@435 | 775 | THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
duke@435 | 776 | } |
duke@435 | 777 | |
never@2658 | 778 | return JNIHandles::make_local(env, mirror); |
duke@435 | 779 | UNSAFE_END |
duke@435 | 780 | |
duke@435 | 781 | //@deprecated |
duke@435 | 782 | UNSAFE_ENTRY(jint, Unsafe_FieldOffset(JNIEnv *env, jobject unsafe, jobject field)) |
duke@435 | 783 | UnsafeWrapper("Unsafe_FieldOffset"); |
duke@435 | 784 | // tries (but fails) to be polymorphic between static and non-static: |
duke@435 | 785 | jlong offset = find_field_offset(field, -1, THREAD); |
duke@435 | 786 | guarantee(offset == (jint)offset, "offset fits in 32 bits"); |
duke@435 | 787 | return (jint)offset; |
duke@435 | 788 | UNSAFE_END |
duke@435 | 789 | |
duke@435 | 790 | //@deprecated |
duke@435 | 791 | UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBaseFromClass(JNIEnv *env, jobject unsafe, jobject clazz)) |
duke@435 | 792 | UnsafeWrapper("Unsafe_StaticFieldBase"); |
duke@435 | 793 | if (clazz == NULL) { |
duke@435 | 794 | THROW_0(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 795 | } |
never@2658 | 796 | return JNIHandles::make_local(env, JNIHandles::resolve_non_null(clazz)); |
duke@435 | 797 | UNSAFE_END |
duke@435 | 798 | |
twisti@3969 | 799 | UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized(JNIEnv *env, jobject unsafe, jobject clazz)) { |
duke@435 | 800 | UnsafeWrapper("Unsafe_EnsureClassInitialized"); |
duke@435 | 801 | if (clazz == NULL) { |
duke@435 | 802 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 803 | } |
duke@435 | 804 | oop mirror = JNIHandles::resolve_non_null(clazz); |
twisti@3969 | 805 | |
coleenp@4037 | 806 | Klass* klass = java_lang_Class::as_Klass(mirror); |
hseigel@4278 | 807 | if (klass != NULL && klass->should_be_initialized()) { |
coleenp@4037 | 808 | InstanceKlass* k = InstanceKlass::cast(klass); |
duke@435 | 809 | k->initialize(CHECK); |
duke@435 | 810 | } |
twisti@3969 | 811 | } |
twisti@3969 | 812 | UNSAFE_END |
twisti@3969 | 813 | |
twisti@3969 | 814 | UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized(JNIEnv *env, jobject unsafe, jobject clazz)) { |
twisti@3969 | 815 | UnsafeWrapper("Unsafe_ShouldBeInitialized"); |
twisti@3969 | 816 | if (clazz == NULL) { |
twisti@3969 | 817 | THROW_(vmSymbols::java_lang_NullPointerException(), false); |
twisti@3969 | 818 | } |
twisti@3969 | 819 | oop mirror = JNIHandles::resolve_non_null(clazz); |
coleenp@4037 | 820 | Klass* klass = java_lang_Class::as_Klass(mirror); |
hseigel@4278 | 821 | if (klass != NULL && klass->should_be_initialized()) { |
twisti@3969 | 822 | return true; |
twisti@3969 | 823 | } |
twisti@3969 | 824 | return false; |
twisti@3969 | 825 | } |
duke@435 | 826 | UNSAFE_END |
duke@435 | 827 | |
duke@435 | 828 | static void getBaseAndScale(int& base, int& scale, jclass acls, TRAPS) { |
duke@435 | 829 | if (acls == NULL) { |
duke@435 | 830 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 831 | } |
duke@435 | 832 | oop mirror = JNIHandles::resolve_non_null(acls); |
coleenp@4037 | 833 | Klass* k = java_lang_Class::as_Klass(mirror); |
coleenp@4037 | 834 | if (k == NULL || !k->oop_is_array()) { |
duke@435 | 835 | THROW(vmSymbols::java_lang_InvalidClassException()); |
coleenp@4037 | 836 | } else if (k->oop_is_objArray()) { |
duke@435 | 837 | base = arrayOopDesc::base_offset_in_bytes(T_OBJECT); |
coleenp@548 | 838 | scale = heapOopSize; |
coleenp@4037 | 839 | } else if (k->oop_is_typeArray()) { |
coleenp@4142 | 840 | TypeArrayKlass* tak = TypeArrayKlass::cast(k); |
duke@435 | 841 | base = tak->array_header_in_bytes(); |
duke@435 | 842 | assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok"); |
duke@435 | 843 | scale = (1 << tak->log2_element_size()); |
duke@435 | 844 | } else { |
duke@435 | 845 | ShouldNotReachHere(); |
duke@435 | 846 | } |
duke@435 | 847 | } |
duke@435 | 848 | |
duke@435 | 849 | UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset(JNIEnv *env, jobject unsafe, jclass acls)) |
duke@435 | 850 | UnsafeWrapper("Unsafe_ArrayBaseOffset"); |
csahu@8316 | 851 | int base = 0, scale = 0; |
duke@435 | 852 | getBaseAndScale(base, scale, acls, CHECK_0); |
duke@435 | 853 | return field_offset_from_byte_offset(base); |
duke@435 | 854 | UNSAFE_END |
duke@435 | 855 | |
duke@435 | 856 | |
duke@435 | 857 | UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale(JNIEnv *env, jobject unsafe, jclass acls)) |
duke@435 | 858 | UnsafeWrapper("Unsafe_ArrayIndexScale"); |
csahu@8316 | 859 | int base = 0, scale = 0; |
duke@435 | 860 | getBaseAndScale(base, scale, acls, CHECK_0); |
duke@435 | 861 | // This VM packs both fields and array elements down to the byte. |
duke@435 | 862 | // But watch out: If this changes, so that array references for |
duke@435 | 863 | // a given primitive type (say, T_BOOLEAN) use different memory units |
duke@435 | 864 | // than fields, this method MUST return zero for such arrays. |
duke@435 | 865 | // For example, the VM used to store sub-word sized fields in full |
duke@435 | 866 | // words in the object layout, so that accessors like getByte(Object,int) |
duke@435 | 867 | // did not really do what one might expect for arrays. Therefore, |
duke@435 | 868 | // this function used to report a zero scale factor, so that the user |
duke@435 | 869 | // would know not to attempt to access sub-word array elements. |
duke@435 | 870 | // // Code for unpacked fields: |
duke@435 | 871 | // if (scale < wordSize) return 0; |
duke@435 | 872 | |
duke@435 | 873 | // The following allows for a pretty general fieldOffset cookie scheme, |
duke@435 | 874 | // but requires it to be linear in byte offset. |
duke@435 | 875 | return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); |
duke@435 | 876 | UNSAFE_END |
duke@435 | 877 | |
duke@435 | 878 | |
duke@435 | 879 | static inline void throw_new(JNIEnv *env, const char *ename) { |
duke@435 | 880 | char buf[100]; |
duke@435 | 881 | strcpy(buf, "java/lang/"); |
duke@435 | 882 | strcat(buf, ename); |
duke@435 | 883 | jclass cls = env->FindClass(buf); |
ccheung@6346 | 884 | if (env->ExceptionCheck()) { |
ccheung@6346 | 885 | env->ExceptionClear(); |
ccheung@6346 | 886 | tty->print_cr("Unsafe: cannot throw %s because FindClass has failed", buf); |
ccheung@6346 | 887 | return; |
ccheung@6346 | 888 | } |
duke@435 | 889 | char* msg = NULL; |
duke@435 | 890 | env->ThrowNew(cls, msg); |
duke@435 | 891 | } |
duke@435 | 892 | |
twisti@4866 | 893 | static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { |
duke@435 | 894 | { |
duke@435 | 895 | // Code lifted from JDK 1.3 ClassLoader.c |
duke@435 | 896 | |
duke@435 | 897 | jbyte *body; |
duke@435 | 898 | char *utfName; |
duke@435 | 899 | jclass result = 0; |
duke@435 | 900 | char buf[128]; |
duke@435 | 901 | |
duke@435 | 902 | if (UsePerfData) { |
duke@435 | 903 | ClassLoader::unsafe_defineClassCallCounter()->inc(); |
duke@435 | 904 | } |
duke@435 | 905 | |
duke@435 | 906 | if (data == NULL) { |
duke@435 | 907 | throw_new(env, "NullPointerException"); |
duke@435 | 908 | return 0; |
duke@435 | 909 | } |
duke@435 | 910 | |
duke@435 | 911 | /* Work around 4153825. malloc crashes on Solaris when passed a |
duke@435 | 912 | * negative size. |
duke@435 | 913 | */ |
duke@435 | 914 | if (length < 0) { |
duke@435 | 915 | throw_new(env, "ArrayIndexOutOfBoundsException"); |
duke@435 | 916 | return 0; |
duke@435 | 917 | } |
duke@435 | 918 | |
zgu@3900 | 919 | body = NEW_C_HEAP_ARRAY(jbyte, length, mtInternal); |
duke@435 | 920 | |
duke@435 | 921 | if (body == 0) { |
duke@435 | 922 | throw_new(env, "OutOfMemoryError"); |
duke@435 | 923 | return 0; |
duke@435 | 924 | } |
duke@435 | 925 | |
duke@435 | 926 | env->GetByteArrayRegion(data, offset, length, body); |
duke@435 | 927 | |
duke@435 | 928 | if (env->ExceptionOccurred()) |
duke@435 | 929 | goto free_body; |
duke@435 | 930 | |
duke@435 | 931 | if (name != NULL) { |
duke@435 | 932 | uint len = env->GetStringUTFLength(name); |
duke@435 | 933 | int unicode_len = env->GetStringLength(name); |
duke@435 | 934 | if (len >= sizeof(buf)) { |
zgu@3900 | 935 | utfName = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |
duke@435 | 936 | if (utfName == NULL) { |
duke@435 | 937 | throw_new(env, "OutOfMemoryError"); |
duke@435 | 938 | goto free_body; |
duke@435 | 939 | } |
duke@435 | 940 | } else { |
duke@435 | 941 | utfName = buf; |
duke@435 | 942 | } |
duke@435 | 943 | env->GetStringUTFRegion(name, 0, unicode_len, utfName); |
duke@435 | 944 | //VerifyFixClassname(utfName); |
duke@435 | 945 | for (uint i = 0; i < len; i++) { |
duke@435 | 946 | if (utfName[i] == '.') utfName[i] = '/'; |
duke@435 | 947 | } |
duke@435 | 948 | } else { |
duke@435 | 949 | utfName = NULL; |
duke@435 | 950 | } |
duke@435 | 951 | |
duke@435 | 952 | result = JVM_DefineClass(env, utfName, loader, body, length, pd); |
duke@435 | 953 | |
duke@435 | 954 | if (utfName && utfName != buf) |
zgu@3900 | 955 | FREE_C_HEAP_ARRAY(char, utfName, mtInternal); |
duke@435 | 956 | |
duke@435 | 957 | free_body: |
zgu@3900 | 958 | FREE_C_HEAP_ARRAY(jbyte, body, mtInternal); |
duke@435 | 959 | return result; |
duke@435 | 960 | } |
duke@435 | 961 | } |
duke@435 | 962 | |
duke@435 | 963 | |
twisti@4866 | 964 | UNSAFE_ENTRY(jclass, Unsafe_DefineClass(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd)) |
twisti@4866 | 965 | UnsafeWrapper("Unsafe_DefineClass"); |
twisti@4866 | 966 | { |
twisti@4866 | 967 | ThreadToNativeFromVM ttnfv(thread); |
twisti@4866 | 968 | return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd); |
twisti@4866 | 969 | } |
twisti@4866 | 970 | UNSAFE_END |
twisti@4866 | 971 | |
twisti@4866 | 972 | |
duke@435 | 973 | UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length)) |
duke@435 | 974 | UnsafeWrapper("Unsafe_DefineClass"); |
duke@435 | 975 | { |
duke@435 | 976 | ThreadToNativeFromVM ttnfv(thread); |
duke@435 | 977 | |
duke@435 | 978 | int depthFromDefineClass0 = 1; |
duke@435 | 979 | jclass caller = JVM_GetCallerClass(env, depthFromDefineClass0); |
coleenp@8638 | 980 | jobject loader = (caller == NULL) ? NULL : JVM_GetClassLoader(env, caller); |
duke@435 | 981 | jobject pd = (caller == NULL) ? NULL : JVM_GetProtectionDomain(env, caller); |
duke@435 | 982 | |
twisti@4866 | 983 | return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd); |
duke@435 | 984 | } |
duke@435 | 985 | UNSAFE_END |
duke@435 | 986 | |
duke@435 | 987 | |
jrose@866 | 988 | #define DAC_Args CLS"[B["OBJ |
jrose@866 | 989 | // define a class but do not make it known to the class loader or system dictionary |
jrose@866 | 990 | // - host_class: supplies context for linkage, access control, protection domain, and class loader |
jrose@866 | 991 | // - data: bytes of a class file, a raw memory address (length gives the number of bytes) |
jrose@866 | 992 | // - cp_patches: where non-null entries exist, they replace corresponding CP entries in data |
jrose@866 | 993 | |
jrose@866 | 994 | // When you load an anonymous class U, it works as if you changed its name just before loading, |
jrose@866 | 995 | // to a name that you will never use again. Since the name is lost, no other class can directly |
jrose@866 | 996 | // link to any member of U. Just after U is loaded, the only way to use it is reflectively, |
jrose@866 | 997 | // through java.lang.Class methods like Class.newInstance. |
jrose@866 | 998 | |
jrose@866 | 999 | // Access checks for linkage sites within U continue to follow the same rules as for named classes. |
jrose@866 | 1000 | // The package of an anonymous class is given by the package qualifier on the name under which it was loaded. |
jrose@866 | 1001 | // An anonymous class also has special privileges to access any member of its host class. |
jrose@866 | 1002 | // This is the main reason why this loading operation is unsafe. The purpose of this is to |
jrose@866 | 1003 | // allow language implementations to simulate "open classes"; a host class in effect gets |
jrose@866 | 1004 | // new code when an anonymous class is loaded alongside it. A less convenient but more |
jrose@866 | 1005 | // standard way to do this is with reflection, which can also be set to ignore access |
jrose@866 | 1006 | // restrictions. |
jrose@866 | 1007 | |
jrose@866 | 1008 | // Access into an anonymous class is possible only through reflection. Therefore, there |
jrose@866 | 1009 | // are no special access rules for calling into an anonymous class. The relaxed access |
jrose@866 | 1010 | // rule for the host class is applied in the opposite direction: A host class reflectively |
jrose@866 | 1011 | // access one of its anonymous classes. |
jrose@866 | 1012 | |
jrose@866 | 1013 | // If you load the same bytecodes twice, you get two different classes. You can reload |
jrose@866 | 1014 | // the same bytecodes with or without varying CP patches. |
jrose@866 | 1015 | |
jrose@866 | 1016 | // By using the CP patching array, you can have a new anonymous class U2 refer to an older one U1. |
jrose@866 | 1017 | // The bytecodes for U2 should refer to U1 by a symbolic name (doesn't matter what the name is). |
jrose@866 | 1018 | // The CONSTANT_Class entry for that name can be patched to refer directly to U1. |
jrose@866 | 1019 | |
jrose@866 | 1020 | // This allows, for example, U2 to use U1 as a superclass or super-interface, or as |
jrose@866 | 1021 | // an outer class (so that U2 is an anonymous inner class of anonymous U1). |
jrose@866 | 1022 | // It is not possible for a named class, or an older anonymous class, to refer by |
jrose@866 | 1023 | // name (via its CP) to a newer anonymous class. |
jrose@866 | 1024 | |
jrose@866 | 1025 | // CP patching may also be used to modify (i.e., hack) the names of methods, classes, |
jrose@866 | 1026 | // or type descriptors used in the loaded anonymous class. |
jrose@866 | 1027 | |
jrose@866 | 1028 | // Finally, CP patching may be used to introduce "live" objects into the constant pool, |
jrose@866 | 1029 | // instead of "dead" strings. A compiled statement like println((Object)"hello") can |
jrose@866 | 1030 | // be changed to println(greeting), where greeting is an arbitrary object created before |
jrose@866 | 1031 | // the anonymous class is loaded. This is useful in dynamic languages, in which |
jrose@866 | 1032 | // various kinds of metaobjects must be introduced as constants into bytecode. |
jrose@866 | 1033 | // Note the cast (Object), which tells the verifier to expect an arbitrary object, |
jrose@866 | 1034 | // not just a literal string. For such ldc instructions, the verifier uses the |
jrose@866 | 1035 | // type Object instead of String, if the loaded constant is not in fact a String. |
jrose@866 | 1036 | |
coleenp@4304 | 1037 | static instanceKlassHandle |
jrose@866 | 1038 | Unsafe_DefineAnonymousClass_impl(JNIEnv *env, |
jrose@866 | 1039 | jclass host_class, jbyteArray data, jobjectArray cp_patches_jh, |
jrose@866 | 1040 | HeapWord* *temp_alloc, |
jrose@866 | 1041 | TRAPS) { |
jrose@866 | 1042 | |
jrose@866 | 1043 | if (UsePerfData) { |
jrose@866 | 1044 | ClassLoader::unsafe_defineClassCallCounter()->inc(); |
jrose@866 | 1045 | } |
jrose@866 | 1046 | |
jrose@866 | 1047 | if (data == NULL) { |
jrose@866 | 1048 | THROW_0(vmSymbols::java_lang_NullPointerException()); |
jrose@866 | 1049 | } |
jrose@866 | 1050 | |
jrose@866 | 1051 | jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length(); |
jrose@866 | 1052 | jint word_length = (length + sizeof(HeapWord)-1) / sizeof(HeapWord); |
zgu@3900 | 1053 | HeapWord* body = NEW_C_HEAP_ARRAY(HeapWord, word_length, mtInternal); |
jrose@866 | 1054 | if (body == NULL) { |
jrose@866 | 1055 | THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
jrose@866 | 1056 | } |
jrose@866 | 1057 | |
jrose@866 | 1058 | // caller responsible to free it: |
jrose@866 | 1059 | (*temp_alloc) = body; |
jrose@866 | 1060 | |
jrose@866 | 1061 | { |
jrose@866 | 1062 | jbyte* array_base = typeArrayOop(JNIHandles::resolve_non_null(data))->byte_at_addr(0); |
jrose@866 | 1063 | Copy::conjoint_words((HeapWord*) array_base, body, word_length); |
jrose@866 | 1064 | } |
jrose@866 | 1065 | |
jrose@866 | 1066 | u1* class_bytes = (u1*) body; |
jrose@866 | 1067 | int class_bytes_length = (int) length; |
jrose@866 | 1068 | if (class_bytes_length < 0) class_bytes_length = 0; |
jrose@866 | 1069 | if (class_bytes == NULL |
jrose@866 | 1070 | || host_class == NULL |
jrose@866 | 1071 | || length != class_bytes_length) |
jrose@866 | 1072 | THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
jrose@866 | 1073 | |
jrose@866 | 1074 | objArrayHandle cp_patches_h; |
jrose@866 | 1075 | if (cp_patches_jh != NULL) { |
jrose@866 | 1076 | oop p = JNIHandles::resolve_non_null(cp_patches_jh); |
jrose@866 | 1077 | if (!p->is_objArray()) |
jrose@866 | 1078 | THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
jrose@866 | 1079 | cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p); |
jrose@866 | 1080 | } |
jrose@866 | 1081 | |
coleenp@4037 | 1082 | KlassHandle host_klass(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(host_class))); |
jrose@866 | 1083 | const char* host_source = host_klass->external_name(); |
jrose@866 | 1084 | Handle host_loader(THREAD, host_klass->class_loader()); |
jrose@866 | 1085 | Handle host_domain(THREAD, host_klass->protection_domain()); |
jrose@866 | 1086 | |
jrose@866 | 1087 | GrowableArray<Handle>* cp_patches = NULL; |
jrose@866 | 1088 | if (cp_patches_h.not_null()) { |
jrose@866 | 1089 | int alen = cp_patches_h->length(); |
jrose@866 | 1090 | for (int i = alen-1; i >= 0; i--) { |
jrose@866 | 1091 | oop p = cp_patches_h->obj_at(i); |
jrose@866 | 1092 | if (p != NULL) { |
jrose@866 | 1093 | Handle patch(THREAD, p); |
jrose@866 | 1094 | if (cp_patches == NULL) |
jrose@866 | 1095 | cp_patches = new GrowableArray<Handle>(i+1, i+1, Handle()); |
jrose@866 | 1096 | cp_patches->at_put(i, patch); |
jrose@866 | 1097 | } |
jrose@866 | 1098 | } |
jrose@866 | 1099 | } |
jrose@866 | 1100 | |
jrose@866 | 1101 | ClassFileStream st(class_bytes, class_bytes_length, (char*) host_source); |
jrose@866 | 1102 | |
jrose@866 | 1103 | instanceKlassHandle anon_klass; |
jrose@866 | 1104 | { |
coleenp@2497 | 1105 | Symbol* no_class_name = NULL; |
coleenp@4037 | 1106 | Klass* anonk = SystemDictionary::parse_stream(no_class_name, |
jrose@866 | 1107 | host_loader, host_domain, |
jrose@866 | 1108 | &st, host_klass, cp_patches, |
jrose@866 | 1109 | CHECK_NULL); |
jrose@866 | 1110 | if (anonk == NULL) return NULL; |
jrose@866 | 1111 | anon_klass = instanceKlassHandle(THREAD, anonk); |
jrose@866 | 1112 | } |
jrose@866 | 1113 | |
coleenp@4304 | 1114 | return anon_klass; |
jrose@866 | 1115 | } |
jrose@866 | 1116 | |
jrose@866 | 1117 | UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) |
jrose@866 | 1118 | { |
coleenp@4304 | 1119 | instanceKlassHandle anon_klass; |
coleenp@4304 | 1120 | jobject res_jh = NULL; |
coleenp@4304 | 1121 | |
jrose@866 | 1122 | UnsafeWrapper("Unsafe_DefineAnonymousClass"); |
jrose@866 | 1123 | ResourceMark rm(THREAD); |
jrose@866 | 1124 | |
jrose@866 | 1125 | HeapWord* temp_alloc = NULL; |
jrose@866 | 1126 | |
coleenp@4304 | 1127 | anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, |
coleenp@4304 | 1128 | cp_patches_jh, |
jrose@866 | 1129 | &temp_alloc, THREAD); |
coleenp@4304 | 1130 | if (anon_klass() != NULL) |
coleenp@4304 | 1131 | res_jh = JNIHandles::make_local(env, anon_klass->java_mirror()); |
jrose@866 | 1132 | |
jrose@866 | 1133 | // try/finally clause: |
jrose@866 | 1134 | if (temp_alloc != NULL) { |
zgu@3900 | 1135 | FREE_C_HEAP_ARRAY(HeapWord, temp_alloc, mtInternal); |
jrose@866 | 1136 | } |
jrose@866 | 1137 | |
coleenp@4304 | 1138 | // The anonymous class loader data has been artificially been kept alive to |
coleenp@4304 | 1139 | // this point. The mirror and any instances of this class have to keep |
coleenp@4304 | 1140 | // it alive afterwards. |
coleenp@4304 | 1141 | if (anon_klass() != NULL) { |
coleenp@4304 | 1142 | anon_klass->class_loader_data()->set_keep_alive(false); |
coleenp@4304 | 1143 | } |
coleenp@4304 | 1144 | |
coleenp@4304 | 1145 | // let caller initialize it as needed... |
coleenp@4304 | 1146 | |
jrose@866 | 1147 | return (jclass) res_jh; |
jrose@866 | 1148 | } |
jrose@866 | 1149 | UNSAFE_END |
jrose@866 | 1150 | |
jrose@866 | 1151 | |
duke@435 | 1152 | |
duke@435 | 1153 | UNSAFE_ENTRY(void, Unsafe_MonitorEnter(JNIEnv *env, jobject unsafe, jobject jobj)) |
duke@435 | 1154 | UnsafeWrapper("Unsafe_MonitorEnter"); |
duke@435 | 1155 | { |
duke@435 | 1156 | if (jobj == NULL) { |
duke@435 | 1157 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 1158 | } |
duke@435 | 1159 | Handle obj(thread, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 1160 | ObjectSynchronizer::jni_enter(obj, CHECK); |
duke@435 | 1161 | } |
duke@435 | 1162 | UNSAFE_END |
duke@435 | 1163 | |
duke@435 | 1164 | |
duke@435 | 1165 | UNSAFE_ENTRY(jboolean, Unsafe_TryMonitorEnter(JNIEnv *env, jobject unsafe, jobject jobj)) |
duke@435 | 1166 | UnsafeWrapper("Unsafe_TryMonitorEnter"); |
duke@435 | 1167 | { |
duke@435 | 1168 | if (jobj == NULL) { |
duke@435 | 1169 | THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); |
duke@435 | 1170 | } |
duke@435 | 1171 | Handle obj(thread, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 1172 | bool res = ObjectSynchronizer::jni_try_enter(obj, CHECK_0); |
duke@435 | 1173 | return (res ? JNI_TRUE : JNI_FALSE); |
duke@435 | 1174 | } |
duke@435 | 1175 | UNSAFE_END |
duke@435 | 1176 | |
duke@435 | 1177 | |
duke@435 | 1178 | UNSAFE_ENTRY(void, Unsafe_MonitorExit(JNIEnv *env, jobject unsafe, jobject jobj)) |
duke@435 | 1179 | UnsafeWrapper("Unsafe_MonitorExit"); |
duke@435 | 1180 | { |
duke@435 | 1181 | if (jobj == NULL) { |
duke@435 | 1182 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 1183 | } |
duke@435 | 1184 | Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 1185 | ObjectSynchronizer::jni_exit(obj(), CHECK); |
duke@435 | 1186 | } |
duke@435 | 1187 | UNSAFE_END |
duke@435 | 1188 | |
duke@435 | 1189 | |
duke@435 | 1190 | UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) |
duke@435 | 1191 | UnsafeWrapper("Unsafe_ThrowException"); |
duke@435 | 1192 | { |
duke@435 | 1193 | ThreadToNativeFromVM ttnfv(thread); |
duke@435 | 1194 | env->Throw(thr); |
duke@435 | 1195 | } |
duke@435 | 1196 | UNSAFE_END |
duke@435 | 1197 | |
duke@435 | 1198 | // JSR166 ------------------------------------------------------------------ |
duke@435 | 1199 | |
duke@435 | 1200 | UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) |
duke@435 | 1201 | UnsafeWrapper("Unsafe_CompareAndSwapObject"); |
duke@435 | 1202 | oop x = JNIHandles::resolve(x_h); |
duke@435 | 1203 | oop e = JNIHandles::resolve(e_h); |
duke@435 | 1204 | oop p = JNIHandles::resolve(obj); |
coleenp@548 | 1205 | HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset); |
coleenp@4037 | 1206 | oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e, true); |
coleenp@548 | 1207 | jboolean success = (res == e); |
duke@435 | 1208 | if (success) |
coleenp@548 | 1209 | update_barrier_set((void*)addr, x); |
duke@435 | 1210 | return success; |
duke@435 | 1211 | UNSAFE_END |
duke@435 | 1212 | |
duke@435 | 1213 | UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) |
duke@435 | 1214 | UnsafeWrapper("Unsafe_CompareAndSwapInt"); |
duke@435 | 1215 | oop p = JNIHandles::resolve(obj); |
duke@435 | 1216 | jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); |
duke@435 | 1217 | return (jint)(Atomic::cmpxchg(x, addr, e)) == e; |
duke@435 | 1218 | UNSAFE_END |
duke@435 | 1219 | |
duke@435 | 1220 | UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) |
duke@435 | 1221 | UnsafeWrapper("Unsafe_CompareAndSwapLong"); |
duke@435 | 1222 | Handle p (THREAD, JNIHandles::resolve(obj)); |
duke@435 | 1223 | jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
dholmes@7547 | 1224 | #ifdef SUPPORTS_NATIVE_CX8 |
dholmes@7547 | 1225 | return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; |
dholmes@7547 | 1226 | #else |
duke@435 | 1227 | if (VM_Version::supports_cx8()) |
duke@435 | 1228 | return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; |
duke@435 | 1229 | else { |
duke@435 | 1230 | jboolean success = false; |
dholmes@7547 | 1231 | MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
dholmes@7547 | 1232 | jlong val = Atomic::load(addr); |
dholmes@7547 | 1233 | if (val == e) { Atomic::store(x, addr); success = true; } |
duke@435 | 1234 | return success; |
duke@435 | 1235 | } |
dholmes@7547 | 1236 | #endif |
duke@435 | 1237 | UNSAFE_END |
duke@435 | 1238 | |
duke@435 | 1239 | UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) |
duke@435 | 1240 | UnsafeWrapper("Unsafe_Park"); |
sla@5237 | 1241 | EventThreadPark event; |
dcubed@3202 | 1242 | #ifndef USDT2 |
fparain@1759 | 1243 | HS_DTRACE_PROBE3(hotspot, thread__park__begin, thread->parker(), (int) isAbsolute, time); |
dcubed@3202 | 1244 | #else /* USDT2 */ |
dcubed@3202 | 1245 | HOTSPOT_THREAD_PARK_BEGIN( |
dcubed@3202 | 1246 | (uintptr_t) thread->parker(), (int) isAbsolute, time); |
dcubed@3202 | 1247 | #endif /* USDT2 */ |
duke@435 | 1248 | JavaThreadParkedState jtps(thread, time != 0); |
duke@435 | 1249 | thread->parker()->park(isAbsolute != 0, time); |
dcubed@3202 | 1250 | #ifndef USDT2 |
fparain@1759 | 1251 | HS_DTRACE_PROBE1(hotspot, thread__park__end, thread->parker()); |
dcubed@3202 | 1252 | #else /* USDT2 */ |
dcubed@3202 | 1253 | HOTSPOT_THREAD_PARK_END( |
dcubed@3202 | 1254 | (uintptr_t) thread->parker()); |
dcubed@3202 | 1255 | #endif /* USDT2 */ |
sla@5237 | 1256 | if (event.should_commit()) { |
sla@5237 | 1257 | oop obj = thread->current_park_blocker(); |
hseigel@5784 | 1258 | event.set_klass((obj != NULL) ? obj->klass() : NULL); |
sla@5237 | 1259 | event.set_timeout(time); |
hseigel@5784 | 1260 | event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0); |
sla@5237 | 1261 | event.commit(); |
sla@5237 | 1262 | } |
duke@435 | 1263 | UNSAFE_END |
duke@435 | 1264 | |
duke@435 | 1265 | UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) |
duke@435 | 1266 | UnsafeWrapper("Unsafe_Unpark"); |
duke@435 | 1267 | Parker* p = NULL; |
duke@435 | 1268 | if (jthread != NULL) { |
duke@435 | 1269 | oop java_thread = JNIHandles::resolve_non_null(jthread); |
duke@435 | 1270 | if (java_thread != NULL) { |
duke@435 | 1271 | jlong lp = java_lang_Thread::park_event(java_thread); |
duke@435 | 1272 | if (lp != 0) { |
duke@435 | 1273 | // This cast is OK even though the jlong might have been read |
duke@435 | 1274 | // non-atomically on 32bit systems, since there, one word will |
duke@435 | 1275 | // always be zero anyway and the value set is always the same |
duke@435 | 1276 | p = (Parker*)addr_from_java(lp); |
duke@435 | 1277 | } else { |
duke@435 | 1278 | // Grab lock if apparently null or using older version of library |
duke@435 | 1279 | MutexLocker mu(Threads_lock); |
duke@435 | 1280 | java_thread = JNIHandles::resolve_non_null(jthread); |
duke@435 | 1281 | if (java_thread != NULL) { |
duke@435 | 1282 | JavaThread* thr = java_lang_Thread::thread(java_thread); |
duke@435 | 1283 | if (thr != NULL) { |
duke@435 | 1284 | p = thr->parker(); |
duke@435 | 1285 | if (p != NULL) { // Bind to Java thread for next time. |
duke@435 | 1286 | java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); |
duke@435 | 1287 | } |
duke@435 | 1288 | } |
duke@435 | 1289 | } |
duke@435 | 1290 | } |
duke@435 | 1291 | } |
duke@435 | 1292 | } |
duke@435 | 1293 | if (p != NULL) { |
dcubed@3202 | 1294 | #ifndef USDT2 |
fparain@1759 | 1295 | HS_DTRACE_PROBE1(hotspot, thread__unpark, p); |
dcubed@3202 | 1296 | #else /* USDT2 */ |
dcubed@3202 | 1297 | HOTSPOT_THREAD_UNPARK( |
dcubed@3202 | 1298 | (uintptr_t) p); |
dcubed@3202 | 1299 | #endif /* USDT2 */ |
duke@435 | 1300 | p->unpark(); |
duke@435 | 1301 | } |
duke@435 | 1302 | UNSAFE_END |
duke@435 | 1303 | |
duke@435 | 1304 | UNSAFE_ENTRY(jint, Unsafe_Loadavg(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) |
duke@435 | 1305 | UnsafeWrapper("Unsafe_Loadavg"); |
duke@435 | 1306 | const int max_nelem = 3; |
duke@435 | 1307 | double la[max_nelem]; |
duke@435 | 1308 | jint ret; |
duke@435 | 1309 | |
duke@435 | 1310 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); |
duke@435 | 1311 | assert(a->is_typeArray(), "must be type array"); |
duke@435 | 1312 | |
duke@435 | 1313 | if (nelem < 0 || nelem > max_nelem || a->length() < nelem) { |
duke@435 | 1314 | ThreadToNativeFromVM ttnfv(thread); |
duke@435 | 1315 | throw_new(env, "ArrayIndexOutOfBoundsException"); |
duke@435 | 1316 | return -1; |
duke@435 | 1317 | } |
duke@435 | 1318 | |
duke@435 | 1319 | ret = os::loadavg(la, nelem); |
duke@435 | 1320 | if (ret == -1) return -1; |
duke@435 | 1321 | |
duke@435 | 1322 | // if successful, ret is the number of samples actually retrieved. |
duke@435 | 1323 | assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); |
duke@435 | 1324 | switch(ret) { |
duke@435 | 1325 | case 3: a->double_at_put(2, (jdouble)la[2]); // fall through |
duke@435 | 1326 | case 2: a->double_at_put(1, (jdouble)la[1]); // fall through |
duke@435 | 1327 | case 1: a->double_at_put(0, (jdouble)la[0]); break; |
duke@435 | 1328 | } |
duke@435 | 1329 | return ret; |
duke@435 | 1330 | UNSAFE_END |
duke@435 | 1331 | |
duke@435 | 1332 | UNSAFE_ENTRY(void, Unsafe_PrefetchRead(JNIEnv* env, jclass ignored, jobject obj, jlong offset)) |
duke@435 | 1333 | UnsafeWrapper("Unsafe_PrefetchRead"); |
duke@435 | 1334 | oop p = JNIHandles::resolve(obj); |
duke@435 | 1335 | void* addr = index_oop_from_field_offset_long(p, 0); |
duke@435 | 1336 | Prefetch::read(addr, (intx)offset); |
duke@435 | 1337 | UNSAFE_END |
duke@435 | 1338 | |
duke@435 | 1339 | UNSAFE_ENTRY(void, Unsafe_PrefetchWrite(JNIEnv* env, jclass ignored, jobject obj, jlong offset)) |
duke@435 | 1340 | UnsafeWrapper("Unsafe_PrefetchWrite"); |
duke@435 | 1341 | oop p = JNIHandles::resolve(obj); |
duke@435 | 1342 | void* addr = index_oop_from_field_offset_long(p, 0); |
duke@435 | 1343 | Prefetch::write(addr, (intx)offset); |
duke@435 | 1344 | UNSAFE_END |
duke@435 | 1345 | |
duke@435 | 1346 | |
duke@435 | 1347 | /// JVM_RegisterUnsafeMethods |
duke@435 | 1348 | |
duke@435 | 1349 | #define ADR "J" |
duke@435 | 1350 | |
duke@435 | 1351 | #define LANG "Ljava/lang/" |
duke@435 | 1352 | |
kevinw@9327 | 1353 | #define OBJ LANG "Object;" |
kevinw@9327 | 1354 | #define CLS LANG "Class;" |
kevinw@9327 | 1355 | #define CTR LANG "reflect/Constructor;" |
kevinw@9327 | 1356 | #define FLD LANG "reflect/Field;" |
kevinw@9327 | 1357 | #define MTH LANG "reflect/Method;" |
kevinw@9327 | 1358 | #define THR LANG "Throwable;" |
duke@435 | 1359 | |
kevinw@9327 | 1360 | #define DC0_Args LANG "String;[BII" |
kevinw@9327 | 1361 | #define DC_Args DC0_Args LANG "ClassLoader;" "Ljava/security/ProtectionDomain;" |
duke@435 | 1362 | |
duke@435 | 1363 | #define CC (char*) /*cast a literal from (const char*)*/ |
duke@435 | 1364 | #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
duke@435 | 1365 | |
duke@435 | 1366 | // define deprecated accessors for compabitility with 1.4.0 |
duke@435 | 1367 | #define DECLARE_GETSETOOP_140(Boolean, Z) \ |
kevinw@9327 | 1368 | {CC "get" #Boolean, CC "(" OBJ "I)" #Z, FN_PTR(Unsafe_Get##Boolean##140)}, \ |
kevinw@9327 | 1369 | {CC "put" #Boolean, CC "(" OBJ "I" #Z ")V", FN_PTR(Unsafe_Set##Boolean##140)} |
duke@435 | 1370 | |
duke@435 | 1371 | // Note: In 1.4.1, getObject and kin take both int and long offsets. |
duke@435 | 1372 | #define DECLARE_GETSETOOP_141(Boolean, Z) \ |
kevinw@9327 | 1373 | {CC "get" #Boolean, CC "(" OBJ "J)" #Z, FN_PTR(Unsafe_Get##Boolean)}, \ |
kevinw@9327 | 1374 | {CC "put" #Boolean, CC "(" OBJ "J" #Z ")V", FN_PTR(Unsafe_Set##Boolean)} |
duke@435 | 1375 | |
duke@435 | 1376 | // Note: In 1.5.0, there are volatile versions too |
duke@435 | 1377 | #define DECLARE_GETSETOOP(Boolean, Z) \ |
kevinw@9327 | 1378 | {CC "get" #Boolean, CC "(" OBJ "J)" #Z, FN_PTR(Unsafe_Get##Boolean)}, \ |
kevinw@9327 | 1379 | {CC "put" #Boolean, CC "(" OBJ "J" #Z ")V", FN_PTR(Unsafe_Set##Boolean)}, \ |
kevinw@9327 | 1380 | {CC "get" #Boolean "Volatile", CC "(" OBJ "J)" #Z, FN_PTR(Unsafe_Get##Boolean##Volatile)}, \ |
kevinw@9327 | 1381 | {CC "put" #Boolean "Volatile", CC "(" OBJ "J" #Z ")V", FN_PTR(Unsafe_Set##Boolean##Volatile)} |
duke@435 | 1382 | |
duke@435 | 1383 | |
duke@435 | 1384 | #define DECLARE_GETSETNATIVE(Byte, B) \ |
kevinw@9327 | 1385 | {CC "get" #Byte, CC "(" ADR ")" #B, FN_PTR(Unsafe_GetNative##Byte)}, \ |
kevinw@9327 | 1386 | {CC "put" #Byte, CC "(" ADR#B ")V", FN_PTR(Unsafe_SetNative##Byte)} |
duke@435 | 1387 | |
duke@435 | 1388 | |
duke@435 | 1389 | |
twisti@4866 | 1390 | // These are the methods for 1.4.0 |
duke@435 | 1391 | static JNINativeMethod methods_140[] = { |
kevinw@9327 | 1392 | {CC "getObject", CC "(" OBJ "I)" OBJ "", FN_PTR(Unsafe_GetObject140)}, |
kevinw@9327 | 1393 | {CC "putObject", CC "(" OBJ "I" OBJ ")V", FN_PTR(Unsafe_SetObject140)}, |
duke@435 | 1394 | |
duke@435 | 1395 | DECLARE_GETSETOOP_140(Boolean, Z), |
duke@435 | 1396 | DECLARE_GETSETOOP_140(Byte, B), |
duke@435 | 1397 | DECLARE_GETSETOOP_140(Short, S), |
duke@435 | 1398 | DECLARE_GETSETOOP_140(Char, C), |
duke@435 | 1399 | DECLARE_GETSETOOP_140(Int, I), |
duke@435 | 1400 | DECLARE_GETSETOOP_140(Long, J), |
duke@435 | 1401 | DECLARE_GETSETOOP_140(Float, F), |
duke@435 | 1402 | DECLARE_GETSETOOP_140(Double, D), |
duke@435 | 1403 | |
duke@435 | 1404 | DECLARE_GETSETNATIVE(Byte, B), |
duke@435 | 1405 | DECLARE_GETSETNATIVE(Short, S), |
duke@435 | 1406 | DECLARE_GETSETNATIVE(Char, C), |
duke@435 | 1407 | DECLARE_GETSETNATIVE(Int, I), |
duke@435 | 1408 | DECLARE_GETSETNATIVE(Long, J), |
duke@435 | 1409 | DECLARE_GETSETNATIVE(Float, F), |
duke@435 | 1410 | DECLARE_GETSETNATIVE(Double, D), |
duke@435 | 1411 | |
kevinw@9327 | 1412 | {CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
kevinw@9327 | 1413 | {CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)}, |
duke@435 | 1414 | |
kevinw@9327 | 1415 | {CC "allocateMemory", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory)}, |
kevinw@9327 | 1416 | {CC "reallocateMemory", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory)}, |
kevinw@9327 | 1417 | {CC "freeMemory", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory)}, |
duke@435 | 1418 | |
kevinw@9327 | 1419 | {CC "fieldOffset", CC "(" FLD ")I", FN_PTR(Unsafe_FieldOffset)}, |
kevinw@9327 | 1420 | {CC "staticFieldBase", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_StaticFieldBaseFromClass)}, |
kevinw@9327 | 1421 | {CC "ensureClassInitialized",CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized)}, |
kevinw@9327 | 1422 | {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)}, |
kevinw@9327 | 1423 | {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)}, |
kevinw@9327 | 1424 | {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)}, |
kevinw@9327 | 1425 | {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
duke@435 | 1426 | |
kevinw@9327 | 1427 | {CC "defineClass", CC "(" DC0_Args ")" CLS, FN_PTR(Unsafe_DefineClass0)}, |
kevinw@9327 | 1428 | {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)}, |
kevinw@9327 | 1429 | {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
kevinw@9327 | 1430 | {CC "monitorEnter", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorEnter)}, |
kevinw@9327 | 1431 | {CC "monitorExit", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorExit)}, |
kevinw@9327 | 1432 | {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)} |
duke@435 | 1433 | }; |
duke@435 | 1434 | |
twisti@4866 | 1435 | // These are the methods prior to the JSR 166 changes in 1.5.0 |
duke@435 | 1436 | static JNINativeMethod methods_141[] = { |
kevinw@9327 | 1437 | {CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)}, |
kevinw@9327 | 1438 | {CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)}, |
duke@435 | 1439 | |
duke@435 | 1440 | DECLARE_GETSETOOP_141(Boolean, Z), |
duke@435 | 1441 | DECLARE_GETSETOOP_141(Byte, B), |
duke@435 | 1442 | DECLARE_GETSETOOP_141(Short, S), |
duke@435 | 1443 | DECLARE_GETSETOOP_141(Char, C), |
duke@435 | 1444 | DECLARE_GETSETOOP_141(Int, I), |
duke@435 | 1445 | DECLARE_GETSETOOP_141(Long, J), |
duke@435 | 1446 | DECLARE_GETSETOOP_141(Float, F), |
duke@435 | 1447 | DECLARE_GETSETOOP_141(Double, D), |
duke@435 | 1448 | |
duke@435 | 1449 | DECLARE_GETSETNATIVE(Byte, B), |
duke@435 | 1450 | DECLARE_GETSETNATIVE(Short, S), |
duke@435 | 1451 | DECLARE_GETSETNATIVE(Char, C), |
duke@435 | 1452 | DECLARE_GETSETNATIVE(Int, I), |
duke@435 | 1453 | DECLARE_GETSETNATIVE(Long, J), |
duke@435 | 1454 | DECLARE_GETSETNATIVE(Float, F), |
duke@435 | 1455 | DECLARE_GETSETNATIVE(Double, D), |
duke@435 | 1456 | |
kevinw@9327 | 1457 | {CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
kevinw@9327 | 1458 | {CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)}, |
duke@435 | 1459 | |
kevinw@9327 | 1460 | {CC "allocateMemory", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory)}, |
kevinw@9327 | 1461 | {CC "reallocateMemory", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory)}, |
kevinw@9327 | 1462 | {CC "freeMemory", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory)}, |
duke@435 | 1463 | |
kevinw@9327 | 1464 | {CC "objectFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset)}, |
kevinw@9327 | 1465 | {CC "staticFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset)}, |
kevinw@9327 | 1466 | {CC "staticFieldBase", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, |
kevinw@9327 | 1467 | {CC "ensureClassInitialized",CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized)}, |
kevinw@9327 | 1468 | {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)}, |
kevinw@9327 | 1469 | {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)}, |
kevinw@9327 | 1470 | {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)}, |
kevinw@9327 | 1471 | {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
duke@435 | 1472 | |
kevinw@9327 | 1473 | {CC "defineClass", CC "(" DC0_Args ")" CLS, FN_PTR(Unsafe_DefineClass0)}, |
kevinw@9327 | 1474 | {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)}, |
kevinw@9327 | 1475 | {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
kevinw@9327 | 1476 | {CC "monitorEnter", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorEnter)}, |
kevinw@9327 | 1477 | {CC "monitorExit", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorExit)}, |
kevinw@9327 | 1478 | {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)} |
duke@435 | 1479 | |
duke@435 | 1480 | }; |
duke@435 | 1481 | |
twisti@4866 | 1482 | // These are the methods prior to the JSR 166 changes in 1.6.0 |
duke@435 | 1483 | static JNINativeMethod methods_15[] = { |
kevinw@9327 | 1484 | {CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)}, |
kevinw@9327 | 1485 | {CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)}, |
kevinw@9327 | 1486 | {CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)}, |
kevinw@9327 | 1487 | {CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObjectVolatile)}, |
duke@435 | 1488 | |
duke@435 | 1489 | |
duke@435 | 1490 | DECLARE_GETSETOOP(Boolean, Z), |
duke@435 | 1491 | DECLARE_GETSETOOP(Byte, B), |
duke@435 | 1492 | DECLARE_GETSETOOP(Short, S), |
duke@435 | 1493 | DECLARE_GETSETOOP(Char, C), |
duke@435 | 1494 | DECLARE_GETSETOOP(Int, I), |
duke@435 | 1495 | DECLARE_GETSETOOP(Long, J), |
duke@435 | 1496 | DECLARE_GETSETOOP(Float, F), |
duke@435 | 1497 | DECLARE_GETSETOOP(Double, D), |
duke@435 | 1498 | |
duke@435 | 1499 | DECLARE_GETSETNATIVE(Byte, B), |
duke@435 | 1500 | DECLARE_GETSETNATIVE(Short, S), |
duke@435 | 1501 | DECLARE_GETSETNATIVE(Char, C), |
duke@435 | 1502 | DECLARE_GETSETNATIVE(Int, I), |
duke@435 | 1503 | DECLARE_GETSETNATIVE(Long, J), |
duke@435 | 1504 | DECLARE_GETSETNATIVE(Float, F), |
duke@435 | 1505 | DECLARE_GETSETNATIVE(Double, D), |
duke@435 | 1506 | |
kevinw@9327 | 1507 | {CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
kevinw@9327 | 1508 | {CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)}, |
duke@435 | 1509 | |
kevinw@9327 | 1510 | {CC "allocateMemory", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory)}, |
kevinw@9327 | 1511 | {CC "reallocateMemory", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory)}, |
kevinw@9327 | 1512 | {CC "freeMemory", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory)}, |
duke@435 | 1513 | |
kevinw@9327 | 1514 | {CC "objectFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset)}, |
kevinw@9327 | 1515 | {CC "staticFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset)}, |
kevinw@9327 | 1516 | {CC "staticFieldBase", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, |
kevinw@9327 | 1517 | {CC "ensureClassInitialized",CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized)}, |
kevinw@9327 | 1518 | {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)}, |
kevinw@9327 | 1519 | {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)}, |
kevinw@9327 | 1520 | {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)}, |
kevinw@9327 | 1521 | {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
duke@435 | 1522 | |
kevinw@9327 | 1523 | {CC "defineClass", CC "(" DC0_Args ")" CLS, FN_PTR(Unsafe_DefineClass0)}, |
kevinw@9327 | 1524 | {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)}, |
kevinw@9327 | 1525 | {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
kevinw@9327 | 1526 | {CC "monitorEnter", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorEnter)}, |
kevinw@9327 | 1527 | {CC "monitorExit", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorExit)}, |
kevinw@9327 | 1528 | {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)}, |
kevinw@9327 | 1529 | {CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, |
kevinw@9327 | 1530 | {CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, |
kevinw@9327 | 1531 | {CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, |
kevinw@9327 | 1532 | {CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)}, |
kevinw@9327 | 1533 | {CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)} |
duke@435 | 1534 | |
duke@435 | 1535 | }; |
duke@435 | 1536 | |
twisti@4866 | 1537 | // These are the methods for 1.6.0 and 1.7.0 |
twisti@4866 | 1538 | static JNINativeMethod methods_16[] = { |
kevinw@9327 | 1539 | {CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)}, |
kevinw@9327 | 1540 | {CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)}, |
kevinw@9327 | 1541 | {CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)}, |
kevinw@9327 | 1542 | {CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObjectVolatile)}, |
duke@435 | 1543 | |
duke@435 | 1544 | DECLARE_GETSETOOP(Boolean, Z), |
duke@435 | 1545 | DECLARE_GETSETOOP(Byte, B), |
duke@435 | 1546 | DECLARE_GETSETOOP(Short, S), |
duke@435 | 1547 | DECLARE_GETSETOOP(Char, C), |
duke@435 | 1548 | DECLARE_GETSETOOP(Int, I), |
duke@435 | 1549 | DECLARE_GETSETOOP(Long, J), |
duke@435 | 1550 | DECLARE_GETSETOOP(Float, F), |
duke@435 | 1551 | DECLARE_GETSETOOP(Double, D), |
duke@435 | 1552 | |
duke@435 | 1553 | DECLARE_GETSETNATIVE(Byte, B), |
duke@435 | 1554 | DECLARE_GETSETNATIVE(Short, S), |
duke@435 | 1555 | DECLARE_GETSETNATIVE(Char, C), |
duke@435 | 1556 | DECLARE_GETSETNATIVE(Int, I), |
duke@435 | 1557 | DECLARE_GETSETNATIVE(Long, J), |
duke@435 | 1558 | DECLARE_GETSETNATIVE(Float, F), |
duke@435 | 1559 | DECLARE_GETSETNATIVE(Double, D), |
duke@435 | 1560 | |
kevinw@9327 | 1561 | {CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
kevinw@9327 | 1562 | {CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)}, |
duke@435 | 1563 | |
kevinw@9327 | 1564 | {CC "allocateMemory", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory)}, |
kevinw@9327 | 1565 | {CC "reallocateMemory", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory)}, |
kevinw@9327 | 1566 | {CC "freeMemory", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory)}, |
duke@435 | 1567 | |
kevinw@9327 | 1568 | {CC "objectFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset)}, |
kevinw@9327 | 1569 | {CC "staticFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset)}, |
kevinw@9327 | 1570 | {CC "staticFieldBase", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, |
kevinw@9327 | 1571 | {CC "ensureClassInitialized",CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized)}, |
kevinw@9327 | 1572 | {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)}, |
kevinw@9327 | 1573 | {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)}, |
kevinw@9327 | 1574 | {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)}, |
kevinw@9327 | 1575 | {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
duke@435 | 1576 | |
kevinw@9327 | 1577 | {CC "defineClass", CC "(" DC0_Args ")" CLS, FN_PTR(Unsafe_DefineClass0)}, |
kevinw@9327 | 1578 | {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)}, |
kevinw@9327 | 1579 | {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
kevinw@9327 | 1580 | {CC "monitorEnter", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorEnter)}, |
kevinw@9327 | 1581 | {CC "monitorExit", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorExit)}, |
kevinw@9327 | 1582 | {CC "tryMonitorEnter", CC "(" OBJ ")Z", FN_PTR(Unsafe_TryMonitorEnter)}, |
kevinw@9327 | 1583 | {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)}, |
kevinw@9327 | 1584 | {CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, |
kevinw@9327 | 1585 | {CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, |
kevinw@9327 | 1586 | {CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, |
kevinw@9327 | 1587 | {CC "putOrderedObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetOrderedObject)}, |
kevinw@9327 | 1588 | {CC "putOrderedInt", CC "(" OBJ "JI)V", FN_PTR(Unsafe_SetOrderedInt)}, |
kevinw@9327 | 1589 | {CC "putOrderedLong", CC "(" OBJ "JJ)V", FN_PTR(Unsafe_SetOrderedLong)}, |
kevinw@9327 | 1590 | {CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)}, |
kevinw@9327 | 1591 | {CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)} |
twisti@4866 | 1592 | }; |
duke@435 | 1593 | |
twisti@4866 | 1594 | // These are the methods for 1.8.0 |
twisti@4866 | 1595 | static JNINativeMethod methods_18[] = { |
kevinw@9327 | 1596 | {CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)}, |
kevinw@9327 | 1597 | {CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)}, |
kevinw@9327 | 1598 | {CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)}, |
kevinw@9327 | 1599 | {CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObjectVolatile)}, |
duke@435 | 1600 | |
twisti@4866 | 1601 | DECLARE_GETSETOOP(Boolean, Z), |
twisti@4866 | 1602 | DECLARE_GETSETOOP(Byte, B), |
twisti@4866 | 1603 | DECLARE_GETSETOOP(Short, S), |
twisti@4866 | 1604 | DECLARE_GETSETOOP(Char, C), |
twisti@4866 | 1605 | DECLARE_GETSETOOP(Int, I), |
twisti@4866 | 1606 | DECLARE_GETSETOOP(Long, J), |
twisti@4866 | 1607 | DECLARE_GETSETOOP(Float, F), |
twisti@4866 | 1608 | DECLARE_GETSETOOP(Double, D), |
duke@435 | 1609 | |
twisti@4866 | 1610 | DECLARE_GETSETNATIVE(Byte, B), |
twisti@4866 | 1611 | DECLARE_GETSETNATIVE(Short, S), |
twisti@4866 | 1612 | DECLARE_GETSETNATIVE(Char, C), |
twisti@4866 | 1613 | DECLARE_GETSETNATIVE(Int, I), |
twisti@4866 | 1614 | DECLARE_GETSETNATIVE(Long, J), |
twisti@4866 | 1615 | DECLARE_GETSETNATIVE(Float, F), |
twisti@4866 | 1616 | DECLARE_GETSETNATIVE(Double, D), |
twisti@4866 | 1617 | |
kevinw@9327 | 1618 | {CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
kevinw@9327 | 1619 | {CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)}, |
twisti@4866 | 1620 | |
kevinw@9327 | 1621 | {CC "allocateMemory", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory)}, |
kevinw@9327 | 1622 | {CC "reallocateMemory", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory)}, |
kevinw@9327 | 1623 | {CC "freeMemory", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory)}, |
twisti@4866 | 1624 | |
kevinw@9327 | 1625 | {CC "objectFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset)}, |
kevinw@9327 | 1626 | {CC "staticFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset)}, |
kevinw@9327 | 1627 | {CC "staticFieldBase", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, |
kevinw@9327 | 1628 | {CC "ensureClassInitialized",CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized)}, |
kevinw@9327 | 1629 | {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)}, |
kevinw@9327 | 1630 | {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)}, |
kevinw@9327 | 1631 | {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)}, |
kevinw@9327 | 1632 | {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
twisti@4866 | 1633 | |
kevinw@9327 | 1634 | {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)}, |
kevinw@9327 | 1635 | {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
kevinw@9327 | 1636 | {CC "monitorEnter", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorEnter)}, |
kevinw@9327 | 1637 | {CC "monitorExit", CC "(" OBJ ")V", FN_PTR(Unsafe_MonitorExit)}, |
kevinw@9327 | 1638 | {CC "tryMonitorEnter", CC "(" OBJ ")Z", FN_PTR(Unsafe_TryMonitorEnter)}, |
kevinw@9327 | 1639 | {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)}, |
kevinw@9327 | 1640 | {CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, |
kevinw@9327 | 1641 | {CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, |
kevinw@9327 | 1642 | {CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, |
kevinw@9327 | 1643 | {CC "putOrderedObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetOrderedObject)}, |
kevinw@9327 | 1644 | {CC "putOrderedInt", CC "(" OBJ "JI)V", FN_PTR(Unsafe_SetOrderedInt)}, |
kevinw@9327 | 1645 | {CC "putOrderedLong", CC "(" OBJ "JJ)V", FN_PTR(Unsafe_SetOrderedLong)}, |
kevinw@9327 | 1646 | {CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)}, |
kevinw@9327 | 1647 | {CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)} |
duke@435 | 1648 | }; |
duke@435 | 1649 | |
duke@435 | 1650 | JNINativeMethod loadavg_method[] = { |
kevinw@9327 | 1651 | {CC "getLoadAverage", CC "([DI)I", FN_PTR(Unsafe_Loadavg)} |
duke@435 | 1652 | }; |
duke@435 | 1653 | |
duke@435 | 1654 | JNINativeMethod prefetch_methods[] = { |
kevinw@9327 | 1655 | {CC "prefetchRead", CC "(" OBJ "J)V", FN_PTR(Unsafe_PrefetchRead)}, |
kevinw@9327 | 1656 | {CC "prefetchWrite", CC "(" OBJ "J)V", FN_PTR(Unsafe_PrefetchWrite)}, |
kevinw@9327 | 1657 | {CC "prefetchReadStatic", CC "(" OBJ "J)V", FN_PTR(Unsafe_PrefetchRead)}, |
kevinw@9327 | 1658 | {CC "prefetchWriteStatic",CC "(" OBJ "J)V", FN_PTR(Unsafe_PrefetchWrite)} |
duke@435 | 1659 | }; |
duke@435 | 1660 | |
twisti@4866 | 1661 | JNINativeMethod memcopy_methods_17[] = { |
kevinw@9327 | 1662 | {CC "copyMemory", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory2)}, |
kevinw@9327 | 1663 | {CC "setMemory", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory2)} |
duke@435 | 1664 | }; |
duke@435 | 1665 | |
duke@435 | 1666 | JNINativeMethod memcopy_methods_15[] = { |
kevinw@9327 | 1667 | {CC "setMemory", CC "(" ADR "JB)V", FN_PTR(Unsafe_SetMemory)}, |
kevinw@9327 | 1668 | {CC "copyMemory", CC "(" ADR ADR "J)V", FN_PTR(Unsafe_CopyMemory)} |
duke@435 | 1669 | }; |
duke@435 | 1670 | |
jrose@866 | 1671 | JNINativeMethod anonk_methods[] = { |
kevinw@9327 | 1672 | {CC "defineAnonymousClass", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass)}, |
jrose@866 | 1673 | }; |
duke@435 | 1674 | |
twisti@3969 | 1675 | JNINativeMethod lform_methods[] = { |
kevinw@9327 | 1676 | {CC "shouldBeInitialized",CC "(" CLS ")Z", FN_PTR(Unsafe_ShouldBeInitialized)}, |
twisti@3969 | 1677 | }; |
twisti@3969 | 1678 | |
twisti@4866 | 1679 | JNINativeMethod fence_methods[] = { |
kevinw@9327 | 1680 | {CC "loadFence", CC "()V", FN_PTR(Unsafe_LoadFence)}, |
kevinw@9327 | 1681 | {CC "storeFence", CC "()V", FN_PTR(Unsafe_StoreFence)}, |
kevinw@9327 | 1682 | {CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)}, |
twisti@4866 | 1683 | }; |
twisti@4866 | 1684 | |
duke@435 | 1685 | #undef CC |
duke@435 | 1686 | #undef FN_PTR |
duke@435 | 1687 | |
duke@435 | 1688 | #undef ADR |
duke@435 | 1689 | #undef LANG |
duke@435 | 1690 | #undef OBJ |
duke@435 | 1691 | #undef CLS |
duke@435 | 1692 | #undef CTR |
duke@435 | 1693 | #undef FLD |
duke@435 | 1694 | #undef MTH |
duke@435 | 1695 | #undef THR |
duke@435 | 1696 | #undef DC0_Args |
twisti@4866 | 1697 | #undef DC_Args |
duke@435 | 1698 | |
duke@435 | 1699 | #undef DECLARE_GETSETOOP |
duke@435 | 1700 | #undef DECLARE_GETSETNATIVE |
duke@435 | 1701 | |
duke@435 | 1702 | |
twisti@4866 | 1703 | /** |
twisti@4866 | 1704 | * Helper method to register native methods. |
twisti@4866 | 1705 | */ |
twisti@4866 | 1706 | static bool register_natives(const char* message, JNIEnv* env, jclass clazz, const JNINativeMethod* methods, jint nMethods) { |
twisti@4866 | 1707 | int status = env->RegisterNatives(clazz, methods, nMethods); |
twisti@4866 | 1708 | if (status < 0 || env->ExceptionOccurred()) { |
twisti@4866 | 1709 | if (PrintMiscellaneous && (Verbose || WizardMode)) { |
twisti@4866 | 1710 | tty->print_cr("Unsafe: failed registering %s", message); |
twisti@4866 | 1711 | } |
twisti@4866 | 1712 | env->ExceptionClear(); |
twisti@4866 | 1713 | return false; |
twisti@4866 | 1714 | } else { |
twisti@4866 | 1715 | if (PrintMiscellaneous && (Verbose || WizardMode)) { |
twisti@4866 | 1716 | tty->print_cr("Unsafe: successfully registered %s", message); |
twisti@4866 | 1717 | } |
twisti@4866 | 1718 | return true; |
twisti@4866 | 1719 | } |
twisti@4866 | 1720 | } |
twisti@4866 | 1721 | |
twisti@4866 | 1722 | |
duke@435 | 1723 | // This one function is exported, used by NativeLookup. |
duke@435 | 1724 | // The Unsafe_xxx functions above are called only from the interpreter. |
duke@435 | 1725 | // The optimizer looks at names and signatures to recognize |
duke@435 | 1726 | // individual functions. |
duke@435 | 1727 | |
duke@435 | 1728 | JVM_ENTRY(void, JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls)) |
duke@435 | 1729 | UnsafeWrapper("JVM_RegisterUnsafeMethods"); |
duke@435 | 1730 | { |
duke@435 | 1731 | ThreadToNativeFromVM ttnfv(thread); |
twisti@4866 | 1732 | |
twisti@4866 | 1733 | // Unsafe methods |
duke@435 | 1734 | { |
twisti@4866 | 1735 | bool success = false; |
twisti@4866 | 1736 | // We need to register the 1.6 methods first because the 1.8 methods would register fine on 1.7 and 1.6 |
twisti@4866 | 1737 | if (!success) { |
twisti@4866 | 1738 | success = register_natives("1.6 methods", env, unsafecls, methods_16, sizeof(methods_16)/sizeof(JNINativeMethod)); |
twisti@4866 | 1739 | } |
twisti@4866 | 1740 | if (!success) { |
twisti@4866 | 1741 | success = register_natives("1.8 methods", env, unsafecls, methods_18, sizeof(methods_18)/sizeof(JNINativeMethod)); |
twisti@4866 | 1742 | } |
twisti@4866 | 1743 | if (!success) { |
twisti@4866 | 1744 | success = register_natives("1.5 methods", env, unsafecls, methods_15, sizeof(methods_15)/sizeof(JNINativeMethod)); |
twisti@4866 | 1745 | } |
twisti@4866 | 1746 | if (!success) { |
twisti@4866 | 1747 | success = register_natives("1.4.1 methods", env, unsafecls, methods_141, sizeof(methods_141)/sizeof(JNINativeMethod)); |
twisti@4866 | 1748 | } |
twisti@4866 | 1749 | if (!success) { |
twisti@4866 | 1750 | success = register_natives("1.4.0 methods", env, unsafecls, methods_140, sizeof(methods_140)/sizeof(JNINativeMethod)); |
twisti@4866 | 1751 | } |
twisti@4866 | 1752 | guarantee(success, "register unsafe natives"); |
twisti@4866 | 1753 | } |
twisti@4866 | 1754 | |
twisti@4866 | 1755 | // Unsafe.getLoadAverage |
twisti@4866 | 1756 | register_natives("1.6 loadavg method", env, unsafecls, loadavg_method, sizeof(loadavg_method)/sizeof(JNINativeMethod)); |
twisti@4866 | 1757 | |
twisti@4866 | 1758 | // Prefetch methods |
twisti@4866 | 1759 | register_natives("1.6 prefetch methods", env, unsafecls, prefetch_methods, sizeof(prefetch_methods)/sizeof(JNINativeMethod)); |
twisti@4866 | 1760 | |
twisti@4866 | 1761 | // Memory copy methods |
twisti@4866 | 1762 | { |
twisti@4866 | 1763 | bool success = false; |
twisti@4866 | 1764 | if (!success) { |
twisti@4866 | 1765 | success = register_natives("1.7 memory copy methods", env, unsafecls, memcopy_methods_17, sizeof(memcopy_methods_17)/sizeof(JNINativeMethod)); |
twisti@4866 | 1766 | } |
twisti@4866 | 1767 | if (!success) { |
twisti@4866 | 1768 | success = register_natives("1.5 memory copy methods", env, unsafecls, memcopy_methods_15, sizeof(memcopy_methods_15)/sizeof(JNINativeMethod)); |
duke@435 | 1769 | } |
duke@435 | 1770 | } |
twisti@4866 | 1771 | |
twisti@4866 | 1772 | // Unsafe.defineAnonymousClass |
twisti@4866 | 1773 | if (EnableInvokeDynamic) { |
twisti@4866 | 1774 | register_natives("1.7 define anonymous class method", env, unsafecls, anonk_methods, sizeof(anonk_methods)/sizeof(JNINativeMethod)); |
duke@435 | 1775 | } |
twisti@4866 | 1776 | |
twisti@4866 | 1777 | // Unsafe.shouldBeInitialized |
twisti@4866 | 1778 | if (EnableInvokeDynamic) { |
twisti@4866 | 1779 | register_natives("1.7 LambdaForm support", env, unsafecls, lform_methods, sizeof(lform_methods)/sizeof(JNINativeMethod)); |
duke@435 | 1780 | } |
twisti@4866 | 1781 | |
twisti@4866 | 1782 | // Fence methods |
twisti@4866 | 1783 | register_natives("1.8 fence methods", env, unsafecls, fence_methods, sizeof(fence_methods)/sizeof(JNINativeMethod)); |
duke@435 | 1784 | } |
duke@435 | 1785 | JVM_END |