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