1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012 Red Hat, Inc.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "ci/ciReplay.hpp"
  28 #include "classfile/altHashing.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "jfr/jfrEvents.hpp"
  36 #include "jfr/support/jfrThreadId.hpp"
  37 #include "utilities/macros.hpp"
  38 #include "utilities/ostream.hpp"
  39 #if INCLUDE_ALL_GCS
  40 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  41 #endif // INCLUDE_ALL_GCS
  42 #include "memory/allocation.hpp"
  43 #include "memory/allocation.inline.hpp"
  44 #include "memory/gcLocker.inline.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/universe.inline.hpp"
  47 #include "oops/instanceKlass.hpp"
  48 #include "oops/instanceOop.hpp"
  49 #include "oops/markOop.hpp"
  50 #include "oops/method.hpp"
  51 #include "oops/objArrayKlass.hpp"
  52 #include "oops/objArrayOop.hpp"
  53 #include "oops/oop.inline.hpp"
  54 #include "oops/symbol.hpp"
  55 #include "oops/typeArrayKlass.hpp"
  56 #include "oops/typeArrayOop.hpp"
  57 #include "prims/jni.h"
  58 #include "prims/jniCheck.hpp"
  59 #include "prims/jniExport.hpp"
  60 #include "prims/jniFastGetField.hpp"
  61 #include "prims/jvm.h"
  62 #include "prims/jvm_misc.hpp"
  63 #include "prims/jvmtiExport.hpp"
  64 #include "prims/jvmtiThreadState.hpp"
  65 #include "runtime/compilationPolicy.hpp"
  66 #include "runtime/fieldDescriptor.hpp"
  67 #include "runtime/fprofiler.hpp"
  68 #include "runtime/handles.inline.hpp"
  69 #include "runtime/interfaceSupport.hpp"
  70 #include "runtime/java.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/jfieldIDWorkaround.hpp"
  73 #include "runtime/orderAccess.inline.hpp"
  74 #include "runtime/reflection.hpp"
  75 #include "runtime/sharedRuntime.hpp"
  76 #include "runtime/signature.hpp"
  77 #include "runtime/thread.inline.hpp"
  78 #include "runtime/vm_operations.hpp"
  79 #include "services/memTracker.hpp"
  80 #include "services/runtimeService.hpp"
  81 #include "utilities/defaultStream.hpp"
  82 #include "utilities/dtrace.hpp"
  83 #include "utilities/events.hpp"
  84 #include "utilities/histogram.hpp"
  85 #ifdef TARGET_OS_FAMILY_linux
  86 # include "os_linux.inline.hpp"
  87 #endif
  88 #ifdef TARGET_OS_FAMILY_solaris
  89 # include "os_solaris.inline.hpp"
  90 #endif
  91 #ifdef TARGET_OS_FAMILY_windows
  92 # include "os_windows.inline.hpp"
  93 #endif
  94 #ifdef TARGET_OS_FAMILY_bsd
  95 # include "os_bsd.inline.hpp"
  96 #endif
  97 
  98 static jint CurrentVersion = JNI_VERSION_1_8;
  99 
 100 
 101 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 102 // '-return' probe regardless of the return path is taken out of the function.
 103 // Methods that have multiple return paths use this to avoid having to
 104 // instrument each return path.  Methods that use CHECK or THROW must use this
 105 // since those macros can cause an immedate uninstrumented return.
 106 //
 107 // In order to get the return value, a reference to the variable containing
 108 // the return value must be passed to the contructor of the object, and
 109 // the return value must be set before return (since the mark object has
 110 // a reference to it).
 111 //
 112 // Example:
 113 // DT_RETURN_MARK_DECL(SomeFunc, int);
 114 // JNI_ENTRY(int, SomeFunc, ...)
 115 //   int return_value = 0;
 116 //   DT_RETURN_MARK(SomeFunc, int, (const int&)return_value);
 117 //   foo(CHECK_0)
 118 //   return_value = 5;
 119 //   return return_value;
 120 // JNI_END
 121 #ifndef USDT2
 122 #define DT_RETURN_MARK_DECL(name, type)                                    \
 123   HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type);                \
 124   DTRACE_ONLY(                                                             \
 125     class DTraceReturnProbeMark_##name {                                   \
 126      public:                                                               \
 127       const type& _ret_ref;                                                \
 128       DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
 129       ~DTraceReturnProbeMark_##name() {                                    \
 130         HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref);           \
 131       }                                                                    \
 132     }                                                                      \
 133   )
 134 // Void functions are simpler since there's no return value
 135 #define DT_VOID_RETURN_MARK_DECL(name)                                     \
 136   HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return);                      \
 137   DTRACE_ONLY(                                                             \
 138     class DTraceReturnProbeMark_##name {                                   \
 139      public:                                                               \
 140       ~DTraceReturnProbeMark_##name() {                                    \
 141         HS_DTRACE_PROBE0(hotspot_jni, name##__return);                     \
 142       }                                                                    \
 143     }                                                                      \
 144   )
 145 
 146 #else /* USDT2 */
 147 
 148 #define DT_RETURN_MARK_DECL(name, type, probe)                             \
 149   DTRACE_ONLY(                                                             \
 150     class DTraceReturnProbeMark_##name {                                   \
 151      public:                                                               \
 152       const type& _ret_ref;                                                \
 153       DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
 154       ~DTraceReturnProbeMark_##name() {                                    \
 155         probe;                                                             \
 156       }                                                                    \
 157     }                                                                      \
 158   )
 159 // Void functions are simpler since there's no return value
 160 #define DT_VOID_RETURN_MARK_DECL(name, probe)                              \
 161   DTRACE_ONLY(                                                             \
 162     class DTraceReturnProbeMark_##name {                                   \
 163      public:                                                               \
 164       ~DTraceReturnProbeMark_##name() {                                    \
 165         probe;                                                             \
 166       }                                                                    \
 167     }                                                                      \
 168   )
 169 #endif /* USDT2 */
 170 
 171 // Place these macros in the function to mark the return.  Non-void
 172 // functions need the type and address of the return value.
 173 #define DT_RETURN_MARK(name, type, ref) \
 174   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) )
 175 #define DT_VOID_RETURN_MARK(name) \
 176   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark )
 177 
 178 
 179 // Use these to select distinct code for floating-point vs. non-floating point
 180 // situations.  Used from within common macros where we need slightly
 181 // different behavior for Float/Double
 182 #define FP_SELECT_Boolean(intcode, fpcode) intcode
 183 #define FP_SELECT_Byte(intcode, fpcode)    intcode
 184 #define FP_SELECT_Char(intcode, fpcode)    intcode
 185 #define FP_SELECT_Short(intcode, fpcode)   intcode
 186 #define FP_SELECT_Object(intcode, fpcode)  intcode
 187 #define FP_SELECT_Int(intcode, fpcode)     intcode
 188 #define FP_SELECT_Long(intcode, fpcode)    intcode
 189 #define FP_SELECT_Float(intcode, fpcode)   fpcode
 190 #define FP_SELECT_Double(intcode, fpcode)  fpcode
 191 #define FP_SELECT(TypeName, intcode, fpcode) \
 192   FP_SELECT_##TypeName(intcode, fpcode)
 193 
 194 #define COMMA ,
 195 
 196 // Choose DT_RETURN_MARK macros  based on the type: float/double -> void
 197 // (dtrace doesn't do FP yet)
 198 #ifndef USDT2
 199 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \
 200   FP_SELECT(TypeName, \
 201     DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) )
 202 #else /* USDT2 */
 203 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe)    \
 204   FP_SELECT(TypeName, \
 205     DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) )
 206 #endif /* USDT2 */
 207 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \
 208   FP_SELECT(TypeName, \
 209     DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) )
 210 
 211 
 212 // out-of-line helpers for class jfieldIDWorkaround:
 213 
 214 bool jfieldIDWorkaround::is_valid_jfieldID(Klass* k, jfieldID id) {
 215   if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) {
 216     uintptr_t as_uint = (uintptr_t) id;
 217     intptr_t offset = raw_instance_offset(id);
 218     if (is_checked_jfieldID(id)) {
 219       if (!klass_hash_ok(k, id)) {
 220         return false;
 221       }
 222     }
 223     return InstanceKlass::cast(k)->contains_field_offset(offset);
 224   } else {
 225     JNIid* result = (JNIid*) id;
 226 #ifdef ASSERT
 227     return result != NULL && result->is_static_field_id();
 228 #else
 229     return result != NULL;
 230 #endif
 231   }
 232 }
 233 
 234 
 235 intptr_t jfieldIDWorkaround::encode_klass_hash(Klass* k, intptr_t offset) {
 236   if (offset <= small_offset_mask) {
 237     Klass* field_klass = k;
 238     Klass* super_klass = field_klass->super();
 239     // With compressed oops the most super class with nonstatic fields would
 240     // be the owner of fields embedded in the header.
 241     while (InstanceKlass::cast(super_klass)->has_nonstatic_fields() &&
 242            InstanceKlass::cast(super_klass)->contains_field_offset(offset)) {
 243       field_klass = super_klass;   // super contains the field also
 244       super_klass = field_klass->super();
 245     }
 246     debug_only(No_Safepoint_Verifier nosafepoint;)
 247     uintptr_t klass_hash = field_klass->identity_hash();
 248     return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place;
 249   } else {
 250 #if 0
 251     #ifndef PRODUCT
 252     {
 253       ResourceMark rm;
 254       warning("VerifyJNIFields: long offset %d in %s", offset, k->external_name());
 255     }
 256     #endif
 257 #endif
 258     return 0;
 259   }
 260 }
 261 
 262 bool jfieldIDWorkaround::klass_hash_ok(Klass* k, jfieldID id) {
 263   uintptr_t as_uint = (uintptr_t) id;
 264   intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask;
 265   do {
 266     debug_only(No_Safepoint_Verifier nosafepoint;)
 267     // Could use a non-blocking query for identity_hash here...
 268     if ((k->identity_hash() & klass_mask) == klass_hash)
 269       return true;
 270     k = k->super();
 271   } while (k != NULL);
 272   return false;
 273 }
 274 
 275 void jfieldIDWorkaround::verify_instance_jfieldID(Klass* k, jfieldID id) {
 276   guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" );
 277   uintptr_t as_uint = (uintptr_t) id;
 278   intptr_t offset = raw_instance_offset(id);
 279   if (VerifyJNIFields) {
 280     if (is_checked_jfieldID(id)) {
 281       guarantee(klass_hash_ok(k, id),
 282     "Bug in native code: jfieldID class must match object");
 283     } else {
 284 #if 0
 285       #ifndef PRODUCT
 286       if (Verbose) {
 287   ResourceMark rm;
 288   warning("VerifyJNIFields: unverified offset %d for %s", offset, k->external_name());
 289       }
 290       #endif
 291 #endif
 292     }
 293   }
 294   guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
 295       "Bug in native code: jfieldID offset must address interior of object");
 296 }
 297 
 298 // Wrapper to trace JNI functions
 299 
 300 #ifdef ASSERT
 301   Histogram* JNIHistogram;
 302   static volatile jint JNIHistogram_lock = 0;
 303 
 304   class JNITraceWrapper : public StackObj {
 305    public:
 306     JNITraceWrapper(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
 307       if (TraceJNICalls) {
 308         va_list ap;
 309         va_start(ap, format);
 310         tty->print("JNI ");
 311         tty->vprint_cr(format, ap);
 312         va_end(ap);
 313       }
 314     }
 315   };
 316 
 317   class JNIHistogramElement : public HistogramElement {
 318     public:
 319      JNIHistogramElement(const char* name);
 320   };
 321 
 322   JNIHistogramElement::JNIHistogramElement(const char* elementName) {
 323     _name = elementName;
 324     uintx count = 0;
 325 
 326     while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) {
 327       while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) {
 328         count +=1;
 329         if ( (WarnOnStalledSpinLock > 0)
 330           && (count % WarnOnStalledSpinLock == 0)) {
 331           warning("JNIHistogram_lock seems to be stalled");
 332         }
 333       }
 334      }
 335 
 336 
 337     if(JNIHistogram == NULL)
 338       JNIHistogram = new Histogram("JNI Call Counts",100);
 339 
 340     JNIHistogram->add_element(this);
 341     Atomic::dec(&JNIHistogram_lock);
 342   }
 343 
 344   #define JNICountWrapper(arg)                                     \
 345      static JNIHistogramElement* e = new JNIHistogramElement(arg); \
 346       /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
 347      if (e != NULL) e->increment_count()
 348   #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg)
 349 #else
 350   #define JNIWrapper(arg)
 351 #endif
 352 
 353 
 354 // Implementation of JNI entries
 355 
 356 #ifndef USDT2
 357 DT_RETURN_MARK_DECL(DefineClass, jclass);
 358 #else /* USDT2 */
 359 DT_RETURN_MARK_DECL(DefineClass, jclass
 360                     , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
 361 #endif /* USDT2 */
 362 
 363 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
 364                                   const jbyte *buf, jsize bufLen))
 365   JNIWrapper("DefineClass");
 366 
 367 #ifndef USDT2
 368   DTRACE_PROBE5(hotspot_jni, DefineClass__entry,
 369     env, name, loaderRef, buf, bufLen);
 370 #else /* USDT2 */
 371   HOTSPOT_JNI_DEFINECLASS_ENTRY(
 372     env, (char*) name, loaderRef, (char*) buf, bufLen);
 373 #endif /* USDT2 */
 374   jclass cls = NULL;
 375   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 376 
 377   TempNewSymbol class_name = NULL;
 378   // Since exceptions can be thrown, class initialization can take place
 379   // if name is NULL no check for class name in .class stream has to be made.
 380   if (name != NULL) {
 381     const int str_len = (int)strlen(name);
 382     if (str_len > Symbol::max_length()) {
 383       // It's impossible to create this class;  the name cannot fit
 384       // into the constant pool.
 385       THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 386     }
 387     class_name = SymbolTable::new_symbol(name, CHECK_NULL);
 388   }
 389   ResourceMark rm(THREAD);
 390   ClassFileStream st((u1*) buf, bufLen, NULL);
 391   Handle class_loader (THREAD, JNIHandles::resolve(loaderRef));
 392 
 393   if (UsePerfData && !class_loader.is_null()) {
 394     // check whether the current caller thread holds the lock or not.
 395     // If not, increment the corresponding counter
 396     if (ObjectSynchronizer::
 397         query_lock_ownership((JavaThread*)THREAD, class_loader) !=
 398         ObjectSynchronizer::owner_self) {
 399       ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc();
 400     }
 401   }
 402   Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
 403                                                      Handle(), &st, true,
 404                                                      CHECK_NULL);
 405 
 406   if (TraceClassResolution && k != NULL) {
 407     trace_class_resolution(k);
 408   }
 409 
 410   cls = (jclass)JNIHandles::make_local(
 411     env, k->java_mirror());
 412   return cls;
 413 JNI_END
 414 
 415 
 416 
 417 static bool first_time_FindClass = true;
 418 
 419 #ifndef USDT2
 420 DT_RETURN_MARK_DECL(FindClass, jclass);
 421 #else /* USDT2 */
 422 DT_RETURN_MARK_DECL(FindClass, jclass
 423                     , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref));
 424 #endif /* USDT2 */
 425 
 426 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name))
 427   JNIWrapper("FindClass");
 428 #ifndef USDT2
 429   DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name);
 430 #else /* USDT2 */
 431   HOTSPOT_JNI_FINDCLASS_ENTRY(
 432                               env, (char *)name);
 433 #endif /* USDT2 */
 434 
 435   jclass result = NULL;
 436   DT_RETURN_MARK(FindClass, jclass, (const jclass&)result);
 437 
 438   // Remember if we are the first invocation of jni_FindClass
 439   bool first_time = first_time_FindClass;
 440   first_time_FindClass = false;
 441 
 442   // Sanity check the name:  it cannot be null or larger than the maximum size
 443   // name we can fit in the constant pool.
 444   if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
 445     THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 446   }
 447 
 448   //%note jni_3
 449   Handle loader;
 450   Handle protection_domain;
 451   // Find calling class
 452   instanceKlassHandle k (THREAD, thread->security_get_caller_class(0));
 453   if (k.not_null()) {
 454     loader = Handle(THREAD, k->class_loader());
 455     // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed
 456     // in the correct class context.
 457     if (loader.is_null() &&
 458         k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) {
 459       JavaValue result(T_OBJECT);
 460       JavaCalls::call_static(&result, k,
 461                                       vmSymbols::getFromClass_name(),
 462                                       vmSymbols::void_class_signature(),
 463                                       thread);
 464       if (HAS_PENDING_EXCEPTION) {
 465         Handle ex(thread, thread->pending_exception());
 466         CLEAR_PENDING_EXCEPTION;
 467         THROW_HANDLE_0(ex);
 468       }
 469       oop mirror = (oop) result.get_jobject();
 470       loader = Handle(THREAD,
 471         InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->class_loader());
 472       protection_domain = Handle(THREAD,
 473         InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->protection_domain());
 474     }
 475   } else {
 476     // We call ClassLoader.getSystemClassLoader to obtain the system class loader.
 477     loader = Handle(THREAD, SystemDictionary::java_system_loader());
 478   }
 479 
 480   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
 481   result = find_class_from_class_loader(env, sym, true, loader,
 482                                         protection_domain, true, thread);
 483 
 484   if (TraceClassResolution && result != NULL) {
 485     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 486   }
 487 
 488   // If we were the first invocation of jni_FindClass, we enable compilation again
 489   // rather than just allowing invocation counter to overflow and decay.
 490   // Controlled by flag DelayCompilationDuringStartup.
 491   if (first_time && !CompileTheWorld)
 492     CompilationPolicy::completed_vm_startup();
 493 
 494   return result;
 495 JNI_END
 496 
 497 #ifndef USDT2
 498 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID);
 499 #else /* USDT2 */
 500 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
 501                     , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
 502 #endif /* USDT2 */
 503 
 504 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
 505   JNIWrapper("FromReflectedMethod");
 506 #ifndef USDT2
 507   DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method);
 508 #else /* USDT2 */
 509   HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(
 510                                         env, method);
 511 #endif /* USDT2 */
 512   jmethodID ret = NULL;
 513   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 514 
 515   // method is a handle to a java.lang.reflect.Method object
 516   oop reflected  = JNIHandles::resolve_non_null(method);
 517   oop mirror     = NULL;
 518   int slot       = 0;
 519 
 520   if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
 521     mirror = java_lang_reflect_Constructor::clazz(reflected);
 522     slot   = java_lang_reflect_Constructor::slot(reflected);
 523   } else {
 524     assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type");
 525     mirror = java_lang_reflect_Method::clazz(reflected);
 526     slot   = java_lang_reflect_Method::slot(reflected);
 527   }
 528   Klass* k     = java_lang_Class::as_Klass(mirror);
 529 
 530   KlassHandle k1(THREAD, k);
 531   // Make sure class is initialized before handing id's out to methods
 532   k1()->initialize(CHECK_NULL);
 533   Method* m = InstanceKlass::cast(k1())->method_with_idnum(slot);
 534   ret = m==NULL? NULL : m->jmethod_id();  // return NULL if reflected method deleted
 535   return ret;
 536 JNI_END
 537 
 538 #ifndef USDT2
 539 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID);
 540 #else /* USDT2 */
 541 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
 542                     , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
 543 #endif /* USDT2 */
 544 
 545 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
 546   JNIWrapper("FromReflectedField");
 547 #ifndef USDT2
 548   DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field);
 549 #else /* USDT2 */
 550   HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(
 551                                        env, field);
 552 #endif /* USDT2 */
 553   jfieldID ret = NULL;
 554   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 555 
 556   // field is a handle to a java.lang.reflect.Field object
 557   oop reflected   = JNIHandles::resolve_non_null(field);
 558   oop mirror      = java_lang_reflect_Field::clazz(reflected);
 559   Klass* k      = java_lang_Class::as_Klass(mirror);
 560   int slot        = java_lang_reflect_Field::slot(reflected);
 561   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 562 
 563   KlassHandle k1(THREAD, k);
 564   // Make sure class is initialized before handing id's out to fields
 565   k1()->initialize(CHECK_NULL);
 566 
 567   // First check if this is a static field
 568   if (modifiers & JVM_ACC_STATIC) {
 569     intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot );
 570     JNIid* id = InstanceKlass::cast(k1())->jni_id_for(offset);
 571     assert(id != NULL, "corrupt Field object");
 572     debug_only(id->set_is_static_field_id();)
 573     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 574     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 575     return ret;
 576   }
 577 
 578   // The slot is the index of the field description in the field-array
 579   // The jfieldID is the offset of the field within the object
 580   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 581   intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot );
 582   assert(InstanceKlass::cast(k1())->contains_field_offset(offset), "stay within object");
 583   ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset);
 584   return ret;
 585 JNI_END
 586 
 587 #ifndef USDT2
 588 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject);
 589 #else /* USDT2 */
 590 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
 591                     , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
 592 #endif /* USDT2 */
 593 
 594 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
 595   JNIWrapper("ToReflectedMethod");
 596 #ifndef USDT2
 597   DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic);
 598 #else /* USDT2 */
 599   HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(
 600                                       env, cls, (uintptr_t) method_id, isStatic);
 601 #endif /* USDT2 */
 602   jobject ret = NULL;
 603   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 604 
 605   methodHandle m (THREAD, Method::resolve_jmethod_id(method_id));
 606   assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match");
 607   oop reflection_method;
 608   if (m->is_initializer()) {
 609     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
 610   } else {
 611     reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL);
 612   }
 613   ret = JNIHandles::make_local(env, reflection_method);
 614   return ret;
 615 JNI_END
 616 
 617 #ifndef USDT2
 618 DT_RETURN_MARK_DECL(GetSuperclass, jclass);
 619 #else /* USDT2 */
 620 DT_RETURN_MARK_DECL(GetSuperclass, jclass
 621                     , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
 622 #endif /* USDT2 */
 623 
 624 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
 625   JNIWrapper("GetSuperclass");
 626 #ifndef USDT2
 627   DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub);
 628 #else /* USDT2 */
 629   HOTSPOT_JNI_GETSUPERCLASS_ENTRY(
 630                                   env, sub);
 631 #endif /* USDT2 */
 632   jclass obj = NULL;
 633   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 634 
 635   oop mirror = JNIHandles::resolve_non_null(sub);
 636   // primitive classes return NULL
 637   if (java_lang_Class::is_primitive(mirror)) return NULL;
 638 
 639   // Rules of Class.getSuperClass as implemented by KLass::java_super:
 640   // arrays return Object
 641   // interfaces return NULL
 642   // proper classes return Klass::super()
 643   Klass* k = java_lang_Class::as_Klass(mirror);
 644   if (k->is_interface()) return NULL;
 645 
 646   // return mirror for superclass
 647   Klass* super = k->java_super();
 648   // super2 is the value computed by the compiler's getSuperClass intrinsic:
 649   debug_only(Klass* super2 = ( k->oop_is_array()
 650                                  ? SystemDictionary::Object_klass()
 651                                  : k->super() ) );
 652   assert(super == super2,
 653          "java_super computation depends on interface, array, other super");
 654   obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(super->java_mirror());
 655   return obj;
 656 JNI_END
 657 
 658 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super))
 659   JNIWrapper("IsSubclassOf");
 660 #ifndef USDT2
 661   DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super);
 662 #else /* USDT2 */
 663   HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY(
 664                                      env, sub, super);
 665 #endif /* USDT2 */
 666   oop sub_mirror   = JNIHandles::resolve_non_null(sub);
 667   oop super_mirror = JNIHandles::resolve_non_null(super);
 668   if (java_lang_Class::is_primitive(sub_mirror) ||
 669       java_lang_Class::is_primitive(super_mirror)) {
 670     jboolean ret = sub_mirror == super_mirror;
 671 #ifndef USDT2
 672     DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret);
 673 #else /* USDT2 */
 674     HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(
 675                                         ret);
 676 #endif /* USDT2 */
 677     return ret;
 678   }
 679   Klass* sub_klass   = java_lang_Class::as_Klass(sub_mirror);
 680   Klass* super_klass = java_lang_Class::as_Klass(super_mirror);
 681   assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom");
 682   jboolean ret = sub_klass->is_subtype_of(super_klass) ?
 683                    JNI_TRUE : JNI_FALSE;
 684 #ifndef USDT2
 685   DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret);
 686 #else /* USDT2 */
 687   HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(
 688                                       ret);
 689 #endif /* USDT2 */
 690   return ret;
 691 JNI_END
 692 
 693 #ifndef USDT2
 694 DT_RETURN_MARK_DECL(Throw, jint);
 695 #else /* USDT2 */
 696 DT_RETURN_MARK_DECL(Throw, jint
 697                     , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
 698 #endif /* USDT2 */
 699 
 700 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
 701   JNIWrapper("Throw");
 702 #ifndef USDT2
 703   DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj);
 704 #else /* USDT2 */
 705   HOTSPOT_JNI_THROW_ENTRY(
 706  env, obj);
 707 #endif /* USDT2 */
 708   jint ret = JNI_OK;
 709   DT_RETURN_MARK(Throw, jint, (const jint&)ret);
 710 
 711   THROW_OOP_(JNIHandles::resolve(obj), JNI_OK);
 712   ShouldNotReachHere();
 713   return 0; // Mute compiler.
 714 JNI_END
 715 
 716 #ifndef USDT2
 717 DT_RETURN_MARK_DECL(ThrowNew, jint);
 718 #else /* USDT2 */
 719 DT_RETURN_MARK_DECL(ThrowNew, jint
 720                     , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
 721 #endif /* USDT2 */
 722 
 723 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
 724   JNIWrapper("ThrowNew");
 725 #ifndef USDT2
 726   DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message);
 727 #else /* USDT2 */
 728   HOTSPOT_JNI_THROWNEW_ENTRY(
 729                              env, clazz, (char *) message);
 730 #endif /* USDT2 */
 731   jint ret = JNI_OK;
 732   DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
 733 
 734   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
 735   Symbol*  name = k->name();
 736   Handle class_loader (THREAD,  k->class_loader());
 737   Handle protection_domain (THREAD, k->protection_domain());
 738   THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK);
 739   ShouldNotReachHere();
 740   return 0; // Mute compiler.
 741 JNI_END
 742 
 743 
 744 // JNI functions only transform a pending async exception to a synchronous
 745 // exception in ExceptionOccurred and ExceptionCheck calls, since
 746 // delivering an async exception in other places won't change the native
 747 // code's control flow and would be harmful when native code further calls
 748 // JNI functions with a pending exception. Async exception is also checked
 749 // during the call, so ExceptionOccurred/ExceptionCheck won't return
 750 // false but deliver the async exception at the very end during
 751 // state transition.
 752 
 753 static void jni_check_async_exceptions(JavaThread *thread) {
 754   assert(thread == Thread::current(), "must be itself");
 755   thread->check_and_handle_async_exceptions();
 756 }
 757 
 758 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
 759   JNIWrapper("ExceptionOccurred");
 760 #ifndef USDT2
 761   DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env);
 762 #else /* USDT2 */
 763   HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY(
 764                                       env);
 765 #endif /* USDT2 */
 766   jni_check_async_exceptions(thread);
 767   oop exception = thread->pending_exception();
 768   jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception);
 769 #ifndef USDT2
 770   DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret);
 771 #else /* USDT2 */
 772   HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN(
 773                                        ret);
 774 #endif /* USDT2 */
 775   return ret;
 776 JNI_END
 777 
 778 
 779 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env))
 780   JNIWrapper("ExceptionDescribe");
 781 #ifndef USDT2
 782   DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env);
 783 #else /* USDT2 */
 784   HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY(
 785                                       env);
 786 #endif /* USDT2 */
 787   if (thread->has_pending_exception()) {
 788     Handle ex(thread, thread->pending_exception());
 789     thread->clear_pending_exception();
 790     if (ex->is_a(SystemDictionary::ThreadDeath_klass())) {
 791       // Don't print anything if we are being killed.
 792     } else {
 793       jio_fprintf(defaultStream::error_stream(), "Exception ");
 794       if (thread != NULL && thread->threadObj() != NULL) {
 795         ResourceMark rm(THREAD);
 796         jio_fprintf(defaultStream::error_stream(),
 797         "in thread \"%s\" ", thread->get_thread_name());
 798       }
 799       if (ex->is_a(SystemDictionary::Throwable_klass())) {
 800         JavaValue result(T_VOID);
 801         JavaCalls::call_virtual(&result,
 802                                 ex,
 803                                 KlassHandle(THREAD,
 804                                   SystemDictionary::Throwable_klass()),
 805                                 vmSymbols::printStackTrace_name(),
 806                                 vmSymbols::void_method_signature(),
 807                                 THREAD);
 808         // If an exception is thrown in the call it gets thrown away. Not much
 809         // we can do with it. The native code that calls this, does not check
 810         // for the exception - hence, it might still be in the thread when DestroyVM gets
 811         // called, potentially causing a few asserts to trigger - since no pending exception
 812         // is expected.
 813         CLEAR_PENDING_EXCEPTION;
 814       } else {
 815         ResourceMark rm(THREAD);
 816         jio_fprintf(defaultStream::error_stream(),
 817         ". Uncaught exception of type %s.",
 818         ex->klass()->external_name());
 819       }
 820     }
 821   }
 822 #ifndef USDT2
 823   DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return);
 824 #else /* USDT2 */
 825   HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN(
 826                                        );
 827 #endif /* USDT2 */
 828 JNI_END
 829 
 830 
 831 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env))
 832   JNIWrapper("ExceptionClear");
 833 #ifndef USDT2
 834   DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env);
 835 #else /* USDT2 */
 836   HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY(
 837                                    env);
 838 #endif /* USDT2 */
 839 
 840   // The jni code might be using this API to clear java thrown exception.
 841   // So just mark jvmti thread exception state as exception caught.
 842   JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state();
 843   if (state != NULL && state->is_exception_detected()) {
 844     state->set_exception_caught();
 845   }
 846   thread->clear_pending_exception();
 847 #ifndef USDT2
 848   DTRACE_PROBE(hotspot_jni, ExceptionClear__return);
 849 #else /* USDT2 */
 850   HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN(
 851                                     );
 852 #endif /* USDT2 */
 853 JNI_END
 854 
 855 
 856 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg))
 857   JNIWrapper("FatalError");
 858 #ifndef USDT2
 859   DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg);
 860 #else /* USDT2 */
 861   HOTSPOT_JNI_FATALERROR_ENTRY(
 862                                env, (char *) msg);
 863 #endif /* USDT2 */
 864   tty->print_cr("FATAL ERROR in native method: %s", msg);
 865   thread->print_stack();
 866   os::abort(); // Dump core and abort
 867 JNI_END
 868 
 869 
 870 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity))
 871   JNIWrapper("PushLocalFrame");
 872 #ifndef USDT2
 873   DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity);
 874 #else /* USDT2 */
 875   HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(
 876                                    env, capacity);
 877 #endif /* USDT2 */
 878   //%note jni_11
 879   if (capacity < 0 ||
 880       ((MaxJNILocalCapacity > 0) && (capacity > MaxJNILocalCapacity))) {
 881 #ifndef USDT2
 882     DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR);
 883 #else /* USDT2 */
 884     HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(
 885                                       (uint32_t)JNI_ERR);
 886 #endif /* USDT2 */
 887     return JNI_ERR;
 888   }
 889   JNIHandleBlock* old_handles = thread->active_handles();
 890   JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
 891   assert(new_handles != NULL, "should not be NULL");
 892   new_handles->set_pop_frame_link(old_handles);
 893   thread->set_active_handles(new_handles);
 894   jint ret = JNI_OK;
 895 #ifndef USDT2
 896   DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret);
 897 #else /* USDT2 */
 898   HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(
 899                                     ret);
 900 #endif /* USDT2 */
 901   return ret;
 902 JNI_END
 903 
 904 
 905 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result))
 906   JNIWrapper("PopLocalFrame");
 907 #ifndef USDT2
 908   DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result);
 909 #else /* USDT2 */
 910   HOTSPOT_JNI_POPLOCALFRAME_ENTRY(
 911                                   env, result);
 912 #endif /* USDT2 */
 913   //%note jni_11
 914   Handle result_handle(thread, JNIHandles::resolve(result));
 915   JNIHandleBlock* old_handles = thread->active_handles();
 916   JNIHandleBlock* new_handles = old_handles->pop_frame_link();
 917   if (new_handles != NULL) {
 918     // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL.
 919     // This way code will still work if PopLocalFrame is called without a corresponding
 920     // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise
 921     // the release_block call will release the blocks.
 922     thread->set_active_handles(new_handles);
 923     old_handles->set_pop_frame_link(NULL);              // clear link we won't release new_handles below
 924     JNIHandleBlock::release_block(old_handles, thread); // may block
 925     result = JNIHandles::make_local(thread, result_handle());
 926   }
 927 #ifndef USDT2
 928   DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result);
 929 #else /* USDT2 */
 930   HOTSPOT_JNI_POPLOCALFRAME_RETURN(
 931                                    result);
 932 #endif /* USDT2 */
 933   return result;
 934 JNI_END
 935 
 936 
 937 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref))
 938   JNIWrapper("NewGlobalRef");
 939 #ifndef USDT2
 940   DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref);
 941 #else /* USDT2 */
 942   HOTSPOT_JNI_NEWGLOBALREF_ENTRY(
 943                                  env, ref);
 944 #endif /* USDT2 */
 945   Handle ref_handle(thread, JNIHandles::resolve(ref));
 946   jobject ret = JNIHandles::make_global(ref_handle);
 947 #ifndef USDT2
 948   DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret);
 949 #else /* USDT2 */
 950   HOTSPOT_JNI_NEWGLOBALREF_RETURN(
 951                                   ret);
 952 #endif /* USDT2 */
 953   return ret;
 954 JNI_END
 955 
 956 // Must be JNI_ENTRY (with HandleMark)
 957 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref))
 958   JNIWrapper("DeleteGlobalRef");
 959 #ifndef USDT2
 960   DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref);
 961 #else /* USDT2 */
 962   HOTSPOT_JNI_DELETEGLOBALREF_ENTRY(
 963                                     env, ref);
 964 #endif /* USDT2 */
 965   JNIHandles::destroy_global(ref);
 966 #ifndef USDT2
 967   DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return);
 968 #else /* USDT2 */
 969   HOTSPOT_JNI_DELETEGLOBALREF_RETURN(
 970                                      );
 971 #endif /* USDT2 */
 972 JNI_END
 973 
 974 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj))
 975   JNIWrapper("DeleteLocalRef");
 976 #ifndef USDT2
 977   DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj);
 978 #else /* USDT2 */
 979   HOTSPOT_JNI_DELETELOCALREF_ENTRY(
 980                                    env, obj);
 981 #endif /* USDT2 */
 982   JNIHandles::destroy_local(obj);
 983 #ifndef USDT2
 984   DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return);
 985 #else /* USDT2 */
 986   HOTSPOT_JNI_DELETELOCALREF_RETURN(
 987                                     );
 988 #endif /* USDT2 */
 989 JNI_END
 990 
 991 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2))
 992   JNIWrapper("IsSameObject");
 993 #ifndef USDT2
 994   DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2);
 995 #else /* USDT2 */
 996   HOTSPOT_JNI_ISSAMEOBJECT_ENTRY(
 997                                  env, r1, r2);
 998 #endif /* USDT2 */
 999   oop a = JNIHandles::resolve(r1);
1000   oop b = JNIHandles::resolve(r2);
1001   jboolean ret = a == b ? JNI_TRUE : JNI_FALSE;
1002 
1003 #ifndef USDT2
1004   DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret);
1005 #else /* USDT2 */
1006   HOTSPOT_JNI_ISSAMEOBJECT_RETURN(
1007                                   ret);
1008 #endif /* USDT2 */
1009   return ret;
1010 JNI_END
1011 
1012 
1013 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref))
1014   JNIWrapper("NewLocalRef");
1015 #ifndef USDT2
1016   DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref);
1017 #else /* USDT2 */
1018   HOTSPOT_JNI_NEWLOCALREF_ENTRY(
1019                                 env, ref);
1020 #endif /* USDT2 */
1021   jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref));
1022 #ifndef USDT2
1023   DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret);
1024 #else /* USDT2 */
1025   HOTSPOT_JNI_NEWLOCALREF_RETURN(
1026                                  ret);
1027 #endif /* USDT2 */
1028   return ret;
1029 JNI_END
1030 
1031 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity))
1032   JNIWrapper("EnsureLocalCapacity");
1033 #ifndef USDT2
1034   DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity);
1035 #else /* USDT2 */
1036   HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY(
1037                                         env, capacity);
1038 #endif /* USDT2 */
1039   jint ret;
1040   if (capacity >= 0 &&
1041       ((MaxJNILocalCapacity <= 0) || (capacity <= MaxJNILocalCapacity))) {
1042     ret = JNI_OK;
1043   } else {
1044     ret = JNI_ERR;
1045   }
1046 #ifndef USDT2
1047   DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret);
1048 #else /* USDT2 */
1049   HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN(
1050                                          ret);
1051 #endif /* USDT2 */
1052   return ret;
1053 JNI_END
1054 
1055 // Return the Handle Type
1056 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj))
1057   JNIWrapper("GetObjectRefType");
1058 #ifndef USDT2
1059   DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj);
1060 #else /* USDT2 */
1061   HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY(
1062                                      env, obj);
1063 #endif /* USDT2 */
1064   jobjectRefType ret;
1065   if (JNIHandles::is_local_handle(thread, obj) ||
1066       JNIHandles::is_frame_handle(thread, obj))
1067     ret = JNILocalRefType;
1068   else if (JNIHandles::is_global_handle(obj))
1069     ret = JNIGlobalRefType;
1070   else if (JNIHandles::is_weak_global_handle(obj))
1071     ret = JNIWeakGlobalRefType;
1072   else
1073     ret = JNIInvalidRefType;
1074 #ifndef USDT2
1075   DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret);
1076 #else /* USDT2 */
1077   HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN(
1078                                       (void *) ret);
1079 #endif /* USDT2 */
1080   return ret;
1081 JNI_END
1082 
1083 
1084 class JNI_ArgumentPusher : public SignatureIterator {
1085  protected:
1086   JavaCallArguments*  _arguments;
1087 
1088   virtual void get_bool   () = 0;
1089   virtual void get_char   () = 0;
1090   virtual void get_short  () = 0;
1091   virtual void get_byte   () = 0;
1092   virtual void get_int    () = 0;
1093   virtual void get_long   () = 0;
1094   virtual void get_float  () = 0;
1095   virtual void get_double () = 0;
1096   virtual void get_object () = 0;
1097 
1098   JNI_ArgumentPusher(Symbol* signature) : SignatureIterator(signature) {
1099     this->_return_type = T_ILLEGAL;
1100     _arguments = NULL;
1101   }
1102 
1103  public:
1104   virtual void iterate( uint64_t fingerprint ) = 0;
1105 
1106   void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; }
1107 
1108   inline void do_bool()                     { if (!is_return_type()) get_bool();   }
1109   inline void do_char()                     { if (!is_return_type()) get_char();   }
1110   inline void do_short()                    { if (!is_return_type()) get_short();  }
1111   inline void do_byte()                     { if (!is_return_type()) get_byte();   }
1112   inline void do_int()                      { if (!is_return_type()) get_int();    }
1113   inline void do_long()                     { if (!is_return_type()) get_long();   }
1114   inline void do_float()                    { if (!is_return_type()) get_float();  }
1115   inline void do_double()                   { if (!is_return_type()) get_double(); }
1116   inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); }
1117   inline void do_array(int begin, int end)  { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array
1118   inline void do_void()                     { }
1119 
1120   JavaCallArguments* arguments()     { return _arguments; }
1121   void push_receiver(Handle h)       { _arguments->push_oop(h); }
1122 };
1123 
1124 
1125 class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher {
1126  protected:
1127   va_list _ap;
1128 
1129   inline void get_bool()   {
1130     // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1131     // 0 to JNI_FALSE.  Boolean return values from native are normalized the same in
1132     // TemplateInterpreterGenerator::generate_result_handler_for and
1133     // SharedRuntime::generate_native_wrapper.
1134     jboolean b = va_arg(_ap, jint);
1135     _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1136   }
1137   inline void get_char()   { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg
1138   inline void get_short()  { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg
1139   inline void get_byte()   { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg
1140   inline void get_int()    { _arguments->push_int(va_arg(_ap, jint)); }
1141 
1142   // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
1143 
1144   inline void get_long()   { _arguments->push_long(va_arg(_ap, jlong)); }
1145   inline void get_float()  { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg
1146   inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); }
1147   inline void get_object() { _arguments->push_jobject(va_arg(_ap, jobject)); }
1148 
1149   inline void set_ap(va_list rap) {
1150 #ifdef va_copy
1151     va_copy(_ap, rap);
1152 #elif defined (__va_copy)
1153     __va_copy(_ap, rap);
1154 #else
1155     _ap = rap;
1156 #endif
1157   }
1158 
1159  public:
1160   JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap)
1161        : JNI_ArgumentPusher(signature) {
1162     set_ap(rap);
1163   }
1164   JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
1165       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1166     set_ap(rap);
1167   }
1168 
1169   // Optimized path if we have the bitvector form of signature
1170   void iterate( uint64_t fingerprint ) {
1171     if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments
1172     else {
1173       _return_type = (BasicType)((fingerprint >> static_feature_size) &
1174                                   result_feature_mask);
1175 
1176       assert(fingerprint, "Fingerprint should not be 0");
1177       fingerprint = fingerprint >> (static_feature_size + result_feature_size);
1178       while ( 1 ) {
1179         switch ( fingerprint & parameter_feature_mask ) {
1180           case bool_parm:
1181             get_bool();
1182             break;
1183           case char_parm:
1184             get_char();
1185             break;
1186           case short_parm:
1187             get_short();
1188             break;
1189           case byte_parm:
1190             get_byte();
1191             break;
1192           case int_parm:
1193             get_int();
1194             break;
1195           case obj_parm:
1196             get_object();
1197             break;
1198           case long_parm:
1199             get_long();
1200             break;
1201           case float_parm:
1202             get_float();
1203             break;
1204           case double_parm:
1205             get_double();
1206             break;
1207           case done_parm:
1208             return;
1209             break;
1210           default:
1211             ShouldNotReachHere();
1212             break;
1213         }
1214         fingerprint >>= parameter_feature_size;
1215       }
1216     }
1217   }
1218 };
1219 
1220 
1221 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher {
1222  protected:
1223   const jvalue *_ap;
1224 
1225   inline void get_bool()   {
1226     // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1227     // 0 to JNI_FALSE.  Boolean return values from native are normalized the same in
1228     // TemplateInterpreterGenerator::generate_result_handler_for and
1229     // SharedRuntime::generate_native_wrapper.
1230     jboolean b = (_ap++)->z;
1231     _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1232   }
1233   inline void get_char()   { _arguments->push_int((jint)(_ap++)->c); }
1234   inline void get_short()  { _arguments->push_int((jint)(_ap++)->s); }
1235   inline void get_byte()   { _arguments->push_int((jint)(_ap++)->b); }
1236   inline void get_int()    { _arguments->push_int((jint)(_ap++)->i); }
1237 
1238   inline void get_long()   { _arguments->push_long((_ap++)->j);  }
1239   inline void get_float()  { _arguments->push_float((_ap++)->f); }
1240   inline void get_double() { _arguments->push_double((_ap++)->d);}
1241   inline void get_object() { _arguments->push_jobject((_ap++)->l); }
1242 
1243   inline void set_ap(const jvalue *rap) { _ap = rap; }
1244 
1245  public:
1246   JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap)
1247        : JNI_ArgumentPusher(signature) {
1248     set_ap(rap);
1249   }
1250   JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap)
1251       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1252     set_ap(rap);
1253   }
1254 
1255   // Optimized path if we have the bitvector form of signature
1256   void iterate( uint64_t fingerprint ) {
1257     if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments
1258     else {
1259       _return_type = (BasicType)((fingerprint >> static_feature_size) &
1260                                   result_feature_mask);
1261       assert(fingerprint, "Fingerprint should not be 0");
1262       fingerprint = fingerprint >> (static_feature_size + result_feature_size);
1263       while ( 1 ) {
1264         switch ( fingerprint & parameter_feature_mask ) {
1265           case bool_parm:
1266             get_bool();
1267             break;
1268           case char_parm:
1269             get_char();
1270             break;
1271           case short_parm:
1272             get_short();
1273             break;
1274           case byte_parm:
1275             get_byte();
1276             break;
1277           case int_parm:
1278             get_int();
1279             break;
1280           case obj_parm:
1281             get_object();
1282             break;
1283           case long_parm:
1284             get_long();
1285             break;
1286           case float_parm:
1287             get_float();
1288             break;
1289           case double_parm:
1290             get_double();
1291             break;
1292           case done_parm:
1293             return;
1294             break;
1295           default:
1296             ShouldNotReachHere();
1297             break;
1298         }
1299         fingerprint >>= parameter_feature_size;
1300       }
1301     }
1302   }
1303 };
1304 
1305 
1306 enum JNICallType {
1307   JNI_STATIC,
1308   JNI_VIRTUAL,
1309   JNI_NONVIRTUAL
1310 };
1311 
1312 
1313 
1314 static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) {
1315   methodHandle method(THREAD, Method::resolve_jmethod_id(method_id));
1316 
1317   // Create object to hold arguments for the JavaCall, and associate it with
1318   // the jni parser
1319   ResourceMark rm(THREAD);
1320   int number_of_parameters = method->size_of_parameters();
1321   JavaCallArguments java_args(number_of_parameters);
1322   args->set_java_argument_object(&java_args);
1323 
1324   assert(method->is_static(), "method should be static");
1325 
1326   // Fill out JavaCallArguments object
1327   args->iterate( Fingerprinter(method).fingerprint() );
1328   // Initialize result type
1329   result->set_type(args->get_ret_type());
1330 
1331   // Invoke the method. Result is returned as oop.
1332   JavaCalls::call(result, method, &java_args, CHECK);
1333 
1334   // Convert result
1335   if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) {
1336     result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject()));
1337   }
1338 }
1339 
1340 
1341 static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) {
1342   oop recv = JNIHandles::resolve(receiver);
1343   if (recv == NULL) {
1344     THROW(vmSymbols::java_lang_NullPointerException());
1345   }
1346   Handle h_recv(THREAD, recv);
1347 
1348   int number_of_parameters;
1349   Method* selected_method;
1350   {
1351     Method* m = Method::resolve_jmethod_id(method_id);
1352     number_of_parameters = m->size_of_parameters();
1353     Klass* holder = m->method_holder();
1354     if (call_type != JNI_VIRTUAL) {
1355         selected_method = m;
1356     } else if (!m->has_itable_index()) {
1357       // non-interface call -- for that little speed boost, don't handlize
1358       debug_only(No_Safepoint_Verifier nosafepoint;)
1359       // jni_GetMethodID makes sure class is linked and initialized
1360       // so m should have a valid vtable index.
1361       assert(m->valid_vtable_index(), "no valid vtable index");
1362       int vtbl_index = m->vtable_index();
1363       if (vtbl_index != Method::nonvirtual_vtable_index) {
1364         Klass* k = h_recv->klass();
1365         // k might be an arrayKlassOop but all vtables start at
1366         // the same place. The cast is to avoid virtual call and assertion.
1367         InstanceKlass *ik = (InstanceKlass*)k;
1368         selected_method = ik->method_at_vtable(vtbl_index);
1369       } else {
1370         // final method
1371         selected_method = m;
1372       }
1373     } else {
1374       // interface call
1375       KlassHandle h_holder(THREAD, holder);
1376 
1377       int itbl_index = m->itable_index();
1378       Klass* k = h_recv->klass();
1379       selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK);
1380     }
1381   }
1382 
1383   methodHandle method(THREAD, selected_method);
1384 
1385   // Create object to hold arguments for the JavaCall, and associate it with
1386   // the jni parser
1387   ResourceMark rm(THREAD);
1388   JavaCallArguments java_args(number_of_parameters);
1389   args->set_java_argument_object(&java_args);
1390 
1391   // handle arguments
1392   assert(!method->is_static(), "method should not be static");
1393   args->push_receiver(h_recv); // Push jobject handle
1394 
1395   // Fill out JavaCallArguments object
1396   args->iterate( Fingerprinter(method).fingerprint() );
1397   // Initialize result type
1398   result->set_type(args->get_ret_type());
1399 
1400   // Invoke the method. Result is returned as oop.
1401   JavaCalls::call(result, method, &java_args, CHECK);
1402 
1403   // Convert result
1404   if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) {
1405     result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject()));
1406   }
1407 }
1408 
1409 
1410 static instanceOop alloc_object(jclass clazz, TRAPS) {
1411   KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
1412   k()->check_valid_for_instantiation(false, CHECK_NULL);
1413   InstanceKlass::cast(k())->initialize(CHECK_NULL);
1414   instanceOop ih = InstanceKlass::cast(k())->allocate_instance(THREAD);
1415   return ih;
1416 }
1417 
1418 #ifndef USDT2
1419 DT_RETURN_MARK_DECL(AllocObject, jobject);
1420 #else /* USDT2 */
1421 DT_RETURN_MARK_DECL(AllocObject, jobject
1422                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
1423 #endif /* USDT2 */
1424 
1425 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
1426   JNIWrapper("AllocObject");
1427 
1428 #ifndef USDT2
1429   DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz);
1430 #else /* USDT2 */
1431   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(
1432                                 env, clazz);
1433 #endif /* USDT2 */
1434   jobject ret = NULL;
1435   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
1436 
1437   instanceOop i = alloc_object(clazz, CHECK_NULL);
1438   ret = JNIHandles::make_local(env, i);
1439   return ret;
1440 JNI_END
1441 
1442 #ifndef USDT2
1443 DT_RETURN_MARK_DECL(NewObjectA, jobject);
1444 #else /* USDT2 */
1445 DT_RETURN_MARK_DECL(NewObjectA, jobject
1446                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
1447 #endif /* USDT2 */
1448 
1449 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
1450   JNIWrapper("NewObjectA");
1451 #ifndef USDT2
1452   DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID);
1453 #else /* USDT2 */
1454   HOTSPOT_JNI_NEWOBJECTA_ENTRY(
1455                                env, clazz, (uintptr_t) methodID);
1456 #endif /* USDT2 */
1457   jobject obj = NULL;
1458   DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj);
1459 
1460   instanceOop i = alloc_object(clazz, CHECK_NULL);
1461   obj = JNIHandles::make_local(env, i);
1462   JavaValue jvalue(T_VOID);
1463   JNI_ArgumentPusherArray ap(methodID, args);
1464   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1465   return obj;
1466 JNI_END
1467 
1468 #ifndef USDT2
1469 DT_RETURN_MARK_DECL(NewObjectV, jobject);
1470 #else /* USDT2 */
1471 DT_RETURN_MARK_DECL(NewObjectV, jobject
1472                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
1473 #endif /* USDT2 */
1474 
1475 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
1476   JNIWrapper("NewObjectV");
1477 #ifndef USDT2
1478   DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID);
1479 #else /* USDT2 */
1480   HOTSPOT_JNI_NEWOBJECTV_ENTRY(
1481                                env, clazz, (uintptr_t) methodID);
1482 #endif /* USDT2 */
1483   jobject obj = NULL;
1484   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
1485 
1486   instanceOop i = alloc_object(clazz, CHECK_NULL);
1487   obj = JNIHandles::make_local(env, i);
1488   JavaValue jvalue(T_VOID);
1489   JNI_ArgumentPusherVaArg ap(methodID, args);
1490   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1491   return obj;
1492 JNI_END
1493 
1494 #ifndef USDT2
1495 DT_RETURN_MARK_DECL(NewObject, jobject);
1496 #else /* USDT2 */
1497 DT_RETURN_MARK_DECL(NewObject, jobject
1498                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1499 #endif /* USDT2 */
1500 
1501 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1502   JNIWrapper("NewObject");
1503 #ifndef USDT2
1504   DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID);
1505 #else /* USDT2 */
1506   HOTSPOT_JNI_NEWOBJECT_ENTRY(
1507                               env, clazz, (uintptr_t) methodID);
1508 #endif /* USDT2 */
1509   jobject obj = NULL;
1510   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1511 
1512   instanceOop i = alloc_object(clazz, CHECK_NULL);
1513   obj = JNIHandles::make_local(env, i);
1514   va_list args;
1515   va_start(args, methodID);
1516   JavaValue jvalue(T_VOID);
1517   JNI_ArgumentPusherVaArg ap(methodID, args);
1518   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1519   va_end(args);
1520   return obj;
1521 JNI_END
1522 
1523 
1524 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1525   JNIWrapper("GetObjectClass");
1526 #ifndef USDT2
1527   DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj);
1528 #else /* USDT2 */
1529   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(
1530                                    env, obj);
1531 #endif /* USDT2 */
1532   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1533   jclass ret =
1534     (jclass) JNIHandles::make_local(env, k->java_mirror());
1535 #ifndef USDT2
1536   DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret);
1537 #else /* USDT2 */
1538   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(
1539                                     ret);
1540 #endif /* USDT2 */
1541   return ret;
1542 JNI_END
1543 
1544 JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz))
1545   JNIWrapper("IsInstanceOf");
1546 #ifndef USDT2
1547   DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz);
1548 #else /* USDT2 */
1549   HOTSPOT_JNI_ISINSTANCEOF_ENTRY(
1550                                  env, obj, clazz);
1551 #endif /* USDT2 */
1552   jboolean ret = JNI_TRUE;
1553   if (obj != NULL) {
1554     ret = JNI_FALSE;
1555     Klass* k = java_lang_Class::as_Klass(
1556       JNIHandles::resolve_non_null(clazz));
1557     if (k != NULL) {
1558       ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE;
1559     }
1560   }
1561 #ifndef USDT2
1562   DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret);
1563 #else /* USDT2 */
1564   HOTSPOT_JNI_ISINSTANCEOF_RETURN(
1565                                   ret);
1566 #endif /* USDT2 */
1567   return ret;
1568 JNI_END
1569 
1570 
1571 static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str,
1572                                const char *sig, bool is_static, TRAPS) {
1573   // %%%% This code should probably just call into a method in the LinkResolver
1574   //
1575   // The class should have been loaded (we have an instance of the class
1576   // passed in) so the method and signature should already be in the symbol
1577   // table.  If they're not there, the method doesn't exist.
1578   const char *name_to_probe = (name_str == NULL)
1579                         ? vmSymbols::object_initializer_name()->as_C_string()
1580                         : name_str;
1581   TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe));
1582   TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig));
1583 
1584   if (name == NULL || signature == NULL) {
1585     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1586   }
1587 
1588   // Throw a NoSuchMethodError exception if we have an instance of a
1589   // primitive java.lang.Class
1590   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) {
1591     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1592   }
1593 
1594   KlassHandle klass(THREAD,
1595                java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
1596 
1597   // Make sure class is linked and initialized before handing id's out to
1598   // Method*s.
1599   klass()->initialize(CHECK_NULL);
1600 
1601   Method* m;
1602   if (name == vmSymbols::object_initializer_name() ||
1603       name == vmSymbols::class_initializer_name()) {
1604     // Never search superclasses for constructors
1605     if (klass->oop_is_instance()) {
1606       m = InstanceKlass::cast(klass())->find_method(name, signature);
1607     } else {
1608       m = NULL;
1609     }
1610   } else {
1611     m = klass->lookup_method(name, signature);
1612     if (m == NULL &&  klass->oop_is_instance()) {
1613       m = InstanceKlass::cast(klass())->lookup_method_in_ordered_interfaces(name, signature);
1614     }
1615   }
1616   if (m == NULL || (m->is_static() != is_static)) {
1617     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1618   }
1619   return m->jmethod_id();
1620 }
1621 
1622 
1623 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz,
1624           const char *name, const char *sig))
1625   JNIWrapper("GetMethodID");
1626 #ifndef USDT2
1627   DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig);
1628 #else /* USDT2 */
1629   HOTSPOT_JNI_GETMETHODID_ENTRY(
1630                                 env, clazz, (char *) name, (char *) sig);
1631 #endif /* USDT2 */
1632   jmethodID ret = get_method_id(env, clazz, name, sig, false, thread);
1633 #ifndef USDT2
1634   DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret);
1635 #else /* USDT2 */
1636   HOTSPOT_JNI_GETMETHODID_RETURN(
1637                                  (uintptr_t) ret);
1638 #endif /* USDT2 */
1639   return ret;
1640 JNI_END
1641 
1642 
1643 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz,
1644           const char *name, const char *sig))
1645   JNIWrapper("GetStaticMethodID");
1646 #ifndef USDT2
1647   DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig);
1648 #else /* USDT2 */
1649   HOTSPOT_JNI_GETSTATICMETHODID_ENTRY(
1650                                       env, (char *) clazz, (char *) name, (char *)sig);
1651 #endif /* USDT2 */
1652   jmethodID ret = get_method_id(env, clazz, name, sig, true, thread);
1653 #ifndef USDT2
1654   DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret);
1655 #else /* USDT2 */
1656   HOTSPOT_JNI_GETSTATICMETHODID_RETURN(
1657                                        (uintptr_t) ret);
1658 #endif /* USDT2 */
1659   return ret;
1660 JNI_END
1661 
1662 
1663 
1664 //
1665 // Calling Methods
1666 //
1667 
1668 #ifndef USDT2
1669 #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \
1670 \
1671   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\
1672   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType);\
1673   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType);\
1674 \
1675 JNI_ENTRY(ResultType, \
1676           jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \
1677   JNIWrapper("Call" XSTR(Result) "Method"); \
1678 \
1679   DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID); \
1680   ResultType ret = 0;\
1681   DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \
1682                      (const ResultType&)ret);\
1683 \
1684   va_list args; \
1685   va_start(args, methodID); \
1686   JavaValue jvalue(Tag); \
1687   JNI_ArgumentPusherVaArg ap(methodID, args); \
1688   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1689   va_end(args); \
1690   ret = jvalue.get_##ResultType(); \
1691   return ret;\
1692 JNI_END \
1693 \
1694 \
1695 JNI_ENTRY(ResultType, \
1696           jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \
1697   JNIWrapper("Call" XSTR(Result) "MethodV"); \
1698 \
1699   DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID); \
1700   ResultType ret = 0;\
1701   DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \
1702                      (const ResultType&)ret);\
1703 \
1704   JavaValue jvalue(Tag); \
1705   JNI_ArgumentPusherVaArg ap(methodID, args); \
1706   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1707   ret = jvalue.get_##ResultType(); \
1708   return ret;\
1709 JNI_END \
1710 \
1711 \
1712 JNI_ENTRY(ResultType, \
1713           jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \
1714   JNIWrapper("Call" XSTR(Result) "MethodA"); \
1715   DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID); \
1716   ResultType ret = 0;\
1717   DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \
1718                      (const ResultType&)ret);\
1719 \
1720   JavaValue jvalue(Tag); \
1721   JNI_ArgumentPusherArray ap(methodID, args); \
1722   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1723   ret = jvalue.get_##ResultType(); \
1724   return ret;\
1725 JNI_END
1726 
1727 // the runtime type of subword integral basic types is integer
1728 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN)
1729 DEFINE_CALLMETHOD(jbyte,    Byte,    T_BYTE)
1730 DEFINE_CALLMETHOD(jchar,    Char,    T_CHAR)
1731 DEFINE_CALLMETHOD(jshort,   Short,   T_SHORT)
1732 
1733 DEFINE_CALLMETHOD(jobject,  Object,  T_OBJECT)
1734 DEFINE_CALLMETHOD(jint,     Int,     T_INT)
1735 DEFINE_CALLMETHOD(jlong,    Long,    T_LONG)
1736 DEFINE_CALLMETHOD(jfloat,   Float,   T_FLOAT)
1737 DEFINE_CALLMETHOD(jdouble,  Double,  T_DOUBLE)
1738 
1739 DT_VOID_RETURN_MARK_DECL(CallVoidMethod);
1740 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV);
1741 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA);
1742 
1743 #else /* USDT2 */
1744 
1745 #define DEFINE_CALLMETHOD(ResultType, Result, Tag \
1746                           , EntryProbe, ReturnProbe)    \
1747 \
1748   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \
1749                           , ReturnProbe);                          \
1750 \
1751 JNI_ENTRY(ResultType, \
1752           jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \
1753   JNIWrapper("Call" XSTR(Result) "Method"); \
1754 \
1755   EntryProbe; \
1756   ResultType ret = 0;\
1757   DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \
1758                      (const ResultType&)ret);\
1759 \
1760   va_list args; \
1761   va_start(args, methodID); \
1762   JavaValue jvalue(Tag); \
1763   JNI_ArgumentPusherVaArg ap(methodID, args); \
1764   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1765   va_end(args); \
1766   ret = jvalue.get_##ResultType(); \
1767   return ret;\
1768 JNI_END
1769 
1770 // the runtime type of subword integral basic types is integer
1771 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN
1772                   , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1773                   HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref))
1774 DEFINE_CALLMETHOD(jbyte,    Byte,    T_BYTE
1775                   , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1776                   HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref))
1777 DEFINE_CALLMETHOD(jchar,    Char,    T_CHAR
1778                   , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1779                   HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref))
1780 DEFINE_CALLMETHOD(jshort,   Short,   T_SHORT
1781                   , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1782                   HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref))
1783 
1784 DEFINE_CALLMETHOD(jobject,  Object,  T_OBJECT
1785                   , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1786                   HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref))
1787 DEFINE_CALLMETHOD(jint,     Int,     T_INT,
1788                   HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1789                   HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref))
1790 DEFINE_CALLMETHOD(jlong,    Long,    T_LONG
1791                   , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1792                   HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref))
1793 // Float and double probes don't return value because dtrace doesn't currently support it
1794 DEFINE_CALLMETHOD(jfloat,   Float,   T_FLOAT
1795                   , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1796                   HOTSPOT_JNI_CALLFLOATMETHOD_RETURN())
1797 DEFINE_CALLMETHOD(jdouble,  Double,  T_DOUBLE
1798                   , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1799                   HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN())
1800 
1801 #define DEFINE_CALLMETHODV(ResultType, Result, Tag \
1802                           , EntryProbe, ReturnProbe)    \
1803 \
1804   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \
1805                           , ReturnProbe);                          \
1806 \
1807 JNI_ENTRY(ResultType, \
1808           jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \
1809   JNIWrapper("Call" XSTR(Result) "MethodV"); \
1810 \
1811   EntryProbe;\
1812   ResultType ret = 0;\
1813   DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \
1814                      (const ResultType&)ret);\
1815 \
1816   JavaValue jvalue(Tag); \
1817   JNI_ArgumentPusherVaArg ap(methodID, args); \
1818   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1819   ret = jvalue.get_##ResultType(); \
1820   return ret;\
1821 JNI_END
1822 
1823 // the runtime type of subword integral basic types is integer
1824 DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN
1825                   , HOTSPOT_JNI_CALLBOOLEANMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1826                   HOTSPOT_JNI_CALLBOOLEANMETHODV_RETURN(_ret_ref))
1827 DEFINE_CALLMETHODV(jbyte,    Byte,    T_BYTE
1828                   , HOTSPOT_JNI_CALLBYTEMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1829                   HOTSPOT_JNI_CALLBYTEMETHODV_RETURN(_ret_ref))
1830 DEFINE_CALLMETHODV(jchar,    Char,    T_CHAR
1831                   , HOTSPOT_JNI_CALLCHARMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1832                   HOTSPOT_JNI_CALLCHARMETHODV_RETURN(_ret_ref))
1833 DEFINE_CALLMETHODV(jshort,   Short,   T_SHORT
1834                   , HOTSPOT_JNI_CALLSHORTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1835                   HOTSPOT_JNI_CALLSHORTMETHODV_RETURN(_ret_ref))
1836 
1837 DEFINE_CALLMETHODV(jobject,  Object,  T_OBJECT
1838                   , HOTSPOT_JNI_CALLOBJECTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1839                   HOTSPOT_JNI_CALLOBJECTMETHODV_RETURN(_ret_ref))
1840 DEFINE_CALLMETHODV(jint,     Int,     T_INT,
1841                   HOTSPOT_JNI_CALLINTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1842                   HOTSPOT_JNI_CALLINTMETHODV_RETURN(_ret_ref))
1843 DEFINE_CALLMETHODV(jlong,    Long,    T_LONG
1844                   , HOTSPOT_JNI_CALLLONGMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1845                   HOTSPOT_JNI_CALLLONGMETHODV_RETURN(_ret_ref))
1846 // Float and double probes don't return value because dtrace doesn't currently support it
1847 DEFINE_CALLMETHODV(jfloat,   Float,   T_FLOAT
1848                   , HOTSPOT_JNI_CALLFLOATMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1849                   HOTSPOT_JNI_CALLFLOATMETHODV_RETURN())
1850 DEFINE_CALLMETHODV(jdouble,  Double,  T_DOUBLE
1851                   , HOTSPOT_JNI_CALLDOUBLEMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1852                   HOTSPOT_JNI_CALLDOUBLEMETHODV_RETURN())
1853 
1854 #define DEFINE_CALLMETHODA(ResultType, Result, Tag \
1855                           , EntryProbe, ReturnProbe)    \
1856 \
1857   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \
1858                           , ReturnProbe);                          \
1859 \
1860 JNI_ENTRY(ResultType, \
1861           jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \
1862   JNIWrapper("Call" XSTR(Result) "MethodA"); \
1863   EntryProbe; \
1864   ResultType ret = 0;\
1865   DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \
1866                      (const ResultType&)ret);\
1867 \
1868   JavaValue jvalue(Tag); \
1869   JNI_ArgumentPusherArray ap(methodID, args); \
1870   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1871   ret = jvalue.get_##ResultType(); \
1872   return ret;\
1873 JNI_END
1874 
1875 // the runtime type of subword integral basic types is integer
1876 DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN
1877                   , HOTSPOT_JNI_CALLBOOLEANMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1878                   HOTSPOT_JNI_CALLBOOLEANMETHODA_RETURN(_ret_ref))
1879 DEFINE_CALLMETHODA(jbyte,    Byte,    T_BYTE
1880                   , HOTSPOT_JNI_CALLBYTEMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1881                   HOTSPOT_JNI_CALLBYTEMETHODA_RETURN(_ret_ref))
1882 DEFINE_CALLMETHODA(jchar,    Char,    T_CHAR
1883                   , HOTSPOT_JNI_CALLCHARMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1884                   HOTSPOT_JNI_CALLCHARMETHODA_RETURN(_ret_ref))
1885 DEFINE_CALLMETHODA(jshort,   Short,   T_SHORT
1886                   , HOTSPOT_JNI_CALLSHORTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1887                   HOTSPOT_JNI_CALLSHORTMETHODA_RETURN(_ret_ref))
1888 
1889 DEFINE_CALLMETHODA(jobject,  Object,  T_OBJECT
1890                   , HOTSPOT_JNI_CALLOBJECTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1891                   HOTSPOT_JNI_CALLOBJECTMETHODA_RETURN(_ret_ref))
1892 DEFINE_CALLMETHODA(jint,     Int,     T_INT,
1893                   HOTSPOT_JNI_CALLINTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1894                   HOTSPOT_JNI_CALLINTMETHODA_RETURN(_ret_ref))
1895 DEFINE_CALLMETHODA(jlong,    Long,    T_LONG
1896                   , HOTSPOT_JNI_CALLLONGMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1897                   HOTSPOT_JNI_CALLLONGMETHODA_RETURN(_ret_ref))
1898 // Float and double probes don't return value because dtrace doesn't currently support it
1899 DEFINE_CALLMETHODA(jfloat,   Float,   T_FLOAT
1900                   , HOTSPOT_JNI_CALLFLOATMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1901                   HOTSPOT_JNI_CALLFLOATMETHODA_RETURN())
1902 DEFINE_CALLMETHODA(jdouble,  Double,  T_DOUBLE
1903                   , HOTSPOT_JNI_CALLDOUBLEMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1904                   HOTSPOT_JNI_CALLDOUBLEMETHODA_RETURN())
1905 
1906 DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN());
1907 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN());
1908 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN());
1909 
1910 #endif /* USDT2 */
1911 
1912 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...))
1913   JNIWrapper("CallVoidMethod");
1914 #ifndef USDT2
1915   DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID);
1916 #else /* USDT2 */
1917   HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY(
1918                                    env, obj, (uintptr_t) methodID);
1919 #endif /* USDT2 */
1920   DT_VOID_RETURN_MARK(CallVoidMethod);
1921 
1922   va_list args;
1923   va_start(args, methodID);
1924   JavaValue jvalue(T_VOID);
1925   JNI_ArgumentPusherVaArg ap(methodID, args);
1926   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1927   va_end(args);
1928 JNI_END
1929 
1930 
1931 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args))
1932   JNIWrapper("CallVoidMethodV");
1933 #ifndef USDT2
1934   DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID);
1935 #else /* USDT2 */
1936   HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY(
1937                                     env, obj, (uintptr_t) methodID);
1938 #endif /* USDT2 */
1939   DT_VOID_RETURN_MARK(CallVoidMethodV);
1940 
1941   JavaValue jvalue(T_VOID);
1942   JNI_ArgumentPusherVaArg ap(methodID, args);
1943   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1944 JNI_END
1945 
1946 
1947 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args))
1948   JNIWrapper("CallVoidMethodA");
1949 #ifndef USDT2
1950   DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID);
1951 #else /* USDT2 */
1952   HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY(
1953                                     env, obj, (uintptr_t) methodID);
1954 #endif /* USDT2 */
1955   DT_VOID_RETURN_MARK(CallVoidMethodA);
1956 
1957   JavaValue jvalue(T_VOID);
1958   JNI_ArgumentPusherArray ap(methodID, args);
1959   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1960 JNI_END
1961 
1962 
1963 #ifndef USDT2
1964 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \
1965 \
1966   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\
1967   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType);\
1968   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType);\
1969 \
1970 JNI_ENTRY(ResultType, \
1971           jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \
1972   JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \
1973 \
1974   DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##Method__entry, env, obj, cls, methodID);\
1975   ResultType ret;\
1976   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \
1977                      (const ResultType&)ret);\
1978 \
1979   va_list args; \
1980   va_start(args, methodID); \
1981   JavaValue jvalue(Tag); \
1982   JNI_ArgumentPusherVaArg ap(methodID, args); \
1983   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
1984   va_end(args); \
1985   ret = jvalue.get_##ResultType(); \
1986   return ret;\
1987 JNI_END \
1988 \
1989 JNI_ENTRY(ResultType, \
1990           jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \
1991   JNIWrapper("CallNonvitual" XSTR(Result) "#MethodV"); \
1992   DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodV__entry, env, obj, cls, methodID);\
1993   ResultType ret;\
1994   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \
1995                      (const ResultType&)ret);\
1996 \
1997   JavaValue jvalue(Tag); \
1998   JNI_ArgumentPusherVaArg ap(methodID, args); \
1999   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
2000   ret = jvalue.get_##ResultType(); \
2001   return ret;\
2002 JNI_END \
2003 \
2004 JNI_ENTRY(ResultType, \
2005           jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \
2006   JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \
2007   DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodA__entry, env, obj, cls, methodID);\
2008   ResultType ret;\
2009   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \
2010                      (const ResultType&)ret);\
2011 \
2012   JavaValue jvalue(Tag); \
2013   JNI_ArgumentPusherArray ap(methodID, args); \
2014   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
2015   ret = jvalue.get_##ResultType(); \
2016   return ret;\
2017 JNI_END
2018 
2019 // the runtime type of subword integral basic types is integer
2020 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN)
2021 DEFINE_CALLNONVIRTUALMETHOD(jbyte,    Byte,    T_BYTE)
2022 DEFINE_CALLNONVIRTUALMETHOD(jchar,    Char,    T_CHAR)
2023 DEFINE_CALLNONVIRTUALMETHOD(jshort,   Short,   T_SHORT)
2024 
2025 DEFINE_CALLNONVIRTUALMETHOD(jobject,  Object,  T_OBJECT)
2026 DEFINE_CALLNONVIRTUALMETHOD(jint,     Int,     T_INT)
2027 DEFINE_CALLNONVIRTUALMETHOD(jlong,    Long,    T_LONG)
2028 DEFINE_CALLNONVIRTUALMETHOD(jfloat,   Float,   T_FLOAT)
2029 DEFINE_CALLNONVIRTUALMETHOD(jdouble,  Double,  T_DOUBLE)
2030 
2031 
2032 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod);
2033 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV);
2034 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA);
2035 
2036 #else /* USDT2 */
2037 
2038 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \
2039                                     , EntryProbe, ReturnProbe)      \
2040 \
2041   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \
2042                           , ReturnProbe);\
2043 \
2044 JNI_ENTRY(ResultType, \
2045           jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \
2046   JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \
2047 \
2048   EntryProbe;\
2049   ResultType ret;\
2050   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \
2051                      (const ResultType&)ret);\
2052 \
2053   va_list args; \
2054   va_start(args, methodID); \
2055   JavaValue jvalue(Tag); \
2056   JNI_ArgumentPusherVaArg ap(methodID, args); \
2057   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
2058   va_end(args); \
2059   ret = jvalue.get_##ResultType(); \
2060   return ret;\
2061 JNI_END
2062 
2063 // the runtime type of subword integral basic types is integer
2064 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN
2065                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2066                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref))
2067 DEFINE_CALLNONVIRTUALMETHOD(jbyte,    Byte,    T_BYTE
2068                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2069                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref))
2070 DEFINE_CALLNONVIRTUALMETHOD(jchar,    Char,    T_CHAR
2071                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2072                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref))
2073 DEFINE_CALLNONVIRTUALMETHOD(jshort,   Short,   T_SHORT
2074                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2075                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref))
2076 
2077 DEFINE_CALLNONVIRTUALMETHOD(jobject,  Object,  T_OBJECT
2078                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2079                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref))
2080 DEFINE_CALLNONVIRTUALMETHOD(jint,     Int,     T_INT
2081                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2082                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref))
2083 DEFINE_CALLNONVIRTUALMETHOD(jlong,    Long,    T_LONG
2084                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2085 // Float and double probes don't return value because dtrace doesn't currently support it
2086                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref))
2087 DEFINE_CALLNONVIRTUALMETHOD(jfloat,   Float,   T_FLOAT
2088                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2089                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN())
2090 DEFINE_CALLNONVIRTUALMETHOD(jdouble,  Double,  T_DOUBLE
2091                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
2092                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN())
2093 
2094 #define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \
2095                                     , EntryProbe, ReturnProbe)      \
2096 \
2097   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \
2098                           , ReturnProbe);\
2099 \
2100 JNI_ENTRY(ResultType, \
2101           jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \
2102   JNIWrapper("CallNonvitual" XSTR(Result) "MethodV"); \
2103 \
2104   EntryProbe;\
2105   ResultType ret;\
2106   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \
2107                      (const ResultType&)ret);\
2108 \
2109   JavaValue jvalue(Tag); \
2110   JNI_ArgumentPusherVaArg ap(methodID, args); \
2111   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
2112   ret = jvalue.get_##ResultType(); \
2113   return ret;\
2114 JNI_END
2115 
2116 // the runtime type of subword integral basic types is integer
2117 DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN
2118                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2119                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref))
2120 DEFINE_CALLNONVIRTUALMETHODV(jbyte,    Byte,    T_BYTE
2121                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2122                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref))
2123 DEFINE_CALLNONVIRTUALMETHODV(jchar,    Char,    T_CHAR
2124                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2125                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref))
2126 DEFINE_CALLNONVIRTUALMETHODV(jshort,   Short,   T_SHORT
2127                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2128                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref))
2129 
2130 DEFINE_CALLNONVIRTUALMETHODV(jobject,  Object,  T_OBJECT
2131                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2132                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref))
2133 DEFINE_CALLNONVIRTUALMETHODV(jint,     Int,     T_INT
2134                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2135                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref))
2136 DEFINE_CALLNONVIRTUALMETHODV(jlong,    Long,    T_LONG
2137                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2138 // Float and double probes don't return value because dtrace doesn't currently support it
2139                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref))
2140 DEFINE_CALLNONVIRTUALMETHODV(jfloat,   Float,   T_FLOAT
2141                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2142                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN())
2143 DEFINE_CALLNONVIRTUALMETHODV(jdouble,  Double,  T_DOUBLE
2144                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
2145                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN())
2146 
2147 #define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \
2148                                     , EntryProbe, ReturnProbe)      \
2149 \
2150   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \
2151                           , ReturnProbe);\
2152 \
2153 JNI_ENTRY(ResultType, \
2154           jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \
2155   JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \
2156 \
2157   EntryProbe;\
2158   ResultType ret;\
2159   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \
2160                      (const ResultType&)ret);\
2161 \
2162   JavaValue jvalue(Tag); \
2163   JNI_ArgumentPusherArray ap(methodID, args); \
2164   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
2165   ret = jvalue.get_##ResultType(); \
2166   return ret;\
2167 JNI_END
2168 
2169 // the runtime type of subword integral basic types is integer
2170 DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN
2171                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2172                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref))
2173 DEFINE_CALLNONVIRTUALMETHODA(jbyte,    Byte,    T_BYTE
2174                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2175                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref))
2176 DEFINE_CALLNONVIRTUALMETHODA(jchar,    Char,    T_CHAR
2177                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2178                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref))
2179 DEFINE_CALLNONVIRTUALMETHODA(jshort,   Short,   T_SHORT
2180                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2181                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref))
2182 
2183 DEFINE_CALLNONVIRTUALMETHODA(jobject,  Object,  T_OBJECT
2184                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2185                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref))
2186 DEFINE_CALLNONVIRTUALMETHODA(jint,     Int,     T_INT
2187                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2188                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref))
2189 DEFINE_CALLNONVIRTUALMETHODA(jlong,    Long,    T_LONG
2190                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2191 // Float and double probes don't return value because dtrace doesn't currently support it
2192                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref))
2193 DEFINE_CALLNONVIRTUALMETHODA(jfloat,   Float,   T_FLOAT
2194                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2195                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN())
2196 DEFINE_CALLNONVIRTUALMETHODA(jdouble,  Double,  T_DOUBLE
2197                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
2198                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN())
2199 
2200 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod
2201                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN());
2202 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV
2203                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN());
2204 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA
2205                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN());
2206 #endif /* USDT2 */
2207 
2208 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...))
2209   JNIWrapper("CallNonvirtualVoidMethod");
2210 
2211 #ifndef USDT2
2212   DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry,
2213                env, obj, cls, methodID);
2214 #else /* USDT2 */
2215   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY(
2216                env, obj, cls, (uintptr_t) methodID);
2217 #endif /* USDT2 */
2218   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod);
2219 
2220   va_list args;
2221   va_start(args, methodID);
2222   JavaValue jvalue(T_VOID);
2223   JNI_ArgumentPusherVaArg ap(methodID, args);
2224   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
2225   va_end(args);
2226 JNI_END
2227 
2228 
2229 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args))
2230   JNIWrapper("CallNonvirtualVoidMethodV");
2231 
2232 #ifndef USDT2
2233   DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry,
2234                env, obj, cls, methodID);
2235 #else /* USDT2 */
2236   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY(
2237                env, obj, cls, (uintptr_t) methodID);
2238 #endif /* USDT2 */
2239   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV);
2240 
2241   JavaValue jvalue(T_VOID);
2242   JNI_ArgumentPusherVaArg ap(methodID, args);
2243   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
2244 JNI_END
2245 
2246 
2247 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args))
2248   JNIWrapper("CallNonvirtualVoidMethodA");
2249 #ifndef USDT2
2250   DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry,
2251                 env, obj, cls, methodID);
2252 #else /* USDT2 */
2253   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY(
2254                 env, obj, cls, (uintptr_t) methodID);
2255 #endif /* USDT2 */
2256   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA);
2257   JavaValue jvalue(T_VOID);
2258   JNI_ArgumentPusherArray ap(methodID, args);
2259   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
2260 JNI_END
2261 
2262 
2263 #ifndef USDT2
2264 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \
2265 \
2266   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\
2267   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType);\
2268   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType);\
2269 \
2270 JNI_ENTRY(ResultType, \
2271           jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \
2272   JNIWrapper("CallStatic" XSTR(Result) "Method"); \
2273 \
2274   DTRACE_PROBE3(hotspot_jni, CallStatic##Result##Method__entry, env, cls, methodID);\
2275   ResultType ret = 0;\
2276   DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \
2277                      (const ResultType&)ret);\
2278 \
2279   va_list args; \
2280   va_start(args, methodID); \
2281   JavaValue jvalue(Tag); \
2282   JNI_ArgumentPusherVaArg ap(methodID, args); \
2283   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
2284   va_end(args); \
2285   ret = jvalue.get_##ResultType(); \
2286   return ret;\
2287 JNI_END \
2288 \
2289 JNI_ENTRY(ResultType, \
2290           jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
2291   JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \
2292   DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodV__entry, env, cls, methodID);\
2293   ResultType ret = 0;\
2294   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
2295                      (const ResultType&)ret);\
2296 \
2297   JavaValue jvalue(Tag); \
2298   JNI_ArgumentPusherVaArg ap(methodID, args); \
2299   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
2300   ret = jvalue.get_##ResultType(); \
2301   return ret;\
2302 JNI_END \
2303 \
2304 JNI_ENTRY(ResultType, \
2305           jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \
2306   JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \
2307   DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodA__entry, env, cls, methodID);\
2308   ResultType ret = 0;\
2309   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \
2310                      (const ResultType&)ret);\
2311 \
2312   JavaValue jvalue(Tag); \
2313   JNI_ArgumentPusherArray ap(methodID, args); \
2314   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
2315   ret = jvalue.get_##ResultType(); \
2316   return ret;\
2317 JNI_END
2318 
2319 // the runtime type of subword integral basic types is integer
2320 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN)
2321 DEFINE_CALLSTATICMETHOD(jbyte,    Byte,    T_BYTE)
2322 DEFINE_CALLSTATICMETHOD(jchar,    Char,    T_CHAR)
2323 DEFINE_CALLSTATICMETHOD(jshort,   Short,   T_SHORT)
2324 
2325 DEFINE_CALLSTATICMETHOD(jobject,  Object,  T_OBJECT)
2326 DEFINE_CALLSTATICMETHOD(jint,     Int,     T_INT)
2327 DEFINE_CALLSTATICMETHOD(jlong,    Long,    T_LONG)
2328 DEFINE_CALLSTATICMETHOD(jfloat,   Float,   T_FLOAT)
2329 DEFINE_CALLSTATICMETHOD(jdouble,  Double,  T_DOUBLE)
2330 
2331 
2332 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod);
2333 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV);
2334 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA);
2335 
2336 #else /* USDT2 */
2337 
2338 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \
2339                                 , EntryProbe, ResultProbe) \
2340 \
2341   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \
2342                           , ResultProbe);                               \
2343 \
2344 JNI_ENTRY(ResultType, \
2345           jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \
2346   JNIWrapper("CallStatic" XSTR(Result) "Method"); \
2347 \
2348   EntryProbe; \
2349   ResultType ret = 0;\
2350   DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \
2351                      (const ResultType&)ret);\
2352 \
2353   va_list args; \
2354   va_start(args, methodID); \
2355   JavaValue jvalue(Tag); \
2356   JNI_ArgumentPusherVaArg ap(methodID, args); \
2357   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
2358   va_end(args); \
2359   ret = jvalue.get_##ResultType(); \
2360   return ret;\
2361 JNI_END
2362 
2363 // the runtime type of subword integral basic types is integer
2364 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN
2365                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2366                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref));
2367 DEFINE_CALLSTATICMETHOD(jbyte,    Byte,    T_BYTE
2368                         , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2369                         HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref));
2370 DEFINE_CALLSTATICMETHOD(jchar,    Char,    T_CHAR
2371                         , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2372                         HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref));
2373 DEFINE_CALLSTATICMETHOD(jshort,   Short,   T_SHORT
2374                         , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2375                         HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref));
2376 
2377 DEFINE_CALLSTATICMETHOD(jobject,  Object,  T_OBJECT
2378                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2379                         HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref));
2380 DEFINE_CALLSTATICMETHOD(jint,     Int,     T_INT
2381                         , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2382                         HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref));
2383 DEFINE_CALLSTATICMETHOD(jlong,    Long,    T_LONG
2384                         , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2385                         HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref));
2386 // Float and double probes don't return value because dtrace doesn't currently support it
2387 DEFINE_CALLSTATICMETHOD(jfloat,   Float,   T_FLOAT
2388                         , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2389                         HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN());
2390 DEFINE_CALLSTATICMETHOD(jdouble,  Double,  T_DOUBLE
2391                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
2392                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN());
2393 
2394 #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \
2395                                 , EntryProbe, ResultProbe) \
2396 \
2397   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \
2398                           , ResultProbe);                               \
2399 \
2400 JNI_ENTRY(ResultType, \
2401           jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
2402   JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \
2403 \
2404   EntryProbe; \
2405   ResultType ret = 0;\
2406   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
2407                      (const ResultType&)ret);\
2408 \
2409   JavaValue jvalue(Tag); \
2410   JNI_ArgumentPusherVaArg ap(methodID, args); \
2411   /* Make sure class is initialized before trying to invoke its method */ \
2412   KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls))); \
2413   k()->initialize(CHECK_0); \
2414   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
2415   va_end(args); \
2416   ret = jvalue.get_##ResultType(); \
2417   return ret;\
2418 JNI_END
2419 
2420 // the runtime type of subword integral basic types is integer
2421 DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN
2422                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2423                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref));
2424 DEFINE_CALLSTATICMETHODV(jbyte,    Byte,    T_BYTE
2425                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2426                         HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref));
2427 DEFINE_CALLSTATICMETHODV(jchar,    Char,    T_CHAR
2428                         , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2429                         HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref));
2430 DEFINE_CALLSTATICMETHODV(jshort,   Short,   T_SHORT
2431                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2432                         HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref));
2433 
2434 DEFINE_CALLSTATICMETHODV(jobject,  Object,  T_OBJECT
2435                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2436                         HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref));
2437 DEFINE_CALLSTATICMETHODV(jint,     Int,     T_INT
2438                         , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2439                         HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref));
2440 DEFINE_CALLSTATICMETHODV(jlong,    Long,    T_LONG
2441                         , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2442                         HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref));
2443 // Float and double probes don't return value because dtrace doesn't currently support it
2444 DEFINE_CALLSTATICMETHODV(jfloat,   Float,   T_FLOAT
2445                         , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2446                         HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN());
2447 DEFINE_CALLSTATICMETHODV(jdouble,  Double,  T_DOUBLE
2448                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
2449                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN());
2450 
2451 #define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \
2452                                 , EntryProbe, ResultProbe) \
2453 \
2454   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \
2455                           , ResultProbe);                               \
2456 \
2457 JNI_ENTRY(ResultType, \
2458           jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \
2459   JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \
2460 \
2461   EntryProbe; \
2462   ResultType ret = 0;\
2463   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \
2464                      (const ResultType&)ret);\
2465 \
2466   JavaValue jvalue(Tag); \
2467   JNI_ArgumentPusherArray ap(methodID, args); \
2468   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
2469   ret = jvalue.get_##ResultType(); \
2470   return ret;\
2471 JNI_END
2472 
2473 // the runtime type of subword integral basic types is integer
2474 DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN
2475                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2476                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref));
2477 DEFINE_CALLSTATICMETHODA(jbyte,    Byte,    T_BYTE
2478                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2479                         HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref));
2480 DEFINE_CALLSTATICMETHODA(jchar,    Char,    T_CHAR
2481                         , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2482                         HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref));
2483 DEFINE_CALLSTATICMETHODA(jshort,   Short,   T_SHORT
2484                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2485                         HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref));
2486 
2487 DEFINE_CALLSTATICMETHODA(jobject,  Object,  T_OBJECT
2488                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2489                         HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref));
2490 DEFINE_CALLSTATICMETHODA(jint,     Int,     T_INT
2491                         , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2492                         HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref));
2493 DEFINE_CALLSTATICMETHODA(jlong,    Long,    T_LONG
2494                         , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2495                         HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref));
2496 // Float and double probes don't return value because dtrace doesn't currently support it
2497 DEFINE_CALLSTATICMETHODA(jfloat,   Float,   T_FLOAT
2498                         , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2499                         HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN());
2500 DEFINE_CALLSTATICMETHODA(jdouble,  Double,  T_DOUBLE
2501                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
2502                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN());
2503 
2504 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod
2505                          , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN());
2506 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV
2507                          , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN());
2508 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA
2509                          , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN());
2510 #endif /* USDT2 */
2511 
2512 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...))
2513   JNIWrapper("CallStaticVoidMethod");
2514 #ifndef USDT2
2515   DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID);
2516 #else /* USDT2 */
2517   HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY(
2518                                          env, cls, (uintptr_t) methodID);
2519 #endif /* USDT2 */
2520   DT_VOID_RETURN_MARK(CallStaticVoidMethod);
2521 
2522   va_list args;
2523   va_start(args, methodID);
2524   JavaValue jvalue(T_VOID);
2525   JNI_ArgumentPusherVaArg ap(methodID, args);
2526   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK);
2527   va_end(args);
2528 JNI_END
2529 
2530 
2531 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args))
2532   JNIWrapper("CallStaticVoidMethodV");
2533 #ifndef USDT2
2534   DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID);
2535 #else /* USDT2 */
2536   HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY(
2537                                           env, cls, (uintptr_t) methodID);
2538 #endif /* USDT2 */
2539   DT_VOID_RETURN_MARK(CallStaticVoidMethodV);
2540 
2541   JavaValue jvalue(T_VOID);
2542   JNI_ArgumentPusherVaArg ap(methodID, args);
2543   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK);
2544 JNI_END
2545 
2546 
2547 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args))
2548   JNIWrapper("CallStaticVoidMethodA");
2549 #ifndef USDT2
2550   DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID);
2551 #else /* USDT2 */
2552   HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY(
2553                                           env, cls, (uintptr_t) methodID);
2554 #endif /* USDT2 */
2555   DT_VOID_RETURN_MARK(CallStaticVoidMethodA);
2556 
2557   JavaValue jvalue(T_VOID);
2558   JNI_ArgumentPusherArray ap(methodID, args);
2559   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK);
2560 JNI_END
2561 
2562 
2563 //
2564 // Accessing Fields
2565 //
2566 
2567 
2568 #ifndef USDT2
2569 DT_RETURN_MARK_DECL(GetFieldID, jfieldID);
2570 #else /* USDT2 */
2571 DT_RETURN_MARK_DECL(GetFieldID, jfieldID
2572                     , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref));
2573 #endif /* USDT2 */
2574 
2575 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz,
2576           const char *name, const char *sig))
2577   JNIWrapper("GetFieldID");
2578 #ifndef USDT2
2579   DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig);
2580 #else /* USDT2 */
2581   HOTSPOT_JNI_GETFIELDID_ENTRY(
2582                                env, clazz, (char *) name, (char *) sig);
2583 #endif /* USDT2 */
2584   jfieldID ret = 0;
2585   DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret);
2586 
2587   // The class should have been loaded (we have an instance of the class
2588   // passed in) so the field and signature should already be in the symbol
2589   // table.  If they're not there, the field doesn't exist.
2590   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
2591   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
2592   if (fieldname == NULL || signame == NULL) {
2593     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2594   }
2595   KlassHandle k(THREAD,
2596                 java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
2597   // Make sure class is initialized before handing id's out to fields
2598   k()->initialize(CHECK_NULL);
2599 
2600   fieldDescriptor fd;
2601   if (!k()->oop_is_instance() ||
2602       !InstanceKlass::cast(k())->find_field(fieldname, signame, false, &fd)) {
2603     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2604   }
2605 
2606   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
2607   // It may also have hash bits for k, if VerifyJNIFields is turned on.
2608   ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset());
2609   return ret;
2610 JNI_END
2611 
2612 
2613 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
2614   JNIWrapper("GetObjectField");
2615 #ifndef USDT2
2616   DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID);
2617 #else /* USDT2 */
2618   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(
2619                                    env, obj, (uintptr_t) fieldID);
2620 #endif /* USDT2 */
2621   oop o = JNIHandles::resolve_non_null(obj);
2622   Klass* k = o->klass();
2623   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2624   // Keep JVMTI addition small and only check enabled flag here.
2625   // jni_GetField_probe() assumes that is okay to create handles.
2626   if (JvmtiExport::should_post_field_access()) {
2627     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2628   }
2629   jobject ret = JNIHandles::make_local(env, o->obj_field(offset));
2630 #if INCLUDE_ALL_GCS
2631   // If G1 is enabled and we are accessing the value of the referent
2632   // field in a reference object then we need to register a non-null
2633   // referent with the SATB barrier.
2634   if (UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier)) {
2635     bool needs_barrier = false;
2636 
2637     if (ret != NULL &&
2638         offset == java_lang_ref_Reference::referent_offset &&
2639         InstanceKlass::cast(k)->reference_type() != REF_NONE) {
2640       assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
2641       needs_barrier = true;
2642     }
2643 
2644     if (needs_barrier) {
2645       oop referent = JNIHandles::resolve(ret);
2646       G1SATBCardTableModRefBS::enqueue(referent);
2647     }
2648   }
2649 #endif // INCLUDE_ALL_GCS
2650 #ifndef USDT2
2651   DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret);
2652 #else /* USDT2 */
2653 HOTSPOT_JNI_GETOBJECTFIELD_RETURN(
2654                                   ret);
2655 #endif /* USDT2 */
2656   return ret;
2657 JNI_END
2658 
2659 
2660 #ifndef USDT2
2661 #define DEFINE_GETFIELD(Return,Fieldname,Result) \
2662 \
2663   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\
2664 \
2665 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2666   JNIWrapper("Get" XSTR(Result) "Field"); \
2667 \
2668   DTRACE_PROBE3(hotspot_jni, Get##Result##Field__entry, env, obj, fieldID);\
2669   Return ret = 0;\
2670   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
2671 \
2672   oop o = JNIHandles::resolve_non_null(obj); \
2673   Klass* k = o->klass(); \
2674   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
2675   /* Keep JVMTI addition small and only check enabled flag here.       */ \
2676   /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \
2677   /* and creates a ResetNoHandleMark.                                   */ \
2678   if (JvmtiExport::should_post_field_access()) { \
2679     o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \
2680   } \
2681   ret = o->Fieldname##_field(offset); \
2682   return ret; \
2683 JNI_END
2684 
2685 DEFINE_GETFIELD(jboolean, bool,   Boolean)
2686 DEFINE_GETFIELD(jbyte,    byte,   Byte)
2687 DEFINE_GETFIELD(jchar,    char,   Char)
2688 DEFINE_GETFIELD(jshort,   short,  Short)
2689 DEFINE_GETFIELD(jint,     int,    Int)
2690 DEFINE_GETFIELD(jlong,    long,   Long)
2691 DEFINE_GETFIELD(jfloat,   float,  Float)
2692 DEFINE_GETFIELD(jdouble,  double, Double)
2693 
2694 #else /* USDT2 */
2695 
2696 #define DEFINE_GETFIELD(Return,Fieldname,Result \
2697   , EntryProbe, ReturnProbe) \
2698 \
2699   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
2700   , ReturnProbe); \
2701 \
2702 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2703   JNIWrapper("Get" XSTR(Result) "Field"); \
2704 \
2705   EntryProbe; \
2706   Return ret = 0;\
2707   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
2708 \
2709   oop o = JNIHandles::resolve_non_null(obj); \
2710   Klass* k = o->klass(); \
2711   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
2712   /* Keep JVMTI addition small and only check enabled flag here.       */ \
2713   /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \
2714   /* and creates a ResetNoHandleMark.                                   */ \
2715   if (JvmtiExport::should_post_field_access()) { \
2716     o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \
2717   } \
2718   ret = o->Fieldname##_field(offset); \
2719   return ret; \
2720 JNI_END
2721 
2722 DEFINE_GETFIELD(jboolean, bool,   Boolean
2723                 , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2724                 HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref))
2725 DEFINE_GETFIELD(jbyte,    byte,   Byte
2726                 , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2727                 HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref))
2728 DEFINE_GETFIELD(jchar,    char,   Char
2729                 , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2730                 HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref))
2731 DEFINE_GETFIELD(jshort,   short,  Short
2732                 , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2733                 HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref))
2734 DEFINE_GETFIELD(jint,     int,    Int
2735                 , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2736                 HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref))
2737 DEFINE_GETFIELD(jlong,    long,   Long
2738                 , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2739                 HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref))
2740 // Float and double probes don't return value because dtrace doesn't currently support it
2741 DEFINE_GETFIELD(jfloat,   float,  Float
2742                 , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2743                 HOTSPOT_JNI_GETFLOATFIELD_RETURN())
2744 DEFINE_GETFIELD(jdouble,  double, Double
2745                 , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2746                 HOTSPOT_JNI_GETDOUBLEFIELD_RETURN())
2747 #endif /* USDT2 */
2748 
2749 address jni_GetBooleanField_addr() {
2750   return (address)jni_GetBooleanField;
2751 }
2752 address jni_GetByteField_addr() {
2753   return (address)jni_GetByteField;
2754 }
2755 address jni_GetCharField_addr() {
2756   return (address)jni_GetCharField;
2757 }
2758 address jni_GetShortField_addr() {
2759   return (address)jni_GetShortField;
2760 }
2761 address jni_GetIntField_addr() {
2762   return (address)jni_GetIntField;
2763 }
2764 address jni_GetLongField_addr() {
2765   return (address)jni_GetLongField;
2766 }
2767 address jni_GetFloatField_addr() {
2768   return (address)jni_GetFloatField;
2769 }
2770 address jni_GetDoubleField_addr() {
2771   return (address)jni_GetDoubleField;
2772 }
2773 
2774 JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value))
2775   JNIWrapper("SetObjectField");
2776 #ifndef USDT2
2777   DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value);
2778 #else /* USDT2 */
2779   HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(
2780                                    env, obj, (uintptr_t) fieldID, value);
2781 #endif /* USDT2 */
2782   oop o = JNIHandles::resolve_non_null(obj);
2783   Klass* k = o->klass();
2784   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2785   // Keep JVMTI addition small and only check enabled flag here.
2786   // jni_SetField_probe_nh() assumes that is not okay to create handles
2787   // and creates a ResetNoHandleMark.
2788   if (JvmtiExport::should_post_field_modification()) {
2789     jvalue field_value;
2790     field_value.l = value;
2791     o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value);
2792   }
2793   o->obj_field_put(offset, JNIHandles::resolve(value));
2794 #ifndef USDT2
2795   DTRACE_PROBE(hotspot_jni, SetObjectField__return);
2796 #else /* USDT2 */
2797   HOTSPOT_JNI_SETOBJECTFIELD_RETURN(
2798 );
2799 #endif /* USDT2 */
2800 JNI_END
2801 
2802 #ifndef USDT2
2803 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \
2804 \
2805 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
2806   JNIWrapper("Set" XSTR(Result) "Field"); \
2807 \
2808   FP_SELECT_##Result( \
2809     DTRACE_PROBE4(hotspot_jni, Set##Result##Field__entry, env, obj, fieldID, value), \
2810     DTRACE_PROBE3(hotspot_jni, Set##Result##Field__entry, env, obj, fieldID)); \
2811 \
2812   oop o = JNIHandles::resolve_non_null(obj); \
2813   Klass* k = o->klass(); \
2814   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
2815   /* Keep JVMTI addition small and only check enabled flag here.       */ \
2816   /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \
2817   /* and creates a ResetNoHandleMark.                                   */ \
2818   if (JvmtiExport::should_post_field_modification()) { \
2819     jvalue field_value; \
2820     field_value.unionType = value; \
2821     o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \
2822   } \
2823   o->Fieldname##_field_put(offset, value); \
2824   DTRACE_PROBE(hotspot_jni, Set##Result##Field__return);\
2825 JNI_END
2826 
2827 DEFINE_SETFIELD(jboolean, bool,   Boolean, 'Z', z)
2828 DEFINE_SETFIELD(jbyte,    byte,   Byte,    'B', b)
2829 DEFINE_SETFIELD(jchar,    char,   Char,    'C', c)
2830 DEFINE_SETFIELD(jshort,   short,  Short,   'S', s)
2831 DEFINE_SETFIELD(jint,     int,    Int,     'I', i)
2832 DEFINE_SETFIELD(jlong,    long,   Long,    'J', j)
2833 DEFINE_SETFIELD(jfloat,   float,  Float,   'F', f)
2834 DEFINE_SETFIELD(jdouble,  double, Double,  'D', d)
2835 
2836 #else /* USDT2 */
2837 
2838 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \
2839                         , EntryProbe, ReturnProbe) \
2840 \
2841 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
2842   JNIWrapper("Set" XSTR(Result) "Field"); \
2843 \
2844   EntryProbe; \
2845 \
2846   oop o = JNIHandles::resolve_non_null(obj); \
2847   Klass* k = o->klass(); \
2848   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
2849   /* Keep JVMTI addition small and only check enabled flag here.       */ \
2850   /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \
2851   /* and creates a ResetNoHandleMark.                                   */ \
2852   if (JvmtiExport::should_post_field_modification()) { \
2853     jvalue field_value; \
2854     field_value.unionType = value; \
2855     o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \
2856   } \
2857   if (SigType == 'Z') { value = ((jboolean)value) & 1; } \
2858   o->Fieldname##_field_put(offset, value); \
2859   ReturnProbe; \
2860 JNI_END
2861 
2862 DEFINE_SETFIELD(jboolean, bool,   Boolean, 'Z', z
2863                 , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2864                 HOTSPOT_JNI_SETBOOLEANFIELD_RETURN())
2865 DEFINE_SETFIELD(jbyte,    byte,   Byte,    'B', b
2866                 , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2867                 HOTSPOT_JNI_SETBYTEFIELD_RETURN())
2868 DEFINE_SETFIELD(jchar,    char,   Char,    'C', c
2869                 , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2870                 HOTSPOT_JNI_SETCHARFIELD_RETURN())
2871 DEFINE_SETFIELD(jshort,   short,  Short,   'S', s
2872                 , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2873                 HOTSPOT_JNI_SETSHORTFIELD_RETURN())
2874 DEFINE_SETFIELD(jint,     int,    Int,     'I', i
2875                 , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2876                 HOTSPOT_JNI_SETINTFIELD_RETURN())
2877 DEFINE_SETFIELD(jlong,    long,   Long,    'J', j
2878                 , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2879                 HOTSPOT_JNI_SETLONGFIELD_RETURN())
2880 // Float and double probes don't return value because dtrace doesn't currently support it
2881 DEFINE_SETFIELD(jfloat,   float,  Float,   'F', f
2882                 , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2883                 HOTSPOT_JNI_SETFLOATFIELD_RETURN())
2884 DEFINE_SETFIELD(jdouble,  double, Double,  'D', d
2885                 , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2886                 HOTSPOT_JNI_SETDOUBLEFIELD_RETURN())
2887 #endif /* USDT2 */
2888 
2889 #ifndef USDT2
2890 DT_RETURN_MARK_DECL(ToReflectedField, jobject);
2891 #else /* USDT2 */
2892 DT_RETURN_MARK_DECL(ToReflectedField, jobject
2893                     , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref));
2894 #endif /* USDT2 */
2895 
2896 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic))
2897   JNIWrapper("ToReflectedField");
2898 #ifndef USDT2
2899   DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry,
2900                 env, cls, fieldID, isStatic);
2901 #else /* USDT2 */
2902   HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY(
2903                 env, cls, (uintptr_t) fieldID, isStatic);
2904 #endif /* USDT2 */
2905   jobject ret = NULL;
2906   DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret);
2907 
2908   fieldDescriptor fd;
2909   bool found = false;
2910   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2911 
2912   assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID");
2913 
2914   if (isStatic) {
2915     // Static field. The fieldID a JNIid specifying the field holder and the offset within the Klass*.
2916     JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2917     assert(id->is_static_field_id(), "invalid static field id");
2918     found = id->find_local_field(&fd);
2919   } else {
2920     // Non-static field. The fieldID is really the offset of the field within the instanceOop.
2921     int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2922     found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, &fd);
2923   }
2924   assert(found, "bad fieldID passed into jni_ToReflectedField");
2925   oop reflected = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL);
2926   ret = JNIHandles::make_local(env, reflected);
2927   return ret;
2928 JNI_END
2929 
2930 
2931 //
2932 // Accessing Static Fields
2933 //
2934 #ifndef USDT2
2935 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID);
2936 #else /* USDT2 */
2937 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID
2938                     , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref));
2939 #endif /* USDT2 */
2940 
2941 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz,
2942           const char *name, const char *sig))
2943   JNIWrapper("GetStaticFieldID");
2944 #ifndef USDT2
2945   DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig);
2946 #else /* USDT2 */
2947   HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(
2948                                      env, clazz, (char *) name, (char *) sig);
2949 #endif /* USDT2 */
2950   jfieldID ret = NULL;
2951   DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret);
2952 
2953   // The class should have been loaded (we have an instance of the class
2954   // passed in) so the field and signature should already be in the symbol
2955   // table.  If they're not there, the field doesn't exist.
2956   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
2957   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
2958   if (fieldname == NULL || signame == NULL) {
2959     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2960   }
2961   KlassHandle k(THREAD,
2962                 java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
2963   // Make sure class is initialized before handing id's out to static fields
2964   k()->initialize(CHECK_NULL);
2965 
2966   fieldDescriptor fd;
2967   if (!k()->oop_is_instance() ||
2968       !InstanceKlass::cast(k())->find_field(fieldname, signame, true, &fd)) {
2969     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2970   }
2971 
2972   // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
2973   JNIid* id = fd.field_holder()->jni_id_for(fd.offset());
2974   debug_only(id->set_is_static_field_id();)
2975 
2976   debug_only(id->verify(fd.field_holder()));
2977 
2978   ret = jfieldIDWorkaround::to_static_jfieldID(id);
2979   return ret;
2980 JNI_END
2981 
2982 
2983 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID))
2984   JNIWrapper("GetStaticObjectField");
2985 #ifndef USDT2
2986   DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID);
2987 #else /* USDT2 */
2988   HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY(
2989                                          env, clazz, (uintptr_t) fieldID);
2990 #endif /* USDT2 */
2991 #if INCLUDE_JNI_CHECK
2992   DEBUG_ONLY(Klass* param_k = jniCheck::validate_class(thread, clazz);)
2993 #endif // INCLUDE_JNI_CHECK
2994   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2995   assert(id->is_static_field_id(), "invalid static field id");
2996   // Keep JVMTI addition small and only check enabled flag here.
2997   // jni_GetField_probe() assumes that is okay to create handles.
2998   if (JvmtiExport::should_post_field_access()) {
2999     JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true);
3000   }
3001   jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset()));
3002 #ifndef USDT2
3003   DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret);
3004 #else /* USDT2 */
3005   HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN(
3006                                           ret);
3007 #endif /* USDT2 */
3008   return ret;
3009 JNI_END
3010 
3011 #ifndef USDT2
3012 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \
3013 \
3014   DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\
3015 \
3016 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \
3017   JNIWrapper("GetStatic" XSTR(Result) "Field"); \
3018   DTRACE_PROBE3(hotspot_jni, GetStatic##Result##Field__entry, env, clazz, fieldID);\
3019   Return ret = 0;\
3020   DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \
3021                      (const Return&)ret);\
3022   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
3023   assert(id->is_static_field_id(), "invalid static field id"); \
3024   /* Keep JVMTI addition small and only check enabled flag here. */ \
3025   /* jni_GetField_probe() assumes that is okay to create handles. */ \
3026   if (JvmtiExport::should_post_field_access()) { \
3027     JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \
3028   } \
3029   ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \
3030   return ret;\
3031 JNI_END
3032 
3033 DEFINE_GETSTATICFIELD(jboolean, bool,   Boolean)
3034 DEFINE_GETSTATICFIELD(jbyte,    byte,   Byte)
3035 DEFINE_GETSTATICFIELD(jchar,    char,   Char)
3036 DEFINE_GETSTATICFIELD(jshort,   short,  Short)
3037 DEFINE_GETSTATICFIELD(jint,     int,    Int)
3038 DEFINE_GETSTATICFIELD(jlong,    long,   Long)
3039 DEFINE_GETSTATICFIELD(jfloat,   float,  Float)
3040 DEFINE_GETSTATICFIELD(jdouble,  double, Double)
3041 
3042 #else /* USDT2 */
3043 
3044 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \
3045                               , EntryProbe, ReturnProbe) \
3046 \
3047   DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \
3048                           , ReturnProbe);                                          \
3049 \
3050 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \
3051   JNIWrapper("GetStatic" XSTR(Result) "Field"); \
3052   EntryProbe; \
3053   Return ret = 0;\
3054   DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \
3055                      (const Return&)ret);\
3056   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
3057   assert(id->is_static_field_id(), "invalid static field id"); \
3058   /* Keep JVMTI addition small and only check enabled flag here. */ \
3059   /* jni_GetField_probe() assumes that is okay to create handles. */ \
3060   if (JvmtiExport::should_post_field_access()) { \
3061     JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \
3062   } \
3063   ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \
3064   return ret;\
3065 JNI_END
3066 
3067 DEFINE_GETSTATICFIELD(jboolean, bool,   Boolean
3068                       , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref))
3069 DEFINE_GETSTATICFIELD(jbyte,    byte,   Byte
3070                       , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref)   )
3071 DEFINE_GETSTATICFIELD(jchar,    char,   Char
3072                       , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref)   )
3073 DEFINE_GETSTATICFIELD(jshort,   short,  Short
3074                       , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref)  )
3075 DEFINE_GETSTATICFIELD(jint,     int,    Int
3076                       , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),     HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref)    )
3077 DEFINE_GETSTATICFIELD(jlong,    long,   Long
3078                       , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref)   )
3079 // Float and double probes don't return value because dtrace doesn't currently support it
3080 DEFINE_GETSTATICFIELD(jfloat,   float,  Float
3081                       , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN()          )
3082 DEFINE_GETSTATICFIELD(jdouble,  double, Double
3083                       , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),  HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN()         )
3084 #endif /* USDT2 */
3085 
3086 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value))
3087   JNIWrapper("SetStaticObjectField");
3088 #ifndef USDT2
3089   DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value);
3090 #else /* USDT2 */
3091  HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY(
3092                                         env, clazz, (uintptr_t) fieldID, value);
3093 #endif /* USDT2 */
3094   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
3095   assert(id->is_static_field_id(), "invalid static field id");
3096   // Keep JVMTI addition small and only check enabled flag here.
3097   // jni_SetField_probe() assumes that is okay to create handles.
3098   if (JvmtiExport::should_post_field_modification()) {
3099     jvalue field_value;
3100     field_value.l = value;
3101     JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value);
3102   }
3103   id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value));
3104 #ifndef USDT2
3105   DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return);
3106 #else /* USDT2 */
3107   HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN(
3108                                           );
3109 #endif /* USDT2 */
3110 JNI_END
3111 
3112 
3113 #ifndef USDT2
3114 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \
3115 \
3116 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \
3117   JNIWrapper("SetStatic" XSTR(Result) "Field"); \
3118   FP_SELECT_##Result( \
3119      DTRACE_PROBE4(hotspot_jni, SetStatic##Result##Field__entry, env, clazz, fieldID, value), \
3120      DTRACE_PROBE3(hotspot_jni, SetStatic##Result##Field__entry, env, clazz, fieldID)); \
3121 \
3122   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
3123   assert(id->is_static_field_id(), "invalid static field id"); \
3124   /* Keep JVMTI addition small and only check enabled flag here. */ \
3125   /* jni_SetField_probe() assumes that is okay to create handles. */ \
3126   if (JvmtiExport::should_post_field_modification()) { \
3127     jvalue field_value; \
3128     field_value.unionType = value; \
3129     JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \
3130   } \
3131   id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \
3132   DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\
3133 JNI_END
3134 
3135 DEFINE_SETSTATICFIELD(jboolean, bool,   Boolean, 'Z', z)
3136 DEFINE_SETSTATICFIELD(jbyte,    byte,   Byte,    'B', b)
3137 DEFINE_SETSTATICFIELD(jchar,    char,   Char,    'C', c)
3138 DEFINE_SETSTATICFIELD(jshort,   short,  Short,   'S', s)
3139 DEFINE_SETSTATICFIELD(jint,     int,    Int,     'I', i)
3140 DEFINE_SETSTATICFIELD(jlong,    long,   Long,    'J', j)
3141 DEFINE_SETSTATICFIELD(jfloat,   float,  Float,   'F', f)
3142 DEFINE_SETSTATICFIELD(jdouble,  double, Double,  'D', d)
3143 
3144 #else /* USDT2 */
3145 
3146 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \
3147                               , EntryProbe, ReturnProbe) \
3148 \
3149 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \
3150   JNIWrapper("SetStatic" XSTR(Result) "Field"); \
3151   EntryProbe; \
3152 \
3153   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
3154   assert(id->is_static_field_id(), "invalid static field id"); \
3155   /* Keep JVMTI addition small and only check enabled flag here. */ \
3156   /* jni_SetField_probe() assumes that is okay to create handles. */ \
3157   if (JvmtiExport::should_post_field_modification()) { \
3158     jvalue field_value; \
3159     field_value.unionType = value; \
3160     JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \
3161   } \
3162   if (SigType == 'Z') { value = ((jboolean)value) & 1; } \
3163   id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \
3164   ReturnProbe;\
3165 JNI_END
3166 
3167 DEFINE_SETSTATICFIELD(jboolean, bool,   Boolean, 'Z', z
3168                       , HOTSPOT_JNI_SETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value),
3169                       HOTSPOT_JNI_SETBOOLEANFIELD_RETURN())
3170 DEFINE_SETSTATICFIELD(jbyte,    byte,   Byte,    'B', b
3171                       , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
3172                       HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN())
3173 DEFINE_SETSTATICFIELD(jchar,    char,   Char,    'C', c
3174                       , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
3175                       HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN())
3176 DEFINE_SETSTATICFIELD(jshort,   short,  Short,   'S', s
3177                       , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
3178                       HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN())
3179 DEFINE_SETSTATICFIELD(jint,     int,    Int,     'I', i
3180                       , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
3181                       HOTSPOT_JNI_SETSTATICINTFIELD_RETURN())
3182 DEFINE_SETSTATICFIELD(jlong,    long,   Long,    'J', j
3183                       , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
3184                       HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN())
3185 // Float and double probes don't return value because dtrace doesn't currently support it
3186 DEFINE_SETSTATICFIELD(jfloat,   float,  Float,   'F', f
3187                       , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
3188                       HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN())
3189 DEFINE_SETSTATICFIELD(jdouble,  double, Double,  'D', d
3190                       , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
3191                       HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN())
3192 #endif /* USDT2 */
3193 
3194 //
3195 // String Operations
3196 //
3197 
3198 // Unicode Interface
3199 
3200 #ifndef USDT2
3201 DT_RETURN_MARK_DECL(NewString, jstring);
3202 #else /* USDT2 */
3203 DT_RETURN_MARK_DECL(NewString, jstring
3204                     , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref));
3205 #endif /* USDT2 */
3206 
3207 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len))
3208   JNIWrapper("NewString");
3209 #ifndef USDT2
3210   DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len);
3211 #else /* USDT2 */
3212  HOTSPOT_JNI_NEWSTRING_ENTRY(
3213                              env, (uint16_t *) unicodeChars, len);
3214 #endif /* USDT2 */
3215   jstring ret = NULL;
3216   DT_RETURN_MARK(NewString, jstring, (const jstring&)ret);
3217   oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL);
3218   ret = (jstring) JNIHandles::make_local(env, string);
3219   return ret;
3220 JNI_END
3221 
3222 
3223 JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string))
3224   JNIWrapper("GetStringLength");
3225 #ifndef USDT2
3226   DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string);
3227 #else /* USDT2 */
3228   HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY(
3229                                     env, string);
3230 #endif /* USDT2 */
3231   jsize ret = 0;
3232   oop s = JNIHandles::resolve_non_null(string);
3233   if (java_lang_String::value(s) != NULL) {
3234     ret = java_lang_String::length(s);
3235   }
3236 #ifndef USDT2
3237   DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret);
3238 #else /* USDT2 */
3239  HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(
3240                                     ret);
3241 #endif /* USDT2 */
3242   return ret;
3243 JNI_END
3244 
3245 
3246 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars(
3247   JNIEnv *env, jstring string, jboolean *isCopy))
3248   JNIWrapper("GetStringChars");
3249 #ifndef USDT2
3250   DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy);
3251 #else /* USDT2 */
3252  HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(
3253                                   env, string, (uintptr_t *) isCopy);
3254 #endif /* USDT2 */
3255   jchar* buf = NULL;
3256   oop s = JNIHandles::resolve_non_null(string);
3257   typeArrayOop s_value = java_lang_String::value(s);
3258   if (s_value != NULL) {
3259     int s_len = java_lang_String::length(s);
3260     int s_offset = java_lang_String::offset(s);
3261     buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
3262     /* JNI Specification states return NULL on OOM */
3263     if (buf != NULL) {
3264       if (s_len > 0) {
3265         memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len);
3266       }
3267       buf[s_len] = 0;
3268       //%note jni_5
3269       if (isCopy != NULL) {
3270         *isCopy = JNI_TRUE;
3271       }
3272     }
3273   }
3274 #ifndef USDT2
3275   DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf);
3276 #else /* USDT2 */
3277   HOTSPOT_JNI_GETSTRINGCHARS_RETURN(
3278                                     buf);
3279 #endif /* USDT2 */
3280   return buf;
3281 JNI_END
3282 
3283 
3284 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars))
3285   JNIWrapper("ReleaseStringChars");
3286 #ifndef USDT2
3287   DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars);
3288 #else /* USDT2 */
3289   HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY(
3290                                        env, str, (uint16_t *) chars);
3291 #endif /* USDT2 */
3292   //%note jni_6
3293   if (chars != NULL) {
3294     // Since String objects are supposed to be immutable, don't copy any
3295     // new data back.  A bad user will have to go after the char array.
3296     FreeHeap((void*) chars);
3297   }
3298 #ifndef USDT2
3299   DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return);
3300 #else /* USDT2 */
3301   HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN(
3302 );
3303 #endif /* USDT2 */
3304 JNI_END
3305 
3306 
3307 // UTF Interface
3308 
3309 #ifndef USDT2
3310 DT_RETURN_MARK_DECL(NewStringUTF, jstring);
3311 #else /* USDT2 */
3312 DT_RETURN_MARK_DECL(NewStringUTF, jstring
3313                     , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref));
3314 #endif /* USDT2 */
3315 
3316 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes))
3317   JNIWrapper("NewStringUTF");
3318 #ifndef USDT2
3319   DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes);
3320 #else /* USDT2 */
3321   HOTSPOT_JNI_NEWSTRINGUTF_ENTRY(
3322                                  env, (char *) bytes);
3323 #endif /* USDT2 */
3324   jstring ret;
3325   DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret);
3326 
3327   oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL);
3328   ret = (jstring) JNIHandles::make_local(env, result);
3329   return ret;
3330 JNI_END
3331 
3332 
3333 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string))
3334   JNIWrapper("GetStringUTFLength");
3335 #ifndef USDT2
3336   DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string);
3337 #else /* USDT2 */
3338  HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY(
3339                                       env, string);
3340 #endif /* USDT2 */
3341   jsize ret = 0;
3342   oop java_string = JNIHandles::resolve_non_null(string);
3343   if (java_lang_String::value(java_string) != NULL) {
3344     ret = java_lang_String::utf8_length(java_string);
3345   }
3346 #ifndef USDT2
3347   DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret);
3348 #else /* USDT2 */
3349   HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN(
3350                                         ret);
3351 #endif /* USDT2 */
3352   return ret;
3353 JNI_END
3354 
3355 
3356 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy))
3357   JNIWrapper("GetStringUTFChars");
3358 #ifndef USDT2
3359   DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy);
3360 #else /* USDT2 */
3361  HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY(
3362                                      env, string, (uintptr_t *) isCopy);
3363 #endif /* USDT2 */
3364   char* result = NULL;
3365   oop java_string = JNIHandles::resolve_non_null(string);
3366   if (java_lang_String::value(java_string) != NULL) {
3367     size_t length = java_lang_String::utf8_length(java_string);
3368     /* JNI Specification states return NULL on OOM */
3369     result = AllocateHeap(length + 1, mtInternal, 0, AllocFailStrategy::RETURN_NULL);
3370     if (result != NULL) {
3371       java_lang_String::as_utf8_string(java_string, result, (int) length + 1);
3372       if (isCopy != NULL) {
3373         *isCopy = JNI_TRUE;
3374       }
3375     }
3376   }
3377 #ifndef USDT2
3378   DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result);
3379 #else /* USDT2 */
3380  HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN(
3381                                       result);
3382 #endif /* USDT2 */
3383   return result;
3384 JNI_END
3385 
3386 
3387 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars))
3388   JNIWrapper("ReleaseStringUTFChars");
3389 #ifndef USDT2
3390   DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars);
3391 #else /* USDT2 */
3392  HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY(
3393                                          env, str, (char *) chars);
3394 #endif /* USDT2 */
3395   if (chars != NULL) {
3396     FreeHeap((char*) chars);
3397   }
3398 #ifndef USDT2
3399   DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return);
3400 #else /* USDT2 */
3401 HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN(
3402 );
3403 #endif /* USDT2 */
3404 JNI_END
3405 
3406 
3407 JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array))
3408   JNIWrapper("GetArrayLength");
3409 #ifndef USDT2
3410   DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array);
3411 #else /* USDT2 */
3412  HOTSPOT_JNI_GETARRAYLENGTH_ENTRY(
3413                                   env, array);
3414 #endif /* USDT2 */
3415   arrayOop a = arrayOop(JNIHandles::resolve_non_null(array));
3416   assert(a->is_array(), "must be array");
3417   jsize ret = a->length();
3418 #ifndef USDT2
3419   DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret);
3420 #else /* USDT2 */
3421  HOTSPOT_JNI_GETARRAYLENGTH_RETURN(
3422                                    ret);
3423 #endif /* USDT2 */
3424   return ret;
3425 JNI_END
3426 
3427 
3428 //
3429 // Object Array Operations
3430 //
3431 
3432 #ifndef USDT2
3433 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray);
3434 #else /* USDT2 */
3435 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray
3436                     , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref));
3437 #endif /* USDT2 */
3438 
3439 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement))
3440   JNIWrapper("NewObjectArray");
3441 #ifndef USDT2
3442   DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement);
3443 #else /* USDT2 */
3444  HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY(
3445                                   env, length, elementClass, initialElement);
3446 #endif /* USDT2 */
3447   jobjectArray ret = NULL;
3448   DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret);
3449   KlassHandle ek(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(elementClass)));
3450   Klass* ako = ek()->array_klass(CHECK_NULL);
3451   KlassHandle ak = KlassHandle(THREAD, ako);
3452   ObjArrayKlass::cast(ak())->initialize(CHECK_NULL);
3453   objArrayOop result = ObjArrayKlass::cast(ak())->allocate(length, CHECK_NULL);
3454   oop initial_value = JNIHandles::resolve(initialElement);
3455   if (initial_value != NULL) {  // array already initialized with NULL
3456     for (int index = 0; index < length; index++) {
3457       result->obj_at_put(index, initial_value);
3458     }
3459   }
3460   ret = (jobjectArray) JNIHandles::make_local(env, result);
3461   return ret;
3462 JNI_END
3463 
3464 #ifndef USDT2
3465 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject);
3466 #else /* USDT2 */
3467 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject
3468                     , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref));
3469 #endif /* USDT2 */
3470 
3471 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index))
3472   JNIWrapper("GetObjectArrayElement");
3473 #ifndef USDT2
3474   DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index);
3475 #else /* USDT2 */
3476  HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(
3477                                          env, array, index);
3478 #endif /* USDT2 */
3479   jobject ret = NULL;
3480   DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret);
3481   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
3482   if (a->is_within_bounds(index)) {
3483     ret = JNIHandles::make_local(env, a->obj_at(index));
3484     return ret;
3485   } else {
3486     char buf[jintAsStringSize];
3487     sprintf(buf, "%d", index);
3488     THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf);
3489   }
3490 JNI_END
3491 
3492 #ifndef USDT2
3493 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement);
3494 #else /* USDT2 */
3495 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement
3496                          , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN());
3497 #endif /* USDT2 */
3498 
3499 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value))
3500   JNIWrapper("SetObjectArrayElement");
3501 #ifndef USDT2
3502   DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value);
3503 #else /* USDT2 */
3504  HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(
3505                                          env, array, index, value);
3506 #endif /* USDT2 */
3507   DT_VOID_RETURN_MARK(SetObjectArrayElement);
3508 
3509   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
3510   oop v = JNIHandles::resolve(value);
3511   if (a->is_within_bounds(index)) {
3512     if (v == NULL || v->is_a(ObjArrayKlass::cast(a->klass())->element_klass())) {
3513       a->obj_at_put(index, v);
3514     } else {
3515       THROW(vmSymbols::java_lang_ArrayStoreException());
3516     }
3517   } else {
3518     char buf[jintAsStringSize];
3519     sprintf(buf, "%d", index);
3520     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf);
3521   }
3522 JNI_END
3523 
3524 
3525 #ifndef USDT2
3526 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \
3527 \
3528   DT_RETURN_MARK_DECL(New##Result##Array, Return); \
3529 \
3530 JNI_ENTRY(Return, \
3531           jni_New##Result##Array(JNIEnv *env, jsize len)) \
3532   JNIWrapper("New" XSTR(Result) "Array"); \
3533   DTRACE_PROBE2(hotspot_jni, New##Result##Array__entry, env, len);\
3534   Return ret = NULL;\
3535   DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
3536 \
3537   oop obj= oopFactory::Allocator(len, CHECK_0); \
3538   ret = (Return) JNIHandles::make_local(env, obj); \
3539   return ret;\
3540 JNI_END
3541 
3542 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray,   Boolean)
3543 DEFINE_NEWSCALARARRAY(jbyteArray,    new_byteArray,   Byte)
3544 DEFINE_NEWSCALARARRAY(jshortArray,   new_shortArray,  Short)
3545 DEFINE_NEWSCALARARRAY(jcharArray,    new_charArray,   Char)
3546 DEFINE_NEWSCALARARRAY(jintArray,     new_intArray,    Int)
3547 DEFINE_NEWSCALARARRAY(jlongArray,    new_longArray,   Long)
3548 DEFINE_NEWSCALARARRAY(jfloatArray,   new_singleArray, Float)
3549 DEFINE_NEWSCALARARRAY(jdoubleArray,  new_doubleArray, Double)
3550 
3551 #else /* USDT2 */
3552 
3553 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \
3554                               ,EntryProbe,ReturnProbe)  \
3555 \
3556   DT_RETURN_MARK_DECL(New##Result##Array, Return \
3557                       , ReturnProbe); \
3558 \
3559 JNI_ENTRY(Return, \
3560           jni_New##Result##Array(JNIEnv *env, jsize len)) \
3561   JNIWrapper("New" XSTR(Result) "Array"); \
3562   EntryProbe; \
3563   Return ret = NULL;\
3564   DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
3565 \
3566   oop obj= oopFactory::Allocator(len, CHECK_0); \
3567   ret = (Return) JNIHandles::make_local(env, obj); \
3568   return ret;\
3569 JNI_END
3570 
3571 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray,   Boolean,
3572                       HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len),
3573                       HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref))
3574 DEFINE_NEWSCALARARRAY(jbyteArray,    new_byteArray,   Byte,
3575                       HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len),
3576                       HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref))
3577 DEFINE_NEWSCALARARRAY(jshortArray,   new_shortArray,  Short,
3578                       HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len),
3579                       HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref))
3580 DEFINE_NEWSCALARARRAY(jcharArray,    new_charArray,   Char,
3581                       HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len),
3582                       HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref))
3583 DEFINE_NEWSCALARARRAY(jintArray,     new_intArray,    Int,
3584                       HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len),
3585                       HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref))
3586 DEFINE_NEWSCALARARRAY(jlongArray,    new_longArray,   Long,
3587                       HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len),
3588                       HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref))
3589 DEFINE_NEWSCALARARRAY(jfloatArray,   new_singleArray, Float,
3590                       HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len),
3591                       HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref))
3592 DEFINE_NEWSCALARARRAY(jdoubleArray,  new_doubleArray, Double,
3593                       HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len),
3594                       HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref))
3595 #endif /* USDT2 */
3596 
3597 // Return an address which will fault if the caller writes to it.
3598 
3599 static char* get_bad_address() {
3600   static char* bad_address = NULL;
3601   if (bad_address == NULL) {
3602     size_t size = os::vm_allocation_granularity();
3603     bad_address = os::reserve_memory(size);
3604     if (bad_address != NULL) {
3605       os::protect_memory(bad_address, size, os::MEM_PROT_READ,
3606                          /*is_committed*/false);
3607       MemTracker::record_virtual_memory_type((void*)bad_address, mtInternal);
3608     }
3609   }
3610   return bad_address;
3611 }
3612 
3613 
3614 #ifndef USDT2
3615 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \
3616 \
3617 JNI_QUICK_ENTRY(ElementType*, \
3618           jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
3619   JNIWrapper("Get" XSTR(Result) "ArrayElements"); \
3620   DTRACE_PROBE3(hotspot_jni, Get##Result##ArrayElements__entry, env, array, isCopy);\
3621   /* allocate an chunk of memory in c land */ \
3622   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3623   ElementType* result; \
3624   int len = a->length(); \
3625   if (len == 0) { \
3626     /* Empty array: legal but useless, can't return NULL. \
3627      * Return a pointer to something useless. \
3628      * Avoid asserts in typeArrayOop. */ \
3629     result = (ElementType*)get_bad_address(); \
3630   } else { \
3631     /* JNI Specification states return NULL on OOM */                    \
3632     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
3633     if (result != NULL) {                                                \
3634       /* copy the array to the c chunk */                                \
3635       memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len);      \
3636       if (isCopy) {                                                      \
3637         *isCopy = JNI_TRUE;                                              \
3638       }                                                                  \
3639     }                                                                    \
3640   } \
3641   DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\
3642   return result; \
3643 JNI_END
3644 
3645 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool)
3646 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte)
3647 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short)
3648 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char)
3649 DEFINE_GETSCALARARRAYELEMENTS(T_INT,     jint,     Int,     int)
3650 DEFINE_GETSCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long)
3651 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float)
3652 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double)
3653 
3654 #else /* USDT2 */
3655 
3656 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \
3657                                       , EntryProbe, ReturnProbe) \
3658 \
3659 JNI_QUICK_ENTRY(ElementType*, \
3660           jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
3661   JNIWrapper("Get" XSTR(Result) "ArrayElements"); \
3662   EntryProbe; \
3663   /* allocate an chunk of memory in c land */ \
3664   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3665   ElementType* result; \
3666   int len = a->length(); \
3667   if (len == 0) { \
3668     /* Empty array: legal but useless, can't return NULL. \
3669      * Return a pointer to something useless. \
3670      * Avoid asserts in typeArrayOop. */ \
3671     result = (ElementType*)get_bad_address(); \
3672   } else { \
3673     /* JNI Specification states return NULL on OOM */                    \
3674     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
3675     if (result != NULL) {                                                \
3676       /* copy the array to the c chunk */                                \
3677       memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len);      \
3678       if (isCopy) {                                                      \
3679         *isCopy = JNI_TRUE;                                              \
3680       }                                                                  \
3681     }                                                                    \
3682   } \
3683   ReturnProbe; \
3684   return result; \
3685 JNI_END
3686 
3687 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
3688                               , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
3689                               HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result))
3690 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
3691                               , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
3692                               HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result))
3693 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
3694                               , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
3695                               HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result))
3696 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
3697                               , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
3698                               HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result))
3699 DEFINE_GETSCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
3700                               , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
3701                               HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result))
3702 DEFINE_GETSCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
3703                               , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
3704                               HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result)))
3705 // Float and double probes don't return value because dtrace doesn't currently support it
3706 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
3707                               , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
3708                               HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result))
3709 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
3710                               , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
3711                               HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result))
3712 #endif /* USDT2 */
3713 
3714 #ifndef USDT2
3715 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \
3716 \
3717 JNI_QUICK_ENTRY(void, \
3718           jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
3719                                              ElementType *buf, jint mode)) \
3720   JNIWrapper("Release" XSTR(Result) "ArrayElements"); \
3721   DTRACE_PROBE4(hotspot_jni, Release##Result##ArrayElements__entry, env, array, buf, mode);\
3722   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3723   int len = a->length(); \
3724   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
3725     if ((mode == 0) || (mode == JNI_COMMIT)) { \
3726       memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \
3727     } \
3728     if ((mode == 0) || (mode == JNI_ABORT)) { \
3729       FreeHeap(buf); \
3730     } \
3731   } \
3732   DTRACE_PROBE(hotspot_jni, Release##Result##ArrayElements__return);\
3733 JNI_END
3734 
3735 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool)
3736 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte)
3737 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short)
3738 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char)
3739 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT,     jint,     Int,     int)
3740 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long)
3741 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float)
3742 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double)
3743 
3744 #else /* USDT2 */
3745 
3746 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \
3747                                           , EntryProbe, ReturnProbe);\
3748 \
3749 JNI_QUICK_ENTRY(void, \
3750           jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
3751                                              ElementType *buf, jint mode)) \
3752   JNIWrapper("Release" XSTR(Result) "ArrayElements"); \
3753   EntryProbe; \
3754   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3755   int len = a->length(); \
3756   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
3757     if ((mode == 0) || (mode == JNI_COMMIT)) { \
3758       memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \
3759     } \
3760     if ((mode == 0) || (mode == JNI_ABORT)) { \
3761       FreeHeap(buf); \
3762     } \
3763   } \
3764   ReturnProbe; \
3765 JNI_END
3766 
3767 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
3768                                   , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
3769                                   HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN())
3770 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
3771                                   , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode),
3772                                   HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN())
3773 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
3774                                   ,  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
3775                                   HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN())
3776 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
3777                                   ,  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
3778                                   HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN())
3779 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
3780                                   , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode),
3781                                   HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN())
3782 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
3783                                   , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
3784                                   HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN())
3785 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
3786                                   , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode),
3787                                   HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN())
3788 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
3789                                   , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode),
3790                                   HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN())
3791 #endif /* USDT2 */
3792 
3793 #ifndef USDT2
3794 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \
3795   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\
3796 \
3797 JNI_ENTRY(void, \
3798 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
3799              jsize len, ElementType *buf)) \
3800   JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \
3801   DTRACE_PROBE5(hotspot_jni, Get##Result##ArrayRegion__entry, env, array, start, len, buf);\
3802   DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
3803   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3804   if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \
3805     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
3806   } else { \
3807     if (len > 0) { \
3808       int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \
3809       memcpy((u_char*) buf, \
3810              (u_char*) src->Tag##_at_addr(start), \
3811              len << sc);                          \
3812     } \
3813   } \
3814 JNI_END
3815 
3816 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool)
3817 DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte)
3818 DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short)
3819 DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char)
3820 DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int)
3821 DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long)
3822 DEFINE_GETSCALARARRAYREGION(T_FLOAT,   jfloat,  Float,   float)
3823 DEFINE_GETSCALARARRAYREGION(T_DOUBLE,  jdouble, Double,  double)
3824 
3825 #else /* USDT2 */
3826 
3827 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
3828                                     , EntryProbe, ReturnProbe); \
3829   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \
3830                            , ReturnProbe); \
3831 \
3832 JNI_ENTRY(void, \
3833 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
3834              jsize len, ElementType *buf)) \
3835   JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \
3836   EntryProbe; \
3837   DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
3838   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3839   if (start < 0 || len < 0 || (start > src->length() - len)) { \
3840     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
3841   } else { \
3842     if (len > 0) { \
3843       int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \
3844       memcpy((u_char*) buf, \
3845              (u_char*) src->Tag##_at_addr(start), \
3846              len << sc);                          \
3847     } \
3848   } \
3849 JNI_END
3850 
3851 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool
3852                             , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
3853                             HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN());
3854 DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte
3855                             ,  HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
3856                             HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN());
3857 DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short
3858                             , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
3859                             HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN());
3860 DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char
3861                             ,  HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf),
3862                             HOTSPOT_JNI_GETCHARARRAYREGION_RETURN());
3863 DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int
3864                             , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf),
3865                             HOTSPOT_JNI_GETINTARRAYREGION_RETURN());
3866 DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long
3867                             ,  HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
3868                             HOTSPOT_JNI_GETLONGARRAYREGION_RETURN());
3869 DEFINE_GETSCALARARRAYREGION(T_FLOAT,   jfloat,  Float,   float
3870                             , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
3871                             HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN());
3872 DEFINE_GETSCALARARRAYREGION(T_DOUBLE,  jdouble, Double,  double
3873                             , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
3874                             HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN());
3875 #endif /* USDT2 */
3876 
3877 #ifndef USDT2
3878 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \
3879   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\
3880 \
3881 JNI_ENTRY(void, \
3882 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
3883              jsize len, const ElementType *buf)) \
3884   JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \
3885   DTRACE_PROBE5(hotspot_jni, Set##Result##ArrayRegion__entry, env, array, start, len, buf);\
3886   DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
3887   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3888   if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \
3889     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
3890   } else { \
3891     if (len > 0) { \
3892       int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \
3893       memcpy((u_char*) dst->Tag##_at_addr(start), \
3894              (u_char*) buf, \
3895              len << sc);    \
3896     } \
3897   } \
3898 JNI_END
3899 
3900 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool)
3901 DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte)
3902 DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short)
3903 DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char)
3904 DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int)
3905 DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long)
3906 DEFINE_SETSCALARARRAYREGION(T_FLOAT,   jfloat,   Float,   float)
3907 DEFINE_SETSCALARARRAYREGION(T_DOUBLE,  jdouble,  Double,  double)
3908 
3909 #else /* USDT2 */
3910 
3911 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
3912                                     , EntryProbe, ReturnProbe); \
3913   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \
3914                            ,ReturnProbe);           \
3915 \
3916 JNI_ENTRY(void, \
3917 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
3918              jsize len, const ElementType *buf)) \
3919   JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \
3920   EntryProbe; \
3921   DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
3922   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
3923   if (start < 0 || len < 0 || (start > dst->length() - len)) { \
3924     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
3925   } else { \
3926     if (len > 0) { \
3927       int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \
3928       memcpy((u_char*) dst->Tag##_at_addr(start), \
3929              (u_char*) buf, \
3930              len << sc);    \
3931     } \
3932   } \
3933 JNI_END
3934 
3935 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool
3936                             , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf),
3937                             HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN())
3938 DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte
3939                             , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
3940                             HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN())
3941 DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short
3942                             , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
3943                             HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
3944 DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char
3945                             , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
3946                             HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
3947 DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int
3948                             , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
3949                             HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
3950 DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long
3951                             , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
3952                             HOTSPOT_JNI_SETLONGARRAYREGION_RETURN())
3953 DEFINE_SETSCALARARRAYREGION(T_FLOAT,   jfloat,   Float,   float
3954                             , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
3955                             HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN())
3956 DEFINE_SETSCALARARRAYREGION(T_DOUBLE,  jdouble,  Double,  double
3957                             , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
3958                             HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN())
3959 #endif /* USDT2 */
3960 
3961 
3962 //
3963 // Interception of natives
3964 //
3965 
3966 // The RegisterNatives call being attempted tried to register with a method that
3967 // is not native.  Ask JVM TI what prefixes have been specified.  Then check
3968 // to see if the native method is now wrapped with the prefixes.  See the
3969 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.
3970 static Method* find_prefixed_native(KlassHandle k,
3971                                       Symbol* name, Symbol* signature, TRAPS) {
3972 #if INCLUDE_JVMTI
3973   ResourceMark rm(THREAD);
3974   Method* method;
3975   int name_len = name->utf8_length();
3976   char* name_str = name->as_utf8();
3977   int prefix_count;
3978   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
3979   for (int i = 0; i < prefix_count; i++) {
3980     char* prefix = prefixes[i];
3981     int prefix_len = (int)strlen(prefix);
3982 
3983     // try adding this prefix to the method name and see if it matches another method name
3984     int trial_len = name_len + prefix_len;
3985     char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
3986     strcpy(trial_name_str, prefix);
3987     strcat(trial_name_str, name_str);
3988     TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len);
3989     if (trial_name == NULL) {
3990       continue; // no such symbol, so this prefix wasn't used, try the next prefix
3991     }
3992     method = k()->lookup_method(trial_name, signature);
3993     if (method == NULL) {
3994       continue; // signature doesn't match, try the next prefix
3995     }
3996     if (method->is_native()) {
3997       method->set_is_prefixed_native();
3998       return method; // wahoo, we found a prefixed version of the method, return it
3999     }
4000     // found as non-native, so prefix is good, add it, probably just need more prefixes
4001     name_len = trial_len;
4002     name_str = trial_name_str;
4003   }
4004 #endif // INCLUDE_JVMTI
4005   return NULL; // not found
4006 }
4007 
4008 static bool register_native(KlassHandle k, Symbol* name, Symbol* signature, address entry, TRAPS) {
4009   Method* method = k()->lookup_method(name, signature);
4010   if (method == NULL) {
4011     ResourceMark rm;
4012     stringStream st;
4013     st.print("Method %s name or signature does not match",
4014              Method::name_and_sig_as_C_string(k(), name, signature));
4015     THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
4016   }
4017   if (!method->is_native()) {
4018     // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
4019     method = find_prefixed_native(k, name, signature, THREAD);
4020     if (method == NULL) {
4021       ResourceMark rm;
4022       stringStream st;
4023       st.print("Method %s is not declared as native",
4024                Method::name_and_sig_as_C_string(k(), name, signature));
4025       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
4026     }
4027   }
4028 
4029   if (entry != NULL) {
4030     method->set_native_function(entry,
4031       Method::native_bind_event_is_interesting);
4032   } else {
4033     method->clear_native_function();
4034   }
4035   if (PrintJNIResolving) {
4036     ResourceMark rm(THREAD);
4037     tty->print_cr("[Registering JNI native method %s.%s]",
4038       method->method_holder()->external_name(),
4039       method->name()->as_C_string());
4040   }
4041   return true;
4042 }
4043 
4044 #ifndef USDT2
4045 DT_RETURN_MARK_DECL(RegisterNatives, jint);
4046 #else /* USDT2 */
4047 DT_RETURN_MARK_DECL(RegisterNatives, jint
4048                     , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref));
4049 #endif /* USDT2 */
4050 
4051 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
4052                                     const JNINativeMethod *methods,
4053                                     jint nMethods))
4054   JNIWrapper("RegisterNatives");
4055 #ifndef USDT2
4056   DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods);
4057 #else /* USDT2 */
4058   HOTSPOT_JNI_REGISTERNATIVES_ENTRY(
4059                                     env, clazz, (void *) methods, nMethods);
4060 #endif /* USDT2 */
4061   jint ret = 0;
4062   DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
4063 
4064   KlassHandle h_k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
4065 
4066   for (int index = 0; index < nMethods; index++) {
4067     const char* meth_name = methods[index].name;
4068     const char* meth_sig = methods[index].signature;
4069     int meth_name_len = (int)strlen(meth_name);
4070 
4071     // The class should have been loaded (we have an instance of the class
4072     // passed in) so the method and signature should already be in the symbol
4073     // table.  If they're not there, the method doesn't exist.
4074     TempNewSymbol  name = SymbolTable::probe(meth_name, meth_name_len);
4075     TempNewSymbol  signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig));
4076 
4077     if (name == NULL || signature == NULL) {
4078       ResourceMark rm;
4079       stringStream st;
4080       st.print("Method %s.%s%s not found", h_k()->external_name(), meth_name, meth_sig);
4081       // Must return negative value on failure
4082       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1);
4083     }
4084 
4085     bool res = register_native(h_k, name, signature,
4086                                (address) methods[index].fnPtr, THREAD);
4087     if (!res) {
4088       ret = -1;
4089       break;
4090     }
4091   }
4092   return ret;
4093 JNI_END
4094 
4095 
4096 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz))
4097   JNIWrapper("UnregisterNatives");
4098 #ifndef USDT2
4099   DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz);
4100 #else /* USDT2 */
4101  HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(
4102                                      env, clazz);
4103 #endif /* USDT2 */
4104   Klass* k   = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
4105   //%note jni_2
4106   if (k->oop_is_instance()) {
4107     for (int index = 0; index < InstanceKlass::cast(k)->methods()->length(); index++) {
4108       Method* m = InstanceKlass::cast(k)->methods()->at(index);
4109       if (m->is_native()) {
4110         m->clear_native_function();
4111         m->set_signature_handler(NULL);
4112       }
4113     }
4114   }
4115 #ifndef USDT2
4116   DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0);
4117 #else /* USDT2 */
4118  HOTSPOT_JNI_UNREGISTERNATIVES_RETURN(
4119                                       0);
4120 #endif /* USDT2 */
4121   return 0;
4122 JNI_END
4123 
4124 //
4125 // Monitor functions
4126 //
4127 
4128 #ifndef USDT2
4129 DT_RETURN_MARK_DECL(MonitorEnter, jint);
4130 #else /* USDT2 */
4131 DT_RETURN_MARK_DECL(MonitorEnter, jint
4132                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
4133 #endif /* USDT2 */
4134 
4135 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
4136 #ifndef USDT2
4137   DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj);
4138 #else /* USDT2 */
4139  HOTSPOT_JNI_MONITORENTER_ENTRY(
4140                                 env, jobj);
4141 #endif /* USDT2 */
4142   jint ret = JNI_ERR;
4143   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
4144 
4145   // If the object is null, we can't do anything with it
4146   if (jobj == NULL) {
4147     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
4148   }
4149 
4150   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
4151   ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR));
4152   ret = JNI_OK;
4153   return ret;
4154 JNI_END
4155 
4156 #ifndef USDT2
4157 DT_RETURN_MARK_DECL(MonitorExit, jint);
4158 #else /* USDT2 */
4159 DT_RETURN_MARK_DECL(MonitorExit, jint
4160                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
4161 #endif /* USDT2 */
4162 
4163 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
4164 #ifndef USDT2
4165   DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj);
4166 #else /* USDT2 */
4167  HOTSPOT_JNI_MONITOREXIT_ENTRY(
4168                                env, jobj);
4169 #endif /* USDT2 */
4170   jint ret = JNI_ERR;
4171   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
4172 
4173   // Don't do anything with a null object
4174   if (jobj == NULL) {
4175     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
4176   }
4177 
4178   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
4179   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
4180 
4181   ret = JNI_OK;
4182   return ret;
4183 JNI_END
4184 
4185 //
4186 // Extensions
4187 //
4188 
4189 #ifndef USDT2
4190 DT_VOID_RETURN_MARK_DECL(GetStringRegion);
4191 #else /* USDT2 */
4192 DT_VOID_RETURN_MARK_DECL(GetStringRegion
4193                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
4194 #endif /* USDT2 */
4195 
4196 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
4197   JNIWrapper("GetStringRegion");
4198 #ifndef USDT2
4199   DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf);
4200 #else /* USDT2 */
4201  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(
4202                                    env, string, start, len, buf);
4203 #endif /* USDT2 */
4204   DT_VOID_RETURN_MARK(GetStringRegion);
4205   oop s = JNIHandles::resolve_non_null(string);
4206   int s_len = java_lang_String::length(s);
4207   if (start < 0 || len < 0 || start > s_len - len) {
4208     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
4209   } else {
4210     if (len > 0) {
4211       int s_offset = java_lang_String::offset(s);
4212       typeArrayOop s_value = java_lang_String::value(s);
4213       memcpy(buf, s_value->char_at_addr(s_offset+start), sizeof(jchar)*len);
4214     }
4215   }
4216 JNI_END
4217 
4218 #ifndef USDT2
4219 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion);
4220 #else /* USDT2 */
4221 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion
4222                          , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN());
4223 #endif /* USDT2 */
4224 
4225 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf))
4226   JNIWrapper("GetStringUTFRegion");
4227 #ifndef USDT2
4228   DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf);
4229 #else /* USDT2 */
4230  HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(
4231                                       env, string, start, len, buf);
4232 #endif /* USDT2 */
4233   DT_VOID_RETURN_MARK(GetStringUTFRegion);
4234   oop s = JNIHandles::resolve_non_null(string);
4235   int s_len = java_lang_String::length(s);
4236   if (start < 0 || len < 0 || start > s_len - len) {
4237     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
4238   } else {
4239     //%note jni_7
4240     if (len > 0) {
4241       ResourceMark rm(THREAD);
4242       char *utf_region = java_lang_String::as_utf8_string(s, start, len);
4243       int utf_len = (int)strlen(utf_region);
4244       memcpy(buf, utf_region, utf_len);
4245       buf[utf_len] = 0;
4246     } else {
4247       // JDK null-terminates the buffer even in len is zero
4248       if (buf != NULL) {
4249         buf[0] = 0;
4250       }
4251     }
4252   }
4253 JNI_END
4254 
4255 static oop lock_gc_or_pin_object(JavaThread* thread, jobject obj) {
4256   if (Universe::heap()->supports_object_pinning()) {
4257     const oop o = JNIHandles::resolve_non_null(obj);
4258     return Universe::heap()->pin_object(thread, o);
4259   } else {
4260     GC_locker::lock_critical(thread);
4261     return JNIHandles::resolve_non_null(obj);
4262   }
4263 }
4264 
4265 static void unlock_gc_or_unpin_object(JavaThread* thread, jobject obj) {
4266   if (Universe::heap()->supports_object_pinning()) {
4267     const oop o = JNIHandles::resolve_non_null(obj);
4268     return Universe::heap()->unpin_object(thread, o);
4269   } else {
4270     GC_locker::unlock_critical(thread);
4271   }
4272 }
4273 
4274 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
4275   JNIWrapper("GetPrimitiveArrayCritical");
4276 #ifndef USDT2
4277   DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy);
4278 #else /* USDT2 */
4279  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(
4280                                              env, array, (uintptr_t *) isCopy);
4281 #endif /* USDT2 */
4282   if (isCopy != NULL) {
4283     *isCopy = JNI_FALSE;
4284   }
4285   oop a = lock_gc_or_pin_object(thread, array);
4286   assert(a->is_array(), "just checking");
4287   BasicType type;
4288   if (a->is_objArray()) {
4289     type = T_OBJECT;
4290   } else {
4291     type = TypeArrayKlass::cast(a->klass())->element_type();
4292   }
4293   void* ret = arrayOop(a)->base(type);
4294 #ifndef USDT2
4295   DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret);
4296 #else /* USDT2 */
4297  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(
4298                                               ret);
4299 #endif /* USDT2 */
4300   return ret;
4301 JNI_END
4302 
4303 
4304 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
4305   JNIWrapper("ReleasePrimitiveArrayCritical");
4306 #ifndef USDT2
4307   DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode);
4308 #else /* USDT2 */
4309   HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(
4310                                                   env, array, carray, mode);
4311 #endif /* USDT2 */
4312   // The array, carray and mode arguments are ignored
4313   unlock_gc_or_unpin_object(thread, array);
4314 #ifndef USDT2
4315   DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return);
4316 #else /* USDT2 */
4317 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN(
4318 );
4319 #endif /* USDT2 */
4320 JNI_END
4321 
4322 
4323 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
4324   JNIWrapper("GetStringCritical");
4325 #ifndef USDT2
4326   DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy);
4327 #else /* USDT2 */
4328   HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(
4329                                       env, string, (uintptr_t *) isCopy);
4330 #endif /* USDT2 */
4331   if (isCopy != NULL) {
4332     *isCopy = JNI_FALSE;
4333   }
4334   oop s = lock_gc_or_pin_object(thread, string);
4335   int s_len = java_lang_String::length(s);
4336   typeArrayOop s_value = java_lang_String::value(s);
4337   int s_offset = java_lang_String::offset(s);
4338   const jchar* ret;
4339   if (s_len > 0) {
4340     ret = s_value->char_at_addr(s_offset);
4341   } else {
4342     ret = (jchar*) s_value->base(T_CHAR);
4343   }
4344 #ifndef USDT2
4345   DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret);
4346 #else /* USDT2 */
4347  HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN(
4348                                       (uint16_t *) ret);
4349 #endif /* USDT2 */
4350   return ret;
4351 JNI_END
4352 
4353 
4354 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
4355   JNIWrapper("ReleaseStringCritical");
4356 #ifndef USDT2
4357   DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars);
4358 #else /* USDT2 */
4359   HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(
4360                                           env, str, (uint16_t *) chars);
4361 #endif /* USDT2 */
4362   // The str and chars arguments are ignored
4363   unlock_gc_or_unpin_object(thread, str);
4364 #ifndef USDT2
4365   DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return);
4366 #else /* USDT2 */
4367 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN(
4368 );
4369 #endif /* USDT2 */
4370 JNI_END
4371 
4372 
4373 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
4374   JNIWrapper("jni_NewWeakGlobalRef");
4375 #ifndef USDT2
4376   DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref);
4377 #else /* USDT2 */
4378  HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(
4379                                     env, ref);
4380 #endif /* USDT2 */
4381   Handle ref_handle(thread, JNIHandles::resolve(ref));
4382   jweak ret = JNIHandles::make_weak_global(ref_handle);
4383 #ifndef USDT2
4384   DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret);
4385 #else /* USDT2 */
4386  HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(
4387                                      ret);
4388 #endif /* USDT2 */
4389   return ret;
4390 JNI_END
4391 
4392 // Must be JNI_ENTRY (with HandleMark)
4393 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref))
4394   JNIWrapper("jni_DeleteWeakGlobalRef");
4395 #ifndef USDT2
4396   DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref);
4397 #else /* USDT2 */
4398   HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY(
4399                                         env, ref);
4400 #endif /* USDT2 */
4401   JNIHandles::destroy_weak_global(ref);
4402 #ifndef USDT2
4403   DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return);
4404 #else /* USDT2 */
4405   HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN(
4406                                          );
4407 #endif /* USDT2 */
4408 JNI_END
4409 
4410 
4411 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env))
4412   JNIWrapper("jni_ExceptionCheck");
4413 #ifndef USDT2
4414   DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env);
4415 #else /* USDT2 */
4416  HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY(
4417                                   env);
4418 #endif /* USDT2 */
4419   jni_check_async_exceptions(thread);
4420   jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE;
4421 #ifndef USDT2
4422   DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret);
4423 #else /* USDT2 */
4424  HOTSPOT_JNI_EXCEPTIONCHECK_RETURN(
4425                                    ret);
4426 #endif /* USDT2 */
4427   return ret;
4428 JNI_END
4429 
4430 
4431 // Initialization state for three routines below relating to
4432 // java.nio.DirectBuffers
4433 static          jint directBufferSupportInitializeStarted = 0;
4434 static volatile jint directBufferSupportInitializeEnded   = 0;
4435 static volatile jint directBufferSupportInitializeFailed  = 0;
4436 static jclass    bufferClass                 = NULL;
4437 static jclass    directBufferClass           = NULL;
4438 static jclass    directByteBufferClass       = NULL;
4439 static jmethodID directByteBufferConstructor = NULL;
4440 static jfieldID  directBufferAddressField    = NULL;
4441 static jfieldID  bufferCapacityField         = NULL;
4442 
4443 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) {
4444   Handle loader;            // null (bootstrap) loader
4445   Handle protection_domain; // null protection domain
4446 
4447   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
4448   jclass result =  find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL);
4449 
4450   if (TraceClassResolution && result != NULL) {
4451     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
4452   }
4453   return result;
4454 }
4455 
4456 // These lookups are done with the NULL (bootstrap) ClassLoader to
4457 // circumvent any security checks that would be done by jni_FindClass.
4458 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env))
4459 {
4460   if ((bufferClass           = lookupOne(env, "java/nio/Buffer", thread))           == NULL) { return false; }
4461   if ((directBufferClass     = lookupOne(env, "sun/nio/ch/DirectBuffer", thread))   == NULL) { return false; }
4462   if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; }
4463   return true;
4464 }
4465 JNI_END
4466 
4467 
4468 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
4469   if (directBufferSupportInitializeFailed) {
4470     return false;
4471   }
4472 
4473   if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) {
4474     if (!lookupDirectBufferClasses(env)) {
4475       directBufferSupportInitializeFailed = 1;
4476       return false;
4477     }
4478 
4479     // Make global references for these
4480     bufferClass           = (jclass) env->NewGlobalRef(bufferClass);
4481     directBufferClass     = (jclass) env->NewGlobalRef(directBufferClass);
4482     directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
4483 
4484     // Get needed field and method IDs
4485     directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
4486     if (env->ExceptionCheck()) {
4487       env->ExceptionClear();
4488       directBufferSupportInitializeFailed = 1;
4489       return false;
4490     }
4491     directBufferAddressField    = env->GetFieldID(bufferClass, "address", "J");
4492     if (env->ExceptionCheck()) {
4493       env->ExceptionClear();
4494       directBufferSupportInitializeFailed = 1;
4495       return false;
4496     }
4497     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
4498     if (env->ExceptionCheck()) {
4499       env->ExceptionClear();
4500       directBufferSupportInitializeFailed = 1;
4501       return false;
4502     }
4503 
4504     if ((directByteBufferConstructor == NULL) ||
4505         (directBufferAddressField    == NULL) ||
4506         (bufferCapacityField         == NULL)) {
4507       directBufferSupportInitializeFailed = 1;
4508       return false;
4509     }
4510 
4511     directBufferSupportInitializeEnded = 1;
4512   } else {
4513     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
4514       // Set state as yield_all can call os:sleep. On Solaris, yield_all calls
4515       // os::sleep which requires the VM state transition. On other platforms, it
4516       // is not necessary. The following call to change the VM state is purposely
4517       // put inside the loop to avoid potential deadlock when multiple threads
4518       // try to call this method. See 6791815 for more details.
4519       ThreadInVMfromNative tivn(thread);
4520       os::yield_all();
4521     }
4522   }
4523 
4524   return !directBufferSupportInitializeFailed;
4525 }
4526 
4527 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
4528 {
4529   // thread_from_jni_environment() will block if VM is gone.
4530   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
4531 
4532   JNIWrapper("jni_NewDirectByteBuffer");
4533 #ifndef USDT2
4534   DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity);
4535 #else /* USDT2 */
4536  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(
4537                                        env, address, capacity);
4538 #endif /* USDT2 */
4539 
4540   if (!directBufferSupportInitializeEnded) {
4541     if (!initializeDirectBufferSupport(env, thread)) {
4542 #ifndef USDT2
4543       DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL);
4544 #else /* USDT2 */
4545       HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(
4546                                              NULL);
4547 #endif /* USDT2 */
4548       return NULL;
4549     }
4550   }
4551 
4552   // Being paranoid about accidental sign extension on address
4553   jlong addr = (jlong) ((uintptr_t) address);
4554   // NOTE that package-private DirectByteBuffer constructor currently
4555   // takes int capacity
4556   jint  cap  = (jint)  capacity;
4557   jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap);
4558 #ifndef USDT2
4559   DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret);
4560 #else /* USDT2 */
4561   HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(
4562                                          ret);
4563 #endif /* USDT2 */
4564   return ret;
4565 }
4566 
4567 #ifndef USDT2
4568 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*);
4569 #else /* USDT2 */
4570 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*
4571                     , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref));
4572 #endif /* USDT2 */
4573 
4574 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
4575 {
4576   // thread_from_jni_environment() will block if VM is gone.
4577   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
4578 
4579   JNIWrapper("jni_GetDirectBufferAddress");
4580 #ifndef USDT2
4581   DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf);
4582 #else /* USDT2 */
4583   HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY(
4584                                            env, buf);
4585 #endif /* USDT2 */
4586   void* ret = NULL;
4587   DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret);
4588 
4589   if (!directBufferSupportInitializeEnded) {
4590     if (!initializeDirectBufferSupport(env, thread)) {
4591       return 0;
4592     }
4593   }
4594 
4595   if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) {
4596     return 0;
4597   }
4598 
4599   ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField);
4600   return ret;
4601 }
4602 
4603 #ifndef USDT2
4604 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong);
4605 #else /* USDT2 */
4606 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong
4607                     , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref));
4608 #endif /* USDT2 */
4609 
4610 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf)
4611 {
4612   // thread_from_jni_environment() will block if VM is gone.
4613   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
4614 
4615   JNIWrapper("jni_GetDirectBufferCapacity");
4616 #ifndef USDT2
4617   DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf);
4618 #else /* USDT2 */
4619   HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY(
4620                                             env, buf);
4621 #endif /* USDT2 */
4622   jlong ret = -1;
4623   DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret);
4624 
4625   if (!directBufferSupportInitializeEnded) {
4626     if (!initializeDirectBufferSupport(env, thread)) {
4627       ret = 0;
4628       return ret;
4629     }
4630   }
4631 
4632   if (buf == NULL) {
4633     return -1;
4634   }
4635 
4636   if (!env->IsInstanceOf(buf, directBufferClass)) {
4637     return -1;
4638   }
4639 
4640   // NOTE that capacity is currently an int in the implementation
4641   ret = env->GetIntField(buf, bufferCapacityField);
4642   return ret;
4643 }
4644 
4645 
4646 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
4647   JNIWrapper("GetVersion");
4648 #ifndef USDT2
4649   DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env);
4650 #else /* USDT2 */
4651   HOTSPOT_JNI_GETVERSION_ENTRY(
4652                                env);
4653 #endif /* USDT2 */
4654 #ifndef USDT2
4655   DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion);
4656 #else /* USDT2 */
4657   HOTSPOT_JNI_GETVERSION_RETURN(
4658                                 CurrentVersion);
4659 #endif /* USDT2 */
4660   return CurrentVersion;
4661 JNI_END
4662 
4663 extern struct JavaVM_ main_vm;
4664 
4665 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
4666   JNIWrapper("jni_GetJavaVM");
4667 #ifndef USDT2
4668   DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm);
4669 #else /* USDT2 */
4670   HOTSPOT_JNI_GETJAVAVM_ENTRY(
4671                               env, (void **) vm);
4672 #endif /* USDT2 */
4673   *vm  = (JavaVM *)(&main_vm);
4674 #ifndef USDT2
4675   DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK);
4676 #else /* USDT2 */
4677   HOTSPOT_JNI_GETJAVAVM_RETURN(
4678                                JNI_OK);
4679 #endif /* USDT2 */
4680   return JNI_OK;
4681 JNI_END
4682 
4683 // Structure containing all jni functions
4684 struct JNINativeInterface_ jni_NativeInterface = {
4685     NULL,
4686     NULL,
4687     NULL,
4688 
4689     NULL,
4690 
4691     jni_GetVersion,
4692 
4693     jni_DefineClass,
4694     jni_FindClass,
4695 
4696     jni_FromReflectedMethod,
4697     jni_FromReflectedField,
4698 
4699     jni_ToReflectedMethod,
4700 
4701     jni_GetSuperclass,
4702     jni_IsAssignableFrom,
4703 
4704     jni_ToReflectedField,
4705 
4706     jni_Throw,
4707     jni_ThrowNew,
4708     jni_ExceptionOccurred,
4709     jni_ExceptionDescribe,
4710     jni_ExceptionClear,
4711     jni_FatalError,
4712 
4713     jni_PushLocalFrame,
4714     jni_PopLocalFrame,
4715 
4716     jni_NewGlobalRef,
4717     jni_DeleteGlobalRef,
4718     jni_DeleteLocalRef,
4719     jni_IsSameObject,
4720 
4721     jni_NewLocalRef,
4722     jni_EnsureLocalCapacity,
4723 
4724     jni_AllocObject,
4725     jni_NewObject,
4726     jni_NewObjectV,
4727     jni_NewObjectA,
4728 
4729     jni_GetObjectClass,
4730     jni_IsInstanceOf,
4731 
4732     jni_GetMethodID,
4733 
4734     jni_CallObjectMethod,
4735     jni_CallObjectMethodV,
4736     jni_CallObjectMethodA,
4737     jni_CallBooleanMethod,
4738     jni_CallBooleanMethodV,
4739     jni_CallBooleanMethodA,
4740     jni_CallByteMethod,
4741     jni_CallByteMethodV,
4742     jni_CallByteMethodA,
4743     jni_CallCharMethod,
4744     jni_CallCharMethodV,
4745     jni_CallCharMethodA,
4746     jni_CallShortMethod,
4747     jni_CallShortMethodV,
4748     jni_CallShortMethodA,
4749     jni_CallIntMethod,
4750     jni_CallIntMethodV,
4751     jni_CallIntMethodA,
4752     jni_CallLongMethod,
4753     jni_CallLongMethodV,
4754     jni_CallLongMethodA,
4755     jni_CallFloatMethod,
4756     jni_CallFloatMethodV,
4757     jni_CallFloatMethodA,
4758     jni_CallDoubleMethod,
4759     jni_CallDoubleMethodV,
4760     jni_CallDoubleMethodA,
4761     jni_CallVoidMethod,
4762     jni_CallVoidMethodV,
4763     jni_CallVoidMethodA,
4764 
4765     jni_CallNonvirtualObjectMethod,
4766     jni_CallNonvirtualObjectMethodV,
4767     jni_CallNonvirtualObjectMethodA,
4768     jni_CallNonvirtualBooleanMethod,
4769     jni_CallNonvirtualBooleanMethodV,
4770     jni_CallNonvirtualBooleanMethodA,
4771     jni_CallNonvirtualByteMethod,
4772     jni_CallNonvirtualByteMethodV,
4773     jni_CallNonvirtualByteMethodA,
4774     jni_CallNonvirtualCharMethod,
4775     jni_CallNonvirtualCharMethodV,
4776     jni_CallNonvirtualCharMethodA,
4777     jni_CallNonvirtualShortMethod,
4778     jni_CallNonvirtualShortMethodV,
4779     jni_CallNonvirtualShortMethodA,
4780     jni_CallNonvirtualIntMethod,
4781     jni_CallNonvirtualIntMethodV,
4782     jni_CallNonvirtualIntMethodA,
4783     jni_CallNonvirtualLongMethod,
4784     jni_CallNonvirtualLongMethodV,
4785     jni_CallNonvirtualLongMethodA,
4786     jni_CallNonvirtualFloatMethod,
4787     jni_CallNonvirtualFloatMethodV,
4788     jni_CallNonvirtualFloatMethodA,
4789     jni_CallNonvirtualDoubleMethod,
4790     jni_CallNonvirtualDoubleMethodV,
4791     jni_CallNonvirtualDoubleMethodA,
4792     jni_CallNonvirtualVoidMethod,
4793     jni_CallNonvirtualVoidMethodV,
4794     jni_CallNonvirtualVoidMethodA,
4795 
4796     jni_GetFieldID,
4797 
4798     jni_GetObjectField,
4799     jni_GetBooleanField,
4800     jni_GetByteField,
4801     jni_GetCharField,
4802     jni_GetShortField,
4803     jni_GetIntField,
4804     jni_GetLongField,
4805     jni_GetFloatField,
4806     jni_GetDoubleField,
4807 
4808     jni_SetObjectField,
4809     jni_SetBooleanField,
4810     jni_SetByteField,
4811     jni_SetCharField,
4812     jni_SetShortField,
4813     jni_SetIntField,
4814     jni_SetLongField,
4815     jni_SetFloatField,
4816     jni_SetDoubleField,
4817 
4818     jni_GetStaticMethodID,
4819 
4820     jni_CallStaticObjectMethod,
4821     jni_CallStaticObjectMethodV,
4822     jni_CallStaticObjectMethodA,
4823     jni_CallStaticBooleanMethod,
4824     jni_CallStaticBooleanMethodV,
4825     jni_CallStaticBooleanMethodA,
4826     jni_CallStaticByteMethod,
4827     jni_CallStaticByteMethodV,
4828     jni_CallStaticByteMethodA,
4829     jni_CallStaticCharMethod,
4830     jni_CallStaticCharMethodV,
4831     jni_CallStaticCharMethodA,
4832     jni_CallStaticShortMethod,
4833     jni_CallStaticShortMethodV,
4834     jni_CallStaticShortMethodA,
4835     jni_CallStaticIntMethod,
4836     jni_CallStaticIntMethodV,
4837     jni_CallStaticIntMethodA,
4838     jni_CallStaticLongMethod,
4839     jni_CallStaticLongMethodV,
4840     jni_CallStaticLongMethodA,
4841     jni_CallStaticFloatMethod,
4842     jni_CallStaticFloatMethodV,
4843     jni_CallStaticFloatMethodA,
4844     jni_CallStaticDoubleMethod,
4845     jni_CallStaticDoubleMethodV,
4846     jni_CallStaticDoubleMethodA,
4847     jni_CallStaticVoidMethod,
4848     jni_CallStaticVoidMethodV,
4849     jni_CallStaticVoidMethodA,
4850 
4851     jni_GetStaticFieldID,
4852 
4853     jni_GetStaticObjectField,
4854     jni_GetStaticBooleanField,
4855     jni_GetStaticByteField,
4856     jni_GetStaticCharField,
4857     jni_GetStaticShortField,
4858     jni_GetStaticIntField,
4859     jni_GetStaticLongField,
4860     jni_GetStaticFloatField,
4861     jni_GetStaticDoubleField,
4862 
4863     jni_SetStaticObjectField,
4864     jni_SetStaticBooleanField,
4865     jni_SetStaticByteField,
4866     jni_SetStaticCharField,
4867     jni_SetStaticShortField,
4868     jni_SetStaticIntField,
4869     jni_SetStaticLongField,
4870     jni_SetStaticFloatField,
4871     jni_SetStaticDoubleField,
4872 
4873     jni_NewString,
4874     jni_GetStringLength,
4875     jni_GetStringChars,
4876     jni_ReleaseStringChars,
4877 
4878     jni_NewStringUTF,
4879     jni_GetStringUTFLength,
4880     jni_GetStringUTFChars,
4881     jni_ReleaseStringUTFChars,
4882 
4883     jni_GetArrayLength,
4884 
4885     jni_NewObjectArray,
4886     jni_GetObjectArrayElement,
4887     jni_SetObjectArrayElement,
4888 
4889     jni_NewBooleanArray,
4890     jni_NewByteArray,
4891     jni_NewCharArray,
4892     jni_NewShortArray,
4893     jni_NewIntArray,
4894     jni_NewLongArray,
4895     jni_NewFloatArray,
4896     jni_NewDoubleArray,
4897 
4898     jni_GetBooleanArrayElements,
4899     jni_GetByteArrayElements,
4900     jni_GetCharArrayElements,
4901     jni_GetShortArrayElements,
4902     jni_GetIntArrayElements,
4903     jni_GetLongArrayElements,
4904     jni_GetFloatArrayElements,
4905     jni_GetDoubleArrayElements,
4906 
4907     jni_ReleaseBooleanArrayElements,
4908     jni_ReleaseByteArrayElements,
4909     jni_ReleaseCharArrayElements,
4910     jni_ReleaseShortArrayElements,
4911     jni_ReleaseIntArrayElements,
4912     jni_ReleaseLongArrayElements,
4913     jni_ReleaseFloatArrayElements,
4914     jni_ReleaseDoubleArrayElements,
4915 
4916     jni_GetBooleanArrayRegion,
4917     jni_GetByteArrayRegion,
4918     jni_GetCharArrayRegion,
4919     jni_GetShortArrayRegion,
4920     jni_GetIntArrayRegion,
4921     jni_GetLongArrayRegion,
4922     jni_GetFloatArrayRegion,
4923     jni_GetDoubleArrayRegion,
4924 
4925     jni_SetBooleanArrayRegion,
4926     jni_SetByteArrayRegion,
4927     jni_SetCharArrayRegion,
4928     jni_SetShortArrayRegion,
4929     jni_SetIntArrayRegion,
4930     jni_SetLongArrayRegion,
4931     jni_SetFloatArrayRegion,
4932     jni_SetDoubleArrayRegion,
4933 
4934     jni_RegisterNatives,
4935     jni_UnregisterNatives,
4936 
4937     jni_MonitorEnter,
4938     jni_MonitorExit,
4939 
4940     jni_GetJavaVM,
4941 
4942     jni_GetStringRegion,
4943     jni_GetStringUTFRegion,
4944 
4945     jni_GetPrimitiveArrayCritical,
4946     jni_ReleasePrimitiveArrayCritical,
4947 
4948     jni_GetStringCritical,
4949     jni_ReleaseStringCritical,
4950 
4951     jni_NewWeakGlobalRef,
4952     jni_DeleteWeakGlobalRef,
4953 
4954     jni_ExceptionCheck,
4955 
4956     jni_NewDirectByteBuffer,
4957     jni_GetDirectBufferAddress,
4958     jni_GetDirectBufferCapacity,
4959 
4960     // New 1_6 features
4961 
4962     jni_GetObjectRefType
4963 };
4964 
4965 
4966 // For jvmti use to modify jni function table.
4967 // Java threads in native contiues to run until it is transitioned
4968 // to VM at safepoint. Before the transition or before it is blocked
4969 // for safepoint it may access jni function table. VM could crash if
4970 // any java thread access the jni function table in the middle of memcpy.
4971 // To avoid this each function pointers are copied automically.
4972 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) {
4973   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
4974   intptr_t *a = (intptr_t *) jni_functions();
4975   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
4976   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
4977     Atomic::store_ptr(*b++, a++);
4978   }
4979 }
4980 
4981 void quicken_jni_functions() {
4982   // Replace Get<Primitive>Field with fast versions
4983   if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access()
4984       && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls
4985 #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2)
4986       // windows x86 currently needs SEH wrapper and the gain of the fast
4987       // versions currently isn't certain for server vm on uniprocessor.
4988       && os::is_MP()
4989 #endif
4990   ) {
4991     address func;
4992     func = JNI_FastGetField::generate_fast_get_boolean_field();
4993     if (func != (address)-1) {
4994       jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func;
4995     }
4996     func = JNI_FastGetField::generate_fast_get_byte_field();
4997     if (func != (address)-1) {
4998       jni_NativeInterface.GetByteField = (GetByteField_t)func;
4999     }
5000     func = JNI_FastGetField::generate_fast_get_char_field();
5001     if (func != (address)-1) {
5002       jni_NativeInterface.GetCharField = (GetCharField_t)func;
5003     }
5004     func = JNI_FastGetField::generate_fast_get_short_field();
5005     if (func != (address)-1) {
5006       jni_NativeInterface.GetShortField = (GetShortField_t)func;
5007     }
5008     func = JNI_FastGetField::generate_fast_get_int_field();
5009     if (func != (address)-1) {
5010       jni_NativeInterface.GetIntField = (GetIntField_t)func;
5011     }
5012     func = JNI_FastGetField::generate_fast_get_long_field();
5013     if (func != (address)-1) {
5014       jni_NativeInterface.GetLongField = (GetLongField_t)func;
5015     }
5016     func = JNI_FastGetField::generate_fast_get_float_field();
5017     if (func != (address)-1) {
5018       jni_NativeInterface.GetFloatField = (GetFloatField_t)func;
5019     }
5020     func = JNI_FastGetField::generate_fast_get_double_field();
5021     if (func != (address)-1) {
5022       jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func;
5023     }
5024   }
5025 }
5026 
5027 // Returns the function structure
5028 struct JNINativeInterface_* jni_functions() {
5029 #if INCLUDE_JNI_CHECK
5030   if (CheckJNICalls) return jni_functions_check();
5031 #endif // INCLUDE_JNI_CHECK
5032   return &jni_NativeInterface;
5033 }
5034 
5035 // Returns the function structure
5036 struct JNINativeInterface_* jni_functions_nocheck() {
5037   return &jni_NativeInterface;
5038 }
5039 
5040 static void post_thread_start_event(const JavaThread* jt) {
5041   assert(jt != NULL, "invariant");
5042   EventThreadStart event;
5043   if (event.should_commit()) {
5044     event.set_thread(JFR_THREAD_ID(jt));
5045     event.commit();
5046   }
5047 }
5048 
5049 // Invocation API
5050 
5051 
5052 // Forward declaration
5053 extern const struct JNIInvokeInterface_ jni_InvokeInterface;
5054 
5055 // Global invocation API vars
5056 volatile jint vm_created = 0;
5057 // Indicate whether it is safe to recreate VM
5058 volatile jint safe_to_recreate_vm = 1;
5059 struct JavaVM_ main_vm = {&jni_InvokeInterface};
5060 
5061 
5062 #define JAVASTACKSIZE (400 * 1024)    /* Default size of a thread java stack */
5063 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL };
5064 
5065 #ifndef USDT2
5066 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*);
5067 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint);
5068 #else /* USDT2 */
5069 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint
5070                     , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref));
5071 #endif /* USDT2 */
5072 
5073 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) {
5074 #ifndef USDT2
5075   HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_);
5076 #else /* USDT2 */
5077   HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY(
5078                                              args_);
5079 #endif /* USDT2 */
5080   JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_;
5081   jint ret = JNI_ERR;
5082   DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret);
5083 
5084   if (Threads::is_supported_jni_version(args->version)) {
5085     ret = JNI_OK;
5086   }
5087   // 1.1 style no longer supported in hotspot.
5088   // According the JNI spec, we should update args->version on return.
5089   // We also use the structure to communicate with launcher about default
5090   // stack size.
5091   if (args->version == JNI_VERSION_1_1) {
5092     args->version = JNI_VERSION_1_2;
5093     // javaStackSize is int in arguments structure
5094     assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow");
5095     args->javaStackSize = (jint)(ThreadStackSize * K);
5096   }
5097   return ret;
5098 }
5099 
5100 #ifndef PRODUCT
5101 
5102 #include "gc_implementation/shared/gcTimer.hpp"
5103 #include "gc_interface/collectedHeap.hpp"
5104 #if INCLUDE_ALL_GCS
5105 #include "gc_implementation/g1/heapRegionRemSet.hpp"
5106 #endif
5107 #include "memory/guardedMemory.hpp"
5108 #include "utilities/quickSort.hpp"
5109 #include "utilities/ostream.hpp"
5110 #if INCLUDE_VM_STRUCTS
5111 #include "runtime/vmStructs.hpp"
5112 #endif
5113 
5114 #define run_unit_test(unit_test_function_call)              \
5115   tty->print_cr("Running test: " #unit_test_function_call); \
5116   unit_test_function_call
5117 
5118 // Forward declaration
5119 void TestOS_test();
5120 void TestReservedSpace_test();
5121 void TestReserveMemorySpecial_test();
5122 void TestVirtualSpace_test();
5123 void TestMetaspaceAux_test();
5124 void SpaceManager_test_adjust_initial_chunk_size();
5125 void TestMetachunk_test();
5126 void TestVirtualSpaceNode_test();
5127 void TestNewSize_test();
5128 void TestKlass_test();
5129 void Test_linked_list();
5130 void TestResourcehash_test();
5131 void TestChunkedList_test();
5132 #if INCLUDE_ALL_GCS
5133 void TestOldFreeSpaceCalculation_test();
5134 void TestG1BiasedArray_test();
5135 void TestBufferingOopClosure_test();
5136 void TestCodeCacheRemSet_test();
5137 void FreeRegionList_test();
5138 void ChunkManager_test_list_index();
5139 #endif
5140 
5141 void execute_internal_vm_tests() {
5142   if (ExecuteInternalVMTests) {
5143     tty->print_cr("Running internal VM tests");
5144     run_unit_test(TestOS_test());
5145     run_unit_test(TestReservedSpace_test());
5146     run_unit_test(TestReserveMemorySpecial_test());
5147     run_unit_test(TestVirtualSpace_test());
5148     run_unit_test(TestMetaspaceAux_test());
5149     run_unit_test(TestMetachunk_test());
5150     run_unit_test(TestVirtualSpaceNode_test());
5151     run_unit_test(GlobalDefinitions::test_globals());
5152     run_unit_test(GlobalDefinitions::test_proper_unit());
5153     run_unit_test(GCTimerAllTest::all());
5154     run_unit_test(arrayOopDesc::test_max_array_length());
5155     run_unit_test(CollectedHeap::test_is_in());
5156     run_unit_test(QuickSort::test_quick_sort());
5157     run_unit_test(GuardedMemory::test_guarded_memory());
5158     run_unit_test(AltHashing::test_alt_hash());
5159     run_unit_test(test_loggc_filename());
5160     run_unit_test(test_snprintf());
5161     run_unit_test(TestNewSize_test());
5162     run_unit_test(TestKlass_test());
5163     run_unit_test(TestResourcehash_test());
5164     run_unit_test(Test_linked_list());
5165     run_unit_test(TestChunkedList_test());
5166     run_unit_test(ObjectMonitor::sanity_checks());
5167 #if INCLUDE_VM_STRUCTS
5168     run_unit_test(VMStructs::test());
5169 #endif
5170 #if INCLUDE_ALL_GCS
5171     run_unit_test(TestOldFreeSpaceCalculation_test());
5172     run_unit_test(TestG1BiasedArray_test());
5173     run_unit_test(HeapRegionRemSet::test_prt());
5174     run_unit_test(SpaceManager_test_adjust_initial_chunk_size());
5175     run_unit_test(ChunkManager_test_list_index());
5176     run_unit_test(TestBufferingOopClosure_test());
5177     run_unit_test(TestCodeCacheRemSet_test());
5178     if (UseG1GC) {
5179       run_unit_test(FreeRegionList_test());
5180     }
5181 #endif
5182     tty->print_cr("All internal VM tests passed");
5183   }
5184 }
5185 
5186 #undef run_unit_test
5187 
5188 #endif
5189 
5190 #ifndef USDT2
5191 HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args);
5192 DT_RETURN_MARK_DECL(CreateJavaVM, jint);
5193 #else /* USDT2 */
5194 DT_RETURN_MARK_DECL(CreateJavaVM, jint
5195                     , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref));
5196 #endif /* USDT2 */
5197 
5198 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
5199 #ifndef USDT2
5200   HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args);
5201 #else /* USDT2 */
5202   HOTSPOT_JNI_CREATEJAVAVM_ENTRY(
5203                                  (void **) vm, penv, args);
5204 #endif /* USDT2 */
5205 
5206   jint result = JNI_ERR;
5207   DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result);
5208 
5209   // We're about to use Atomic::xchg for synchronization.  Some Zero
5210   // platforms use the GCC builtin __sync_lock_test_and_set for this,
5211   // but __sync_lock_test_and_set is not guaranteed to do what we want
5212   // on all architectures.  So we check it works before relying on it.
5213 #if defined(ZERO) && defined(ASSERT)
5214   {
5215     jint a = 0xcafebabe;
5216     jint b = Atomic::xchg(0xdeadbeef, &a);
5217     void *c = &a;
5218     void *d = Atomic::xchg_ptr(&b, &c);
5219     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
5220     assert(c == &b && d == &a, "Atomic::xchg_ptr() works");
5221   }
5222 #endif // ZERO && ASSERT
5223 
5224   // At the moment it's only possible to have one Java VM,
5225   // since some of the runtime state is in global variables.
5226 
5227   // We cannot use our mutex locks here, since they only work on
5228   // Threads. We do an atomic compare and exchange to ensure only
5229   // one thread can call this method at a time
5230 
5231   // We use Atomic::xchg rather than Atomic::add/dec since on some platforms
5232   // the add/dec implementations are dependent on whether we are running
5233   // on a multiprocessor, and at this stage of initialization the os::is_MP
5234   // function used to determine this will always return false. Atomic::xchg
5235   // does not have this problem.
5236   if (Atomic::xchg(1, &vm_created) == 1) {
5237     return JNI_EEXIST;   // already created, or create attempt in progress
5238   }
5239   if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) {
5240     return JNI_ERR;  // someone tried and failed and retry not allowed.
5241   }
5242 
5243   assert(vm_created == 1, "vm_created is true during the creation");
5244 
5245   /**
5246    * Certain errors during initialization are recoverable and do not
5247    * prevent this method from being called again at a later time
5248    * (perhaps with different arguments).  However, at a certain
5249    * point during initialization if an error occurs we cannot allow
5250    * this function to be called again (or it will crash).  In those
5251    * situations, the 'canTryAgain' flag is set to false, which atomically
5252    * sets safe_to_recreate_vm to 1, such that any new call to
5253    * JNI_CreateJavaVM will immediately fail using the above logic.
5254    */
5255   bool can_try_again = true;
5256 
5257   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
5258   if (result == JNI_OK) {
5259     JavaThread *thread = JavaThread::current();
5260     /* thread is thread_in_vm here */
5261     *vm = (JavaVM *)(&main_vm);
5262     *(JNIEnv**)penv = thread->jni_environment();
5263 
5264     // Tracks the time application was running before GC
5265     RuntimeService::record_application_start();
5266 
5267     // Notify JVMTI
5268     if (JvmtiExport::should_post_thread_life()) {
5269        JvmtiExport::post_thread_start(thread);
5270     }
5271 
5272     post_thread_start_event(thread);
5273 
5274 #ifndef PRODUCT
5275   #ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
5276     #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
5277   #endif
5278 
5279     // Check if we should compile all classes on bootclasspath
5280     if (CompileTheWorld) ClassLoader::compile_the_world();
5281     if (ReplayCompiles) ciReplay::replay(thread);
5282 
5283     // Some platforms (like Win*) need a wrapper around these test
5284     // functions in order to properly handle error conditions.
5285     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(test_error_handler);
5286     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(execute_internal_vm_tests);
5287 #endif
5288 
5289     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
5290     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5291   } else {
5292     if (can_try_again) {
5293       // reset safe_to_recreate_vm to 1 so that retrial would be possible
5294       safe_to_recreate_vm = 1;
5295     }
5296 
5297     // Creation failed. We must reset vm_created
5298     *vm = 0;
5299     *(JNIEnv**)penv = 0;
5300     // reset vm_created last to avoid race condition. Use OrderAccess to
5301     // control both compiler and architectural-based reordering.
5302     OrderAccess::release_store(&vm_created, 0);
5303   }
5304 
5305   return result;
5306 }
5307 
5308 #ifndef USDT2
5309 HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \
5310   JavaVM**, jsize, jsize*);
5311 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint);
5312 #endif /* !USDT2 */
5313 
5314 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) {
5315   // See bug 4367188, the wrapper can sometimes cause VM crashes
5316   // JNIWrapper("GetCreatedJavaVMs");
5317 #ifndef USDT2
5318   HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \
5319     vm_buf, bufLen, numVMs);
5320 #else /* USDT2 */
5321   HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY(
5322                                       (void **) vm_buf, bufLen, (uintptr_t *) numVMs);
5323 #endif /* USDT2 */
5324   if (vm_created) {
5325     if (numVMs != NULL) *numVMs = 1;
5326     if (bufLen > 0)     *vm_buf = (JavaVM *)(&main_vm);
5327   } else {
5328     if (numVMs != NULL) *numVMs = 0;
5329   }
5330 #ifndef USDT2
5331   HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK);
5332 #else /* USDT2 */
5333   HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN(
5334                                     JNI_OK);
5335 #endif /* USDT2 */
5336   return JNI_OK;
5337 }
5338 
5339 extern "C" {
5340 
5341 #ifndef USDT2
5342 DT_RETURN_MARK_DECL(DestroyJavaVM, jint);
5343 #else /* USDT2 */
5344 DT_RETURN_MARK_DECL(DestroyJavaVM, jint
5345                     , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref));
5346 #endif /* USDT2 */
5347 
5348 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
5349 #ifndef USDT2
5350   DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm);
5351 #else /* USDT2 */
5352   HOTSPOT_JNI_DESTROYJAVAVM_ENTRY(
5353                                   vm);
5354 #endif /* USDT2 */
5355   jint res = JNI_ERR;
5356   DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res);
5357 
5358   if (!vm_created) {
5359     res = JNI_ERR;
5360     return res;
5361   }
5362 
5363   JNIWrapper("DestroyJavaVM");
5364   JNIEnv *env;
5365   JavaVMAttachArgs destroyargs;
5366   destroyargs.version = CurrentVersion;
5367   destroyargs.name = (char *)"DestroyJavaVM";
5368   destroyargs.group = NULL;
5369   res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs);
5370   if (res != JNI_OK) {
5371     return res;
5372   }
5373 
5374   // Since this is not a JVM_ENTRY we have to set the thread state manually before entering.
5375   JavaThread* thread = JavaThread::current();
5376   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
5377   if (Threads::destroy_vm()) {
5378     // Should not change thread state, VM is gone
5379     vm_created = false;
5380     res = JNI_OK;
5381     return res;
5382   } else {
5383     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5384     res = JNI_ERR;
5385     return res;
5386   }
5387 }
5388 
5389 
5390 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) {
5391   JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args;
5392 
5393   // Check below commented out from JDK1.2fcs as well
5394   /*
5395   if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) {
5396     return JNI_EVERSION;
5397   }
5398   */
5399 
5400   Thread* t = ThreadLocalStorage::get_thread_slow();
5401   if (t != NULL) {
5402     // If the thread has been attached this operation is a no-op
5403     *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
5404     return JNI_OK;
5405   }
5406 
5407   // Create a thread and mark it as attaching so it will be skipped by the
5408   // ThreadsListEnumerator - see CR 6404306
5409   JavaThread* thread = new JavaThread(true);
5410 
5411   // Set correct safepoint info. The thread is going to call into Java when
5412   // initializing the Java level thread object. Hence, the correct state must
5413   // be set in order for the Safepoint code to deal with it correctly.
5414   thread->set_thread_state(_thread_in_vm);
5415   // Must do this before initialize_thread_local_storage
5416   thread->record_stack_base_and_size();
5417 
5418   thread->initialize_thread_local_storage();
5419 
5420   if (!os::create_attached_thread(thread)) {
5421     delete thread;
5422     return JNI_ERR;
5423   }
5424   // Enable stack overflow checks
5425   thread->create_stack_guard_pages();
5426 
5427   thread->initialize_tlab();
5428 
5429   thread->cache_global_variables();
5430 
5431   // Crucial that we do not have a safepoint check for this thread, since it has
5432   // not been added to the Thread list yet.
5433   { Threads_lock->lock_without_safepoint_check();
5434     // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
5435     // avoid this thread trying to do a GC before it is added to the thread-list
5436     thread->set_active_handles(JNIHandleBlock::allocate_block());
5437     Threads::add(thread, daemon);
5438     Threads_lock->unlock();
5439   }
5440   // Create thread group and name info from attach arguments
5441   oop group = NULL;
5442   char* thread_name = NULL;
5443   if (args != NULL && Threads::is_supported_jni_version(args->version)) {
5444     group = JNIHandles::resolve(args->group);
5445     thread_name = args->name; // may be NULL
5446   }
5447   if (group == NULL) group = Universe::main_thread_group();
5448 
5449   // Create Java level thread object and attach it to this thread
5450   bool attach_failed = false;
5451   {
5452     EXCEPTION_MARK;
5453     HandleMark hm(THREAD);
5454     Handle thread_group(THREAD, group);
5455     thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD);
5456     if (HAS_PENDING_EXCEPTION) {
5457       CLEAR_PENDING_EXCEPTION;
5458       // cleanup outside the handle mark.
5459       attach_failed = true;
5460     }
5461   }
5462 
5463   if (attach_failed) {
5464     // Added missing cleanup
5465     thread->cleanup_failed_attach_current_thread();
5466     return JNI_ERR;
5467   }
5468 
5469   // mark the thread as no longer attaching
5470   // this uses a fence to push the change through so we don't have
5471   // to regrab the threads_lock
5472   thread->set_done_attaching_via_jni();
5473 
5474   // Set java thread status.
5475   java_lang_Thread::set_thread_status(thread->threadObj(),
5476               java_lang_Thread::RUNNABLE);
5477 
5478   // Notify the debugger
5479   if (JvmtiExport::should_post_thread_life()) {
5480     JvmtiExport::post_thread_start(thread);
5481   }
5482 
5483   post_thread_start_event(thread);
5484 
5485   *(JNIEnv**)penv = thread->jni_environment();
5486 
5487   // Now leaving the VM, so change thread_state. This is normally automatically taken care
5488   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
5489   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
5490   // needed.
5491 
5492   ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5493 
5494   // Perform any platform dependent FPU setup
5495   os::setup_fpu();
5496 
5497   return JNI_OK;
5498 }
5499 
5500 
5501 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
5502 #ifndef USDT2
5503   DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args);
5504 #else /* USDT2 */
5505   HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(
5506                                         vm, penv, _args);
5507 #endif /* USDT2 */
5508   if (!vm_created) {
5509 #ifndef USDT2
5510     DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR);
5511 #else /* USDT2 */
5512   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(
5513                                          (uint32_t) JNI_ERR);
5514 #endif /* USDT2 */
5515     return JNI_ERR;
5516   }
5517 
5518   JNIWrapper("AttachCurrentThread");
5519   jint ret = attach_current_thread(vm, penv, _args, false);
5520 #ifndef USDT2
5521   DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret);
5522 #else /* USDT2 */
5523   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(
5524                                          ret);
5525 #endif /* USDT2 */
5526   return ret;
5527 }
5528 
5529 
5530 jint JNICALL jni_DetachCurrentThread(JavaVM *vm)  {
5531 #ifndef USDT2
5532   DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm);
5533 #else /* USDT2 */
5534   HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(
5535                                         vm);
5536 #endif /* USDT2 */
5537   VM_Exit::block_if_vm_exited();
5538 
5539   JNIWrapper("DetachCurrentThread");
5540 
5541   // If the thread has been deattacted the operations is a no-op
5542   if (ThreadLocalStorage::thread() == NULL) {
5543 #ifndef USDT2
5544     DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK);
5545 #else /* USDT2 */
5546   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
5547                                          JNI_OK);
5548 #endif /* USDT2 */
5549     return JNI_OK;
5550   }
5551 
5552   JavaThread* thread = JavaThread::current();
5553   if (thread->has_last_Java_frame()) {
5554 #ifndef USDT2
5555     DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR);
5556 #else /* USDT2 */
5557   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
5558                                          (uint32_t) JNI_ERR);
5559 #endif /* USDT2 */
5560     // Can't detach a thread that's running java, that can't work.
5561     return JNI_ERR;
5562   }
5563 
5564   // Safepoint support. Have to do call-back to safepoint code, if in the
5565   // middel of a safepoint operation
5566   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
5567 
5568   // XXX: Note that JavaThread::exit() call below removes the guards on the
5569   // stack pages set up via enable_stack_{red,yellow}_zone() calls
5570   // above in jni_AttachCurrentThread. Unfortunately, while the setting
5571   // of the guards is visible in jni_AttachCurrentThread above,
5572   // the removal of the guards is buried below in JavaThread::exit()
5573   // here. The abstraction should be more symmetrically either exposed
5574   // or hidden (e.g. it could probably be hidden in the same
5575   // (platform-dependent) methods where we do alternate stack
5576   // maintenance work?)
5577   thread->exit(false, JavaThread::jni_detach);
5578   delete thread;
5579 
5580 #ifndef USDT2
5581   DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK);
5582 #else /* USDT2 */
5583   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
5584                                          JNI_OK);
5585 #endif /* USDT2 */
5586   return JNI_OK;
5587 }
5588 
5589 #ifndef USDT2
5590 DT_RETURN_MARK_DECL(GetEnv, jint);
5591 #else /* USDT2 */
5592 DT_RETURN_MARK_DECL(GetEnv, jint
5593                     , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
5594 #endif /* USDT2 */
5595 
5596 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
5597 #ifndef USDT2
5598   DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version);
5599 #else /* USDT2 */
5600   HOTSPOT_JNI_GETENV_ENTRY(
5601                            vm, penv, version);
5602 #endif /* USDT2 */
5603   jint ret = JNI_ERR;
5604   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
5605 
5606   if (!vm_created) {
5607     *penv = NULL;
5608     ret = JNI_EDETACHED;
5609     return ret;
5610   }
5611 
5612   if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {
5613     return ret;
5614   }
5615 
5616 #ifndef JVMPI_VERSION_1
5617 // need these in order to be polite about older agents
5618 #define JVMPI_VERSION_1   ((jint)0x10000001)
5619 #define JVMPI_VERSION_1_1 ((jint)0x10000002)
5620 #define JVMPI_VERSION_1_2 ((jint)0x10000003)
5621 #endif // !JVMPI_VERSION_1
5622 
5623   Thread* thread = ThreadLocalStorage::thread();
5624   if (thread != NULL && thread->is_Java_thread()) {
5625     if (Threads::is_supported_jni_version_including_1_1(version)) {
5626       *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment();
5627       ret = JNI_OK;
5628       return ret;
5629 
5630     } else if (version == JVMPI_VERSION_1 ||
5631                version == JVMPI_VERSION_1_1 ||
5632                version == JVMPI_VERSION_1_2) {
5633       tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported.");
5634       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
5635       ret = JNI_EVERSION;
5636       return ret;
5637     } else if (JvmtiExport::is_jvmdi_version(version)) {
5638       tty->print_cr("FATAL ERROR: JVMDI is no longer supported.");
5639       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
5640       ret = JNI_EVERSION;
5641       return ret;
5642     } else {
5643       *penv = NULL;
5644       ret = JNI_EVERSION;
5645       return ret;
5646     }
5647   } else {
5648     *penv = NULL;
5649     ret = JNI_EDETACHED;
5650     return ret;
5651   }
5652 }
5653 
5654 
5655 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) {
5656 #ifndef USDT2
5657   DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args);
5658 #else /* USDT2 */
5659   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY(
5660                                                 vm, penv, _args);
5661 #endif /* USDT2 */
5662   if (!vm_created) {
5663 #ifndef USDT2
5664     DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR);
5665 #else /* USDT2 */
5666   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(
5667                                                  (uint32_t) JNI_ERR);
5668 #endif /* USDT2 */
5669     return JNI_ERR;
5670   }
5671 
5672   JNIWrapper("AttachCurrentThreadAsDaemon");
5673   jint ret = attach_current_thread(vm, penv, _args, true);
5674 #ifndef USDT2
5675   DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret);
5676 #else /* USDT2 */
5677   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(
5678                                                  ret);
5679 #endif /* USDT2 */
5680   return ret;
5681 }
5682 
5683 
5684 } // End extern "C"
5685 
5686 const struct JNIInvokeInterface_ jni_InvokeInterface = {
5687     NULL,
5688     NULL,
5689     NULL,
5690 
5691     jni_DestroyJavaVM,
5692     jni_AttachCurrentThread,
5693     jni_DetachCurrentThread,
5694     jni_GetEnv,
5695     jni_AttachCurrentThreadAsDaemon
5696 };