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 #include "gc_implementation/shenandoah/shenandoahStringDedup.hpp"
  42 #endif // INCLUDE_ALL_GCS
  43 #include "memory/allocation.hpp"
  44 #include "memory/allocation.inline.hpp"
  45 #include "memory/gcLocker.inline.hpp"
  46 #include "memory/oopFactory.hpp"
  47 #include "memory/universe.inline.hpp"
  48 #include "oops/instanceKlass.hpp"
  49 #include "oops/instanceOop.hpp"
  50 #include "oops/markOop.hpp"
  51 #include "oops/method.hpp"
  52 #include "oops/objArrayKlass.hpp"
  53 #include "oops/objArrayOop.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/symbol.hpp"
  56 #include "oops/typeArrayKlass.hpp"
  57 #include "oops/typeArrayOop.hpp"
  58 #include "prims/jni.h"
  59 #include "prims/jniCheck.hpp"
  60 #include "prims/jniExport.hpp"
  61 #include "prims/jniFastGetField.hpp"
  62 #include "prims/jvm.h"
  63 #include "prims/jvm_misc.hpp"
  64 #include "prims/jvmtiExport.hpp"
  65 #include "prims/jvmtiThreadState.hpp"
  66 #include "runtime/compilationPolicy.hpp"
  67 #include "runtime/fieldDescriptor.hpp"
  68 #include "runtime/fprofiler.hpp"
  69 #include "runtime/handles.inline.hpp"
  70 #include "runtime/interfaceSupport.hpp"
  71 #include "runtime/java.hpp"
  72 #include "runtime/javaCalls.hpp"
  73 #include "runtime/jfieldIDWorkaround.hpp"
  74 #include "runtime/orderAccess.inline.hpp"
  75 #include "runtime/reflection.hpp"
  76 #include "runtime/sharedRuntime.hpp"
  77 #include "runtime/signature.hpp"
  78 #include "runtime/thread.inline.hpp"
  79 #include "runtime/vm_operations.hpp"
  80 #include "services/memTracker.hpp"
  81 #include "services/runtimeService.hpp"
  82 #include "utilities/defaultStream.hpp"
  83 #include "utilities/dtrace.hpp"
  84 #include "utilities/events.hpp"
  85 #include "utilities/histogram.hpp"
  86 #ifdef TARGET_OS_FAMILY_linux
  87 # include "os_linux.inline.hpp"
  88 #endif
  89 #ifdef TARGET_OS_FAMILY_solaris
  90 # include "os_solaris.inline.hpp"
  91 #endif
  92 #ifdef TARGET_OS_FAMILY_windows
  93 # include "os_windows.inline.hpp"
  94 #endif
  95 #ifdef TARGET_OS_FAMILY_bsd
  96 # include "os_bsd.inline.hpp"
  97 #endif
  98 
  99 static jint CurrentVersion = JNI_VERSION_1_8;
 100 
 101 
 102 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 103 // '-return' probe regardless of the return path is taken out of the function.
 104 // Methods that have multiple return paths use this to avoid having to
 105 // instrument each return path.  Methods that use CHECK or THROW must use this
 106 // since those macros can cause an immedate uninstrumented return.
 107 //
 108 // In order to get the return value, a reference to the variable containing
 109 // the return value must be passed to the contructor of the object, and
 110 // the return value must be set before return (since the mark object has
 111 // a reference to it).
 112 //
 113 // Example:
 114 // DT_RETURN_MARK_DECL(SomeFunc, int);
 115 // JNI_ENTRY(int, SomeFunc, ...)
 116 //   int return_value = 0;
 117 //   DT_RETURN_MARK(SomeFunc, int, (const int&)return_value);
 118 //   foo(CHECK_0)
 119 //   return_value = 5;
 120 //   return return_value;
 121 // JNI_END
 122 #ifndef USDT2
 123 #define DT_RETURN_MARK_DECL(name, type)                                    \
 124   HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type);                \
 125   DTRACE_ONLY(                                                             \
 126     class DTraceReturnProbeMark_##name {                                   \
 127      public:                                                               \
 128       const type& _ret_ref;                                                \
 129       DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
 130       ~DTraceReturnProbeMark_##name() {                                    \
 131         HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref);           \
 132       }                                                                    \
 133     }                                                                      \
 134   )
 135 // Void functions are simpler since there's no return value
 136 #define DT_VOID_RETURN_MARK_DECL(name)                                     \
 137   HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return);                      \
 138   DTRACE_ONLY(                                                             \
 139     class DTraceReturnProbeMark_##name {                                   \
 140      public:                                                               \
 141       ~DTraceReturnProbeMark_##name() {                                    \
 142         HS_DTRACE_PROBE0(hotspot_jni, name##__return);                     \
 143       }                                                                    \
 144     }                                                                      \
 145   )
 146 
 147 #else /* USDT2 */
 148 
 149 #define DT_RETURN_MARK_DECL(name, type, probe)                             \
 150   DTRACE_ONLY(                                                             \
 151     class DTraceReturnProbeMark_##name {                                   \
 152      public:                                                               \
 153       const type& _ret_ref;                                                \
 154       DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
 155       ~DTraceReturnProbeMark_##name() {                                    \
 156         probe;                                                             \
 157       }                                                                    \
 158     }                                                                      \
 159   )
 160 // Void functions are simpler since there's no return value
 161 #define DT_VOID_RETURN_MARK_DECL(name, probe)                              \
 162   DTRACE_ONLY(                                                             \
 163     class DTraceReturnProbeMark_##name {                                   \
 164      public:                                                               \
 165       ~DTraceReturnProbeMark_##name() {                                    \
 166         probe;                                                             \
 167       }                                                                    \
 168     }                                                                      \
 169   )
 170 #endif /* USDT2 */
 171 
 172 // Place these macros in the function to mark the return.  Non-void
 173 // functions need the type and address of the return value.
 174 #define DT_RETURN_MARK(name, type, ref) \
 175   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) )
 176 #define DT_VOID_RETURN_MARK(name) \
 177   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark )
 178 
 179 
 180 // Use these to select distinct code for floating-point vs. non-floating point
 181 // situations.  Used from within common macros where we need slightly
 182 // different behavior for Float/Double
 183 #define FP_SELECT_Boolean(intcode, fpcode) intcode
 184 #define FP_SELECT_Byte(intcode, fpcode)    intcode
 185 #define FP_SELECT_Char(intcode, fpcode)    intcode
 186 #define FP_SELECT_Short(intcode, fpcode)   intcode
 187 #define FP_SELECT_Object(intcode, fpcode)  intcode
 188 #define FP_SELECT_Int(intcode, fpcode)     intcode
 189 #define FP_SELECT_Long(intcode, fpcode)    intcode
 190 #define FP_SELECT_Float(intcode, fpcode)   fpcode
 191 #define FP_SELECT_Double(intcode, fpcode)  fpcode
 192 #define FP_SELECT(TypeName, intcode, fpcode) \
 193   FP_SELECT_##TypeName(intcode, fpcode)
 194 
 195 #define COMMA ,
 196 
 197 // Choose DT_RETURN_MARK macros  based on the type: float/double -> void
 198 // (dtrace doesn't do FP yet)
 199 #ifndef USDT2
 200 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \
 201   FP_SELECT(TypeName, \
 202     DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) )
 203 #else /* USDT2 */
 204 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe)    \
 205   FP_SELECT(TypeName, \
 206     DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) )
 207 #endif /* USDT2 */
 208 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \
 209   FP_SELECT(TypeName, \
 210     DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) )
 211 
 212 
 213 // out-of-line helpers for class jfieldIDWorkaround:
 214 
 215 bool jfieldIDWorkaround::is_valid_jfieldID(Klass* k, jfieldID id) {
 216   if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) {
 217     uintptr_t as_uint = (uintptr_t) id;
 218     intptr_t offset = raw_instance_offset(id);
 219     if (is_checked_jfieldID(id)) {
 220       if (!klass_hash_ok(k, id)) {
 221         return false;
 222       }
 223     }
 224     return InstanceKlass::cast(k)->contains_field_offset(offset);
 225   } else {
 226     JNIid* result = (JNIid*) id;
 227 #ifdef ASSERT
 228     return result != NULL && result->is_static_field_id();
 229 #else
 230     return result != NULL;
 231 #endif
 232   }
 233 }
 234 
 235 
 236 intptr_t jfieldIDWorkaround::encode_klass_hash(Klass* k, intptr_t offset) {
 237   if (offset <= small_offset_mask) {
 238     Klass* field_klass = k;
 239     Klass* super_klass = field_klass->super();
 240     // With compressed oops the most super class with nonstatic fields would
 241     // be the owner of fields embedded in the header.
 242     while (InstanceKlass::cast(super_klass)->has_nonstatic_fields() &&
 243            InstanceKlass::cast(super_klass)->contains_field_offset(offset)) {
 244       field_klass = super_klass;   // super contains the field also
 245       super_klass = field_klass->super();
 246     }
 247     debug_only(No_Safepoint_Verifier nosafepoint;)
 248     uintptr_t klass_hash = field_klass->identity_hash();
 249     return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place;
 250   } else {
 251 #if 0
 252     #ifndef PRODUCT
 253     {
 254       ResourceMark rm;
 255       warning("VerifyJNIFields: long offset %d in %s", offset, k->external_name());
 256     }
 257     #endif
 258 #endif
 259     return 0;
 260   }
 261 }
 262 
 263 bool jfieldIDWorkaround::klass_hash_ok(Klass* k, jfieldID id) {
 264   uintptr_t as_uint = (uintptr_t) id;
 265   intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask;
 266   do {
 267     debug_only(No_Safepoint_Verifier nosafepoint;)
 268     // Could use a non-blocking query for identity_hash here...
 269     if ((k->identity_hash() & klass_mask) == klass_hash)
 270       return true;
 271     k = k->super();
 272   } while (k != NULL);
 273   return false;
 274 }
 275 
 276 void jfieldIDWorkaround::verify_instance_jfieldID(Klass* k, jfieldID id) {
 277   guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" );
 278   uintptr_t as_uint = (uintptr_t) id;
 279   intptr_t offset = raw_instance_offset(id);
 280   if (VerifyJNIFields) {
 281     if (is_checked_jfieldID(id)) {
 282       guarantee(klass_hash_ok(k, id),
 283     "Bug in native code: jfieldID class must match object");
 284     } else {
 285 #if 0
 286       #ifndef PRODUCT
 287       if (Verbose) {
 288   ResourceMark rm;
 289   warning("VerifyJNIFields: unverified offset %d for %s", offset, k->external_name());
 290       }
 291       #endif
 292 #endif
 293     }
 294   }
 295   guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
 296       "Bug in native code: jfieldID offset must address interior of object");
 297 }
 298 
 299 // Wrapper to trace JNI functions
 300 
 301 #ifdef ASSERT
 302   Histogram* JNIHistogram;
 303   static volatile jint JNIHistogram_lock = 0;
 304 
 305   class JNITraceWrapper : public StackObj {
 306    public:
 307     JNITraceWrapper(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
 308       if (TraceJNICalls) {
 309         va_list ap;
 310         va_start(ap, format);
 311         tty->print("JNI ");
 312         tty->vprint_cr(format, ap);
 313         va_end(ap);
 314       }
 315     }
 316   };
 317 
 318   class JNIHistogramElement : public HistogramElement {
 319     public:
 320      JNIHistogramElement(const char* name);
 321   };
 322 
 323   JNIHistogramElement::JNIHistogramElement(const char* elementName) {
 324     _name = elementName;
 325     uintx count = 0;
 326 
 327     while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) {
 328       while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) {
 329         count +=1;
 330         if ( (WarnOnStalledSpinLock > 0)
 331           && (count % WarnOnStalledSpinLock == 0)) {
 332           warning("JNIHistogram_lock seems to be stalled");
 333         }
 334       }
 335      }
 336 
 337 
 338     if(JNIHistogram == NULL)
 339       JNIHistogram = new Histogram("JNI Call Counts",100);
 340 
 341     JNIHistogram->add_element(this);
 342     Atomic::dec(&JNIHistogram_lock);
 343   }
 344 
 345   #define JNICountWrapper(arg)                                     \
 346      static JNIHistogramElement* e = new JNIHistogramElement(arg); \
 347       /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
 348      if (e != NULL) e->increment_count()
 349   #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg)
 350 #else
 351   #define JNIWrapper(arg)
 352 #endif
 353 
 354 
 355 // Implementation of JNI entries
 356 
 357 #ifndef USDT2
 358 DT_RETURN_MARK_DECL(DefineClass, jclass);
 359 #else /* USDT2 */
 360 DT_RETURN_MARK_DECL(DefineClass, jclass
 361                     , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
 362 #endif /* USDT2 */
 363 
 364 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
 365                                   const jbyte *buf, jsize bufLen))
 366   JNIWrapper("DefineClass");
 367 
 368 #ifndef USDT2
 369   DTRACE_PROBE5(hotspot_jni, DefineClass__entry,
 370     env, name, loaderRef, buf, bufLen);
 371 #else /* USDT2 */
 372   HOTSPOT_JNI_DEFINECLASS_ENTRY(
 373     env, (char*) name, loaderRef, (char*) buf, bufLen);
 374 #endif /* USDT2 */
 375   jclass cls = NULL;
 376   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 377 
 378   TempNewSymbol class_name = NULL;
 379   // Since exceptions can be thrown, class initialization can take place
 380   // if name is NULL no check for class name in .class stream has to be made.
 381   if (name != NULL) {
 382     const int str_len = (int)strlen(name);
 383     if (str_len > Symbol::max_length()) {
 384       // It's impossible to create this class;  the name cannot fit
 385       // into the constant pool.
 386       THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 387     }
 388     class_name = SymbolTable::new_symbol(name, CHECK_NULL);
 389   }
 390   ResourceMark rm(THREAD);
 391   ClassFileStream st((u1*) buf, bufLen, NULL);
 392   Handle class_loader (THREAD, JNIHandles::resolve(loaderRef));
 393 
 394   if (UsePerfData && !class_loader.is_null()) {
 395     // check whether the current caller thread holds the lock or not.
 396     // If not, increment the corresponding counter
 397     if (ObjectSynchronizer::
 398         query_lock_ownership((JavaThread*)THREAD, class_loader) !=
 399         ObjectSynchronizer::owner_self) {
 400       ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc();
 401     }
 402   }
 403   Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
 404                                                      Handle(), &st, true,
 405                                                      CHECK_NULL);
 406 
 407   if (TraceClassResolution && k != NULL) {
 408     trace_class_resolution(k);
 409   }
 410 
 411   cls = (jclass)JNIHandles::make_local(
 412     env, k->java_mirror());
 413   return cls;
 414 JNI_END
 415 
 416 
 417 
 418 static bool first_time_FindClass = true;
 419 
 420 #ifndef USDT2
 421 DT_RETURN_MARK_DECL(FindClass, jclass);
 422 #else /* USDT2 */
 423 DT_RETURN_MARK_DECL(FindClass, jclass
 424                     , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref));
 425 #endif /* USDT2 */
 426 
 427 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name))
 428   JNIWrapper("FindClass");
 429 #ifndef USDT2
 430   DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name);
 431 #else /* USDT2 */
 432   HOTSPOT_JNI_FINDCLASS_ENTRY(
 433                               env, (char *)name);
 434 #endif /* USDT2 */
 435 
 436   jclass result = NULL;
 437   DT_RETURN_MARK(FindClass, jclass, (const jclass&)result);
 438 
 439   // Remember if we are the first invocation of jni_FindClass
 440   bool first_time = first_time_FindClass;
 441   first_time_FindClass = false;
 442 
 443   // Sanity check the name:  it cannot be null or larger than the maximum size
 444   // name we can fit in the constant pool.
 445   if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
 446     THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
 447   }
 448 
 449   //%note jni_3
 450   Handle loader;
 451   Handle protection_domain;
 452   // Find calling class
 453   instanceKlassHandle k (THREAD, thread->security_get_caller_class(0));
 454   if (k.not_null()) {
 455     loader = Handle(THREAD, k->class_loader());
 456     // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed
 457     // in the correct class context.
 458     if (loader.is_null() &&
 459         k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) {
 460       JavaValue result(T_OBJECT);
 461       JavaCalls::call_static(&result, k,
 462                                       vmSymbols::getFromClass_name(),
 463                                       vmSymbols::void_class_signature(),
 464                                       thread);
 465       if (HAS_PENDING_EXCEPTION) {
 466         Handle ex(thread, thread->pending_exception());
 467         CLEAR_PENDING_EXCEPTION;
 468         THROW_HANDLE_0(ex);
 469       }
 470       oop mirror = (oop) result.get_jobject();
 471       loader = Handle(THREAD,
 472         InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->class_loader());
 473       protection_domain = Handle(THREAD,
 474         InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->protection_domain());
 475     }
 476   } else {
 477     // We call ClassLoader.getSystemClassLoader to obtain the system class loader.
 478     loader = Handle(THREAD, SystemDictionary::java_system_loader());
 479   }
 480 
 481   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
 482   result = find_class_from_class_loader(env, sym, true, loader,
 483                                         protection_domain, true, thread);
 484 
 485   if (TraceClassResolution && result != NULL) {
 486     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 487   }
 488 
 489   // If we were the first invocation of jni_FindClass, we enable compilation again
 490   // rather than just allowing invocation counter to overflow and decay.
 491   // Controlled by flag DelayCompilationDuringStartup.
 492   if (first_time && !CompileTheWorld)
 493     CompilationPolicy::completed_vm_startup();
 494 
 495   return result;
 496 JNI_END
 497 
 498 #ifndef USDT2
 499 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID);
 500 #else /* USDT2 */
 501 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
 502                     , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
 503 #endif /* USDT2 */
 504 
 505 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
 506   JNIWrapper("FromReflectedMethod");
 507 #ifndef USDT2
 508   DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method);
 509 #else /* USDT2 */
 510   HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(
 511                                         env, method);
 512 #endif /* USDT2 */
 513   jmethodID ret = NULL;
 514   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 515 
 516   // method is a handle to a java.lang.reflect.Method object
 517   oop reflected  = JNIHandles::resolve_non_null(method);
 518   oop mirror     = NULL;
 519   int slot       = 0;
 520 
 521   if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
 522     mirror = java_lang_reflect_Constructor::clazz(reflected);
 523     slot   = java_lang_reflect_Constructor::slot(reflected);
 524   } else {
 525     assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type");
 526     mirror = java_lang_reflect_Method::clazz(reflected);
 527     slot   = java_lang_reflect_Method::slot(reflected);
 528   }
 529   Klass* k     = java_lang_Class::as_Klass(mirror);
 530 
 531   KlassHandle k1(THREAD, k);
 532   // Make sure class is initialized before handing id's out to methods
 533   k1()->initialize(CHECK_NULL);
 534   Method* m = InstanceKlass::cast(k1())->method_with_idnum(slot);
 535   ret = m==NULL? NULL : m->jmethod_id();  // return NULL if reflected method deleted
 536   return ret;
 537 JNI_END
 538 
 539 #ifndef USDT2
 540 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID);
 541 #else /* USDT2 */
 542 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
 543                     , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
 544 #endif /* USDT2 */
 545 
 546 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
 547   JNIWrapper("FromReflectedField");
 548 #ifndef USDT2
 549   DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field);
 550 #else /* USDT2 */
 551   HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(
 552                                        env, field);
 553 #endif /* USDT2 */
 554   jfieldID ret = NULL;
 555   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 556 
 557   // field is a handle to a java.lang.reflect.Field object
 558   oop reflected   = JNIHandles::resolve_non_null(field);
 559   oop mirror      = java_lang_reflect_Field::clazz(reflected);
 560   Klass* k      = java_lang_Class::as_Klass(mirror);
 561   int slot        = java_lang_reflect_Field::slot(reflected);
 562   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 563 
 564   KlassHandle k1(THREAD, k);
 565   // Make sure class is initialized before handing id's out to fields
 566   k1()->initialize(CHECK_NULL);
 567 
 568   // First check if this is a static field
 569   if (modifiers & JVM_ACC_STATIC) {
 570     intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot );
 571     JNIid* id = InstanceKlass::cast(k1())->jni_id_for(offset);
 572     assert(id != NULL, "corrupt Field object");
 573     debug_only(id->set_is_static_field_id();)
 574     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 575     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 576     return ret;
 577   }
 578 
 579   // The slot is the index of the field description in the field-array
 580   // The jfieldID is the offset of the field within the object
 581   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 582   intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot );
 583   assert(InstanceKlass::cast(k1())->contains_field_offset(offset), "stay within object");
 584   ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset);
 585   return ret;
 586 JNI_END
 587 
 588 #ifndef USDT2
 589 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject);
 590 #else /* USDT2 */
 591 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
 592                     , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
 593 #endif /* USDT2 */
 594 
 595 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
 596   JNIWrapper("ToReflectedMethod");
 597 #ifndef USDT2
 598   DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic);
 599 #else /* USDT2 */
 600   HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(
 601                                       env, cls, (uintptr_t) method_id, isStatic);
 602 #endif /* USDT2 */
 603   jobject ret = NULL;
 604   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 605 
 606   methodHandle m (THREAD, Method::resolve_jmethod_id(method_id));
 607   assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match");
 608   oop reflection_method;
 609   if (m->is_initializer()) {
 610     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
 611   } else {
 612     reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL);
 613   }
 614   ret = JNIHandles::make_local(env, reflection_method);
 615   return ret;
 616 JNI_END
 617 
 618 #ifndef USDT2
 619 DT_RETURN_MARK_DECL(GetSuperclass, jclass);
 620 #else /* USDT2 */
 621 DT_RETURN_MARK_DECL(GetSuperclass, jclass
 622                     , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
 623 #endif /* USDT2 */
 624 
 625 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
 626   JNIWrapper("GetSuperclass");
 627 #ifndef USDT2
 628   DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub);
 629 #else /* USDT2 */
 630   HOTSPOT_JNI_GETSUPERCLASS_ENTRY(
 631                                   env, sub);
 632 #endif /* USDT2 */
 633   jclass obj = NULL;
 634   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 635 
 636   oop mirror = JNIHandles::resolve_non_null(sub);
 637   // primitive classes return NULL
 638   if (java_lang_Class::is_primitive(mirror)) return NULL;
 639 
 640   // Rules of Class.getSuperClass as implemented by KLass::java_super:
 641   // arrays return Object
 642   // interfaces return NULL
 643   // proper classes return Klass::super()
 644   Klass* k = java_lang_Class::as_Klass(mirror);
 645   if (k->is_interface()) return NULL;
 646 
 647   // return mirror for superclass
 648   Klass* super = k->java_super();
 649   // super2 is the value computed by the compiler's getSuperClass intrinsic:
 650   debug_only(Klass* super2 = ( k->oop_is_array()
 651                                  ? SystemDictionary::Object_klass()
 652                                  : k->super() ) );
 653   assert(super == super2,
 654          "java_super computation depends on interface, array, other super");
 655   obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(super->java_mirror());
 656   return obj;
 657 JNI_END
 658 
 659 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super))
 660   JNIWrapper("IsSubclassOf");
 661 #ifndef USDT2
 662   DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super);
 663 #else /* USDT2 */
 664   HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY(
 665                                      env, sub, super);
 666 #endif /* USDT2 */
 667   oop sub_mirror   = JNIHandles::resolve_non_null(sub);
 668   oop super_mirror = JNIHandles::resolve_non_null(super);
 669   if (java_lang_Class::is_primitive(sub_mirror) ||
 670       java_lang_Class::is_primitive(super_mirror)) {
 671     jboolean ret = (sub_mirror == super_mirror);
 672 #ifndef USDT2
 673     DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret);
 674 #else /* USDT2 */
 675     HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(
 676                                         ret);
 677 #endif /* USDT2 */
 678     return ret;
 679   }
 680   Klass* sub_klass   = java_lang_Class::as_Klass(sub_mirror);
 681   Klass* super_klass = java_lang_Class::as_Klass(super_mirror);
 682   assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom");
 683   jboolean ret = sub_klass->is_subtype_of(super_klass) ?
 684                    JNI_TRUE : JNI_FALSE;
 685 #ifndef USDT2
 686   DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret);
 687 #else /* USDT2 */
 688   HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(
 689                                       ret);
 690 #endif /* USDT2 */
 691   return ret;
 692 JNI_END
 693 
 694 #ifndef USDT2
 695 DT_RETURN_MARK_DECL(Throw, jint);
 696 #else /* USDT2 */
 697 DT_RETURN_MARK_DECL(Throw, jint
 698                     , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
 699 #endif /* USDT2 */
 700 
 701 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
 702   JNIWrapper("Throw");
 703 #ifndef USDT2
 704   DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj);
 705 #else /* USDT2 */
 706   HOTSPOT_JNI_THROW_ENTRY(
 707  env, obj);
 708 #endif /* USDT2 */
 709   jint ret = JNI_OK;
 710   DT_RETURN_MARK(Throw, jint, (const jint&)ret);
 711 
 712   THROW_OOP_(JNIHandles::resolve(obj), JNI_OK);
 713   ShouldNotReachHere();
 714   return 0; // Mute compiler.
 715 JNI_END
 716 
 717 #ifndef USDT2
 718 DT_RETURN_MARK_DECL(ThrowNew, jint);
 719 #else /* USDT2 */
 720 DT_RETURN_MARK_DECL(ThrowNew, jint
 721                     , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
 722 #endif /* USDT2 */
 723 
 724 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
 725   JNIWrapper("ThrowNew");
 726 #ifndef USDT2
 727   DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message);
 728 #else /* USDT2 */
 729   HOTSPOT_JNI_THROWNEW_ENTRY(
 730                              env, clazz, (char *) message);
 731 #endif /* USDT2 */
 732   jint ret = JNI_OK;
 733   DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
 734 
 735   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
 736   Symbol*  name = k->name();
 737   Handle class_loader (THREAD,  k->class_loader());
 738   Handle protection_domain (THREAD, k->protection_domain());
 739   THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK);
 740   ShouldNotReachHere();
 741   return 0; // Mute compiler.
 742 JNI_END
 743 
 744 
 745 // JNI functions only transform a pending async exception to a synchronous
 746 // exception in ExceptionOccurred and ExceptionCheck calls, since
 747 // delivering an async exception in other places won't change the native
 748 // code's control flow and would be harmful when native code further calls
 749 // JNI functions with a pending exception. Async exception is also checked
 750 // during the call, so ExceptionOccurred/ExceptionCheck won't return
 751 // false but deliver the async exception at the very end during
 752 // state transition.
 753 
 754 static void jni_check_async_exceptions(JavaThread *thread) {
 755   assert(thread == Thread::current(), "must be itself");
 756   thread->check_and_handle_async_exceptions();
 757 }
 758 
 759 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
 760   JNIWrapper("ExceptionOccurred");
 761 #ifndef USDT2
 762   DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env);
 763 #else /* USDT2 */
 764   HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY(
 765                                       env);
 766 #endif /* USDT2 */
 767   jni_check_async_exceptions(thread);
 768   oop exception = thread->pending_exception();
 769   jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception);
 770 #ifndef USDT2
 771   DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret);
 772 #else /* USDT2 */
 773   HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN(
 774                                        ret);
 775 #endif /* USDT2 */
 776   return ret;
 777 JNI_END
 778 
 779 
 780 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env))
 781   JNIWrapper("ExceptionDescribe");
 782 #ifndef USDT2
 783   DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env);
 784 #else /* USDT2 */
 785   HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY(
 786                                       env);
 787 #endif /* USDT2 */
 788   if (thread->has_pending_exception()) {
 789     Handle ex(thread, thread->pending_exception());
 790     thread->clear_pending_exception();
 791     if (ex->is_a(SystemDictionary::ThreadDeath_klass())) {
 792       // Don't print anything if we are being killed.
 793     } else {
 794       jio_fprintf(defaultStream::error_stream(), "Exception ");
 795       if (thread != NULL && thread->threadObj() != NULL) {
 796         ResourceMark rm(THREAD);
 797         jio_fprintf(defaultStream::error_stream(),
 798         "in thread \"%s\" ", thread->get_thread_name());
 799       }
 800       if (ex->is_a(SystemDictionary::Throwable_klass())) {
 801         JavaValue result(T_VOID);
 802         JavaCalls::call_virtual(&result,
 803                                 ex,
 804                                 KlassHandle(THREAD,
 805                                   SystemDictionary::Throwable_klass()),
 806                                 vmSymbols::printStackTrace_name(),
 807                                 vmSymbols::void_method_signature(),
 808                                 THREAD);
 809         // If an exception is thrown in the call it gets thrown away. Not much
 810         // we can do with it. The native code that calls this, does not check
 811         // for the exception - hence, it might still be in the thread when DestroyVM gets
 812         // called, potentially causing a few asserts to trigger - since no pending exception
 813         // is expected.
 814         CLEAR_PENDING_EXCEPTION;
 815       } else {
 816         ResourceMark rm(THREAD);
 817         jio_fprintf(defaultStream::error_stream(),
 818         ". Uncaught exception of type %s.",
 819         ex->klass()->external_name());
 820       }
 821     }
 822   }
 823 #ifndef USDT2
 824   DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return);
 825 #else /* USDT2 */
 826   HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN(
 827                                        );
 828 #endif /* USDT2 */
 829 JNI_END
 830 
 831 
 832 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env))
 833   JNIWrapper("ExceptionClear");
 834 #ifndef USDT2
 835   DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env);
 836 #else /* USDT2 */
 837   HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY(
 838                                    env);
 839 #endif /* USDT2 */
 840 
 841   // The jni code might be using this API to clear java thrown exception.
 842   // So just mark jvmti thread exception state as exception caught.
 843   JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state();
 844   if (state != NULL && state->is_exception_detected()) {
 845     state->set_exception_caught();
 846   }
 847   thread->clear_pending_exception();
 848 #ifndef USDT2
 849   DTRACE_PROBE(hotspot_jni, ExceptionClear__return);
 850 #else /* USDT2 */
 851   HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN(
 852                                     );
 853 #endif /* USDT2 */
 854 JNI_END
 855 
 856 
 857 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg))
 858   JNIWrapper("FatalError");
 859 #ifndef USDT2
 860   DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg);
 861 #else /* USDT2 */
 862   HOTSPOT_JNI_FATALERROR_ENTRY(
 863                                env, (char *) msg);
 864 #endif /* USDT2 */
 865   tty->print_cr("FATAL ERROR in native method: %s", msg);
 866   thread->print_stack();
 867   os::abort(); // Dump core and abort
 868 JNI_END
 869 
 870 
 871 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity))
 872   JNIWrapper("PushLocalFrame");
 873 #ifndef USDT2
 874   DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity);
 875 #else /* USDT2 */
 876   HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(
 877                                    env, capacity);
 878 #endif /* USDT2 */
 879   //%note jni_11
 880   if (capacity < 0 ||
 881       ((MaxJNILocalCapacity > 0) && (capacity > MaxJNILocalCapacity))) {
 882 #ifndef USDT2
 883     DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR);
 884 #else /* USDT2 */
 885     HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(
 886                                       (uint32_t)JNI_ERR);
 887 #endif /* USDT2 */
 888     return JNI_ERR;
 889   }
 890   JNIHandleBlock* old_handles = thread->active_handles();
 891   JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
 892   assert(new_handles != NULL, "should not be NULL");
 893   new_handles->set_pop_frame_link(old_handles);
 894   thread->set_active_handles(new_handles);
 895   jint ret = JNI_OK;
 896 #ifndef USDT2
 897   DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret);
 898 #else /* USDT2 */
 899   HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(
 900                                     ret);
 901 #endif /* USDT2 */
 902   return ret;
 903 JNI_END
 904 
 905 
 906 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result))
 907   JNIWrapper("PopLocalFrame");
 908 #ifndef USDT2
 909   DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result);
 910 #else /* USDT2 */
 911   HOTSPOT_JNI_POPLOCALFRAME_ENTRY(
 912                                   env, result);
 913 #endif /* USDT2 */
 914   //%note jni_11
 915   Handle result_handle(thread, JNIHandles::resolve(result));
 916   JNIHandleBlock* old_handles = thread->active_handles();
 917   JNIHandleBlock* new_handles = old_handles->pop_frame_link();
 918   if (new_handles != NULL) {
 919     // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL.
 920     // This way code will still work if PopLocalFrame is called without a corresponding
 921     // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise
 922     // the release_block call will release the blocks.
 923     thread->set_active_handles(new_handles);
 924     old_handles->set_pop_frame_link(NULL);              // clear link we won't release new_handles below
 925     JNIHandleBlock::release_block(old_handles, thread); // may block
 926     result = JNIHandles::make_local(thread, result_handle());
 927   }
 928 #ifndef USDT2
 929   DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result);
 930 #else /* USDT2 */
 931   HOTSPOT_JNI_POPLOCALFRAME_RETURN(
 932                                    result);
 933 #endif /* USDT2 */
 934   return result;
 935 JNI_END
 936 
 937 
 938 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref))
 939   JNIWrapper("NewGlobalRef");
 940 #ifndef USDT2
 941   DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref);
 942 #else /* USDT2 */
 943   HOTSPOT_JNI_NEWGLOBALREF_ENTRY(
 944                                  env, ref);
 945 #endif /* USDT2 */
 946   Handle ref_handle(thread, JNIHandles::resolve(ref));
 947   jobject ret = JNIHandles::make_global(ref_handle);
 948 #ifndef USDT2
 949   DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret);
 950 #else /* USDT2 */
 951   HOTSPOT_JNI_NEWGLOBALREF_RETURN(
 952                                   ret);
 953 #endif /* USDT2 */
 954   return ret;
 955 JNI_END
 956 
 957 // Must be JNI_ENTRY (with HandleMark)
 958 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref))
 959   JNIWrapper("DeleteGlobalRef");
 960 #ifndef USDT2
 961   DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref);
 962 #else /* USDT2 */
 963   HOTSPOT_JNI_DELETEGLOBALREF_ENTRY(
 964                                     env, ref);
 965 #endif /* USDT2 */
 966   JNIHandles::destroy_global(ref);
 967 #ifndef USDT2
 968   DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return);
 969 #else /* USDT2 */
 970   HOTSPOT_JNI_DELETEGLOBALREF_RETURN(
 971                                      );
 972 #endif /* USDT2 */
 973 JNI_END
 974 
 975 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj))
 976   JNIWrapper("DeleteLocalRef");
 977 #ifndef USDT2
 978   DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj);
 979 #else /* USDT2 */
 980   HOTSPOT_JNI_DELETELOCALREF_ENTRY(
 981                                    env, obj);
 982 #endif /* USDT2 */
 983   JNIHandles::destroy_local(obj);
 984 #ifndef USDT2
 985   DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return);
 986 #else /* USDT2 */
 987   HOTSPOT_JNI_DELETELOCALREF_RETURN(
 988                                     );
 989 #endif /* USDT2 */
 990 JNI_END
 991 
 992 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2))
 993   JNIWrapper("IsSameObject");
 994 #ifndef USDT2
 995   DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2);
 996 #else /* USDT2 */
 997   HOTSPOT_JNI_ISSAMEOBJECT_ENTRY(
 998                                  env, r1, r2);
 999 #endif /* USDT2 */
1000   oop a = JNIHandles::resolve(r1);
1001   oop b = JNIHandles::resolve(r2);
1002   jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE;
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   jchar* ret;
4332   if (!UseShenandoahGC) {
4333     GC_locker::lock_critical(thread);
4334     if (isCopy != NULL) {
4335       *isCopy = JNI_FALSE;
4336     }
4337     oop s = JNIHandles::resolve_non_null(string);
4338     int s_len = java_lang_String::length(s);
4339     typeArrayOop s_value = java_lang_String::value(s);
4340     int s_offset = java_lang_String::offset(s);
4341     if (s_len > 0) {
4342       ret = s_value->char_at_addr(s_offset);
4343     } else {
4344       ret = (jchar*) s_value->base(T_CHAR);
4345     }
4346   }
4347 #if INCLUDE_ALL_GCS
4348   else {
4349     assert(UseShenandoahGC, "This path should only be taken with Shenandoah");
4350     oop s = JNIHandles::resolve_non_null(string);
4351     if (ShenandoahStringDedup::is_enabled()) {
4352       typeArrayOop s_value = java_lang_String::value(s);
4353       int s_len = java_lang_String::length(s);
4354       ret = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
4355       /* JNI Specification states return NULL on OOM */
4356       if (ret != NULL) {
4357         memcpy(ret, s_value->char_at_addr(0), s_len * sizeof(jchar));
4358         ret[s_len] = 0;
4359       }
4360       if (isCopy != NULL) *isCopy = JNI_TRUE;
4361     } else {
4362       typeArrayOop s_value = java_lang_String::value(s);
4363       s_value = (typeArrayOop) Universe::heap()->pin_object(thread, s_value);
4364       ret = (jchar *) s_value->base(T_CHAR);
4365       if (isCopy != NULL) *isCopy = JNI_FALSE;
4366     }
4367   }
4368 #else
4369   else {
4370     ShouldNotReachHere();
4371   }
4372 #endif
4373 #ifndef USDT2
4374   DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret);
4375 #else /* USDT2 */
4376  HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN(
4377                                       (uint16_t *) ret);
4378 #endif /* USDT2 */
4379   return ret;
4380 JNI_END
4381 
4382 
4383 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
4384   JNIWrapper("ReleaseStringCritical");
4385 #ifndef USDT2
4386   DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars);
4387 #else /* USDT2 */
4388   HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(
4389                                           env, str, (uint16_t *) chars);
4390 #endif /* USDT2 */
4391   if (!UseShenandoahGC) {
4392     // The str and chars arguments are ignored
4393     GC_locker::unlock_critical(thread);
4394   }
4395 #if INCLUDE_ALL_GCS
4396   else if (ShenandoahStringDedup::is_enabled()) {
4397     assert(UseShenandoahGC, "This path should only be taken with Shenandoah");
4398     // For copied string value, free jchar array allocated by earlier call to GetStringCritical.
4399     // This assumes that ReleaseStringCritical bookends GetStringCritical.
4400     FREE_C_HEAP_ARRAY(jchar, chars, mtInternal);
4401   } else {
4402     assert(UseShenandoahGC, "This path should only be taken with Shenandoah");
4403     oop s = JNIHandles::resolve_non_null(str);
4404     // For not copied string value, drop the associated gc-locker/pin.
4405     typeArrayOop s_value = java_lang_String::value(s);
4406     Universe::heap()->unpin_object(thread, s_value);
4407   }
4408 #else
4409   else {
4410     ShouldNotReachHere();
4411   }
4412 #endif
4413 #ifndef USDT2
4414   DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return);
4415 #else /* USDT2 */
4416 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN(
4417 );
4418 #endif /* USDT2 */
4419 JNI_END
4420 
4421 
4422 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
4423   JNIWrapper("jni_NewWeakGlobalRef");
4424 #ifndef USDT2
4425   DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref);
4426 #else /* USDT2 */
4427  HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(
4428                                     env, ref);
4429 #endif /* USDT2 */
4430   Handle ref_handle(thread, JNIHandles::resolve(ref));
4431   jweak ret = JNIHandles::make_weak_global(ref_handle);
4432 #ifndef USDT2
4433   DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret);
4434 #else /* USDT2 */
4435  HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(
4436                                      ret);
4437 #endif /* USDT2 */
4438   return ret;
4439 JNI_END
4440 
4441 // Must be JNI_ENTRY (with HandleMark)
4442 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref))
4443   JNIWrapper("jni_DeleteWeakGlobalRef");
4444 #ifndef USDT2
4445   DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref);
4446 #else /* USDT2 */
4447   HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY(
4448                                         env, ref);
4449 #endif /* USDT2 */
4450   JNIHandles::destroy_weak_global(ref);
4451 #ifndef USDT2
4452   DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return);
4453 #else /* USDT2 */
4454   HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN(
4455                                          );
4456 #endif /* USDT2 */
4457 JNI_END
4458 
4459 
4460 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env))
4461   JNIWrapper("jni_ExceptionCheck");
4462 #ifndef USDT2
4463   DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env);
4464 #else /* USDT2 */
4465  HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY(
4466                                   env);
4467 #endif /* USDT2 */
4468   jni_check_async_exceptions(thread);
4469   jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE;
4470 #ifndef USDT2
4471   DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret);
4472 #else /* USDT2 */
4473  HOTSPOT_JNI_EXCEPTIONCHECK_RETURN(
4474                                    ret);
4475 #endif /* USDT2 */
4476   return ret;
4477 JNI_END
4478 
4479 
4480 // Initialization state for three routines below relating to
4481 // java.nio.DirectBuffers
4482 static          jint directBufferSupportInitializeStarted = 0;
4483 static volatile jint directBufferSupportInitializeEnded   = 0;
4484 static volatile jint directBufferSupportInitializeFailed  = 0;
4485 static jclass    bufferClass                 = NULL;
4486 static jclass    directBufferClass           = NULL;
4487 static jclass    directByteBufferClass       = NULL;
4488 static jmethodID directByteBufferConstructor = NULL;
4489 static jfieldID  directBufferAddressField    = NULL;
4490 static jfieldID  bufferCapacityField         = NULL;
4491 
4492 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) {
4493   Handle loader;            // null (bootstrap) loader
4494   Handle protection_domain; // null protection domain
4495 
4496   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
4497   jclass result =  find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL);
4498 
4499   if (TraceClassResolution && result != NULL) {
4500     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
4501   }
4502   return result;
4503 }
4504 
4505 // These lookups are done with the NULL (bootstrap) ClassLoader to
4506 // circumvent any security checks that would be done by jni_FindClass.
4507 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env))
4508 {
4509   if ((bufferClass           = lookupOne(env, "java/nio/Buffer", thread))           == NULL) { return false; }
4510   if ((directBufferClass     = lookupOne(env, "sun/nio/ch/DirectBuffer", thread))   == NULL) { return false; }
4511   if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; }
4512   return true;
4513 }
4514 JNI_END
4515 
4516 
4517 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
4518   if (directBufferSupportInitializeFailed) {
4519     return false;
4520   }
4521 
4522   if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) {
4523     if (!lookupDirectBufferClasses(env)) {
4524       directBufferSupportInitializeFailed = 1;
4525       return false;
4526     }
4527 
4528     // Make global references for these
4529     bufferClass           = (jclass) env->NewGlobalRef(bufferClass);
4530     directBufferClass     = (jclass) env->NewGlobalRef(directBufferClass);
4531     directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
4532 
4533     // Get needed field and method IDs
4534     directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
4535     if (env->ExceptionCheck()) {
4536       env->ExceptionClear();
4537       directBufferSupportInitializeFailed = 1;
4538       return false;
4539     }
4540     directBufferAddressField    = env->GetFieldID(bufferClass, "address", "J");
4541     if (env->ExceptionCheck()) {
4542       env->ExceptionClear();
4543       directBufferSupportInitializeFailed = 1;
4544       return false;
4545     }
4546     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
4547     if (env->ExceptionCheck()) {
4548       env->ExceptionClear();
4549       directBufferSupportInitializeFailed = 1;
4550       return false;
4551     }
4552 
4553     if ((directByteBufferConstructor == NULL) ||
4554         (directBufferAddressField    == NULL) ||
4555         (bufferCapacityField         == NULL)) {
4556       directBufferSupportInitializeFailed = 1;
4557       return false;
4558     }
4559 
4560     directBufferSupportInitializeEnded = 1;
4561   } else {
4562     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
4563       // Set state as yield_all can call os:sleep. On Solaris, yield_all calls
4564       // os::sleep which requires the VM state transition. On other platforms, it
4565       // is not necessary. The following call to change the VM state is purposely
4566       // put inside the loop to avoid potential deadlock when multiple threads
4567       // try to call this method. See 6791815 for more details.
4568       ThreadInVMfromNative tivn(thread);
4569       os::yield_all();
4570     }
4571   }
4572 
4573   return !directBufferSupportInitializeFailed;
4574 }
4575 
4576 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
4577 {
4578   // thread_from_jni_environment() will block if VM is gone.
4579   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
4580 
4581   JNIWrapper("jni_NewDirectByteBuffer");
4582 #ifndef USDT2
4583   DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity);
4584 #else /* USDT2 */
4585  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(
4586                                        env, address, capacity);
4587 #endif /* USDT2 */
4588 
4589   if (!directBufferSupportInitializeEnded) {
4590     if (!initializeDirectBufferSupport(env, thread)) {
4591 #ifndef USDT2
4592       DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL);
4593 #else /* USDT2 */
4594       HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(
4595                                              NULL);
4596 #endif /* USDT2 */
4597       return NULL;
4598     }
4599   }
4600 
4601   // Being paranoid about accidental sign extension on address
4602   jlong addr = (jlong) ((uintptr_t) address);
4603   // NOTE that package-private DirectByteBuffer constructor currently
4604   // takes int capacity
4605   jint  cap  = (jint)  capacity;
4606   jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap);
4607 #ifndef USDT2
4608   DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret);
4609 #else /* USDT2 */
4610   HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(
4611                                          ret);
4612 #endif /* USDT2 */
4613   return ret;
4614 }
4615 
4616 #ifndef USDT2
4617 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*);
4618 #else /* USDT2 */
4619 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*
4620                     , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref));
4621 #endif /* USDT2 */
4622 
4623 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
4624 {
4625   // thread_from_jni_environment() will block if VM is gone.
4626   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
4627 
4628   JNIWrapper("jni_GetDirectBufferAddress");
4629 #ifndef USDT2
4630   DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf);
4631 #else /* USDT2 */
4632   HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY(
4633                                            env, buf);
4634 #endif /* USDT2 */
4635   void* ret = NULL;
4636   DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret);
4637 
4638   if (!directBufferSupportInitializeEnded) {
4639     if (!initializeDirectBufferSupport(env, thread)) {
4640       return 0;
4641     }
4642   }
4643 
4644   if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) {
4645     return 0;
4646   }
4647 
4648   ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField);
4649   return ret;
4650 }
4651 
4652 #ifndef USDT2
4653 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong);
4654 #else /* USDT2 */
4655 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong
4656                     , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref));
4657 #endif /* USDT2 */
4658 
4659 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf)
4660 {
4661   // thread_from_jni_environment() will block if VM is gone.
4662   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
4663 
4664   JNIWrapper("jni_GetDirectBufferCapacity");
4665 #ifndef USDT2
4666   DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf);
4667 #else /* USDT2 */
4668   HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY(
4669                                             env, buf);
4670 #endif /* USDT2 */
4671   jlong ret = -1;
4672   DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret);
4673 
4674   if (!directBufferSupportInitializeEnded) {
4675     if (!initializeDirectBufferSupport(env, thread)) {
4676       ret = 0;
4677       return ret;
4678     }
4679   }
4680 
4681   if (buf == NULL) {
4682     return -1;
4683   }
4684 
4685   if (!env->IsInstanceOf(buf, directBufferClass)) {
4686     return -1;
4687   }
4688 
4689   // NOTE that capacity is currently an int in the implementation
4690   ret = env->GetIntField(buf, bufferCapacityField);
4691   return ret;
4692 }
4693 
4694 
4695 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
4696   JNIWrapper("GetVersion");
4697 #ifndef USDT2
4698   DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env);
4699 #else /* USDT2 */
4700   HOTSPOT_JNI_GETVERSION_ENTRY(
4701                                env);
4702 #endif /* USDT2 */
4703 #ifndef USDT2
4704   DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion);
4705 #else /* USDT2 */
4706   HOTSPOT_JNI_GETVERSION_RETURN(
4707                                 CurrentVersion);
4708 #endif /* USDT2 */
4709   return CurrentVersion;
4710 JNI_END
4711 
4712 extern struct JavaVM_ main_vm;
4713 
4714 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
4715   JNIWrapper("jni_GetJavaVM");
4716 #ifndef USDT2
4717   DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm);
4718 #else /* USDT2 */
4719   HOTSPOT_JNI_GETJAVAVM_ENTRY(
4720                               env, (void **) vm);
4721 #endif /* USDT2 */
4722   *vm  = (JavaVM *)(&main_vm);
4723 #ifndef USDT2
4724   DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK);
4725 #else /* USDT2 */
4726   HOTSPOT_JNI_GETJAVAVM_RETURN(
4727                                JNI_OK);
4728 #endif /* USDT2 */
4729   return JNI_OK;
4730 JNI_END
4731 
4732 // Structure containing all jni functions
4733 struct JNINativeInterface_ jni_NativeInterface = {
4734     NULL,
4735     NULL,
4736     NULL,
4737 
4738     NULL,
4739 
4740     jni_GetVersion,
4741 
4742     jni_DefineClass,
4743     jni_FindClass,
4744 
4745     jni_FromReflectedMethod,
4746     jni_FromReflectedField,
4747 
4748     jni_ToReflectedMethod,
4749 
4750     jni_GetSuperclass,
4751     jni_IsAssignableFrom,
4752 
4753     jni_ToReflectedField,
4754 
4755     jni_Throw,
4756     jni_ThrowNew,
4757     jni_ExceptionOccurred,
4758     jni_ExceptionDescribe,
4759     jni_ExceptionClear,
4760     jni_FatalError,
4761 
4762     jni_PushLocalFrame,
4763     jni_PopLocalFrame,
4764 
4765     jni_NewGlobalRef,
4766     jni_DeleteGlobalRef,
4767     jni_DeleteLocalRef,
4768     jni_IsSameObject,
4769 
4770     jni_NewLocalRef,
4771     jni_EnsureLocalCapacity,
4772 
4773     jni_AllocObject,
4774     jni_NewObject,
4775     jni_NewObjectV,
4776     jni_NewObjectA,
4777 
4778     jni_GetObjectClass,
4779     jni_IsInstanceOf,
4780 
4781     jni_GetMethodID,
4782 
4783     jni_CallObjectMethod,
4784     jni_CallObjectMethodV,
4785     jni_CallObjectMethodA,
4786     jni_CallBooleanMethod,
4787     jni_CallBooleanMethodV,
4788     jni_CallBooleanMethodA,
4789     jni_CallByteMethod,
4790     jni_CallByteMethodV,
4791     jni_CallByteMethodA,
4792     jni_CallCharMethod,
4793     jni_CallCharMethodV,
4794     jni_CallCharMethodA,
4795     jni_CallShortMethod,
4796     jni_CallShortMethodV,
4797     jni_CallShortMethodA,
4798     jni_CallIntMethod,
4799     jni_CallIntMethodV,
4800     jni_CallIntMethodA,
4801     jni_CallLongMethod,
4802     jni_CallLongMethodV,
4803     jni_CallLongMethodA,
4804     jni_CallFloatMethod,
4805     jni_CallFloatMethodV,
4806     jni_CallFloatMethodA,
4807     jni_CallDoubleMethod,
4808     jni_CallDoubleMethodV,
4809     jni_CallDoubleMethodA,
4810     jni_CallVoidMethod,
4811     jni_CallVoidMethodV,
4812     jni_CallVoidMethodA,
4813 
4814     jni_CallNonvirtualObjectMethod,
4815     jni_CallNonvirtualObjectMethodV,
4816     jni_CallNonvirtualObjectMethodA,
4817     jni_CallNonvirtualBooleanMethod,
4818     jni_CallNonvirtualBooleanMethodV,
4819     jni_CallNonvirtualBooleanMethodA,
4820     jni_CallNonvirtualByteMethod,
4821     jni_CallNonvirtualByteMethodV,
4822     jni_CallNonvirtualByteMethodA,
4823     jni_CallNonvirtualCharMethod,
4824     jni_CallNonvirtualCharMethodV,
4825     jni_CallNonvirtualCharMethodA,
4826     jni_CallNonvirtualShortMethod,
4827     jni_CallNonvirtualShortMethodV,
4828     jni_CallNonvirtualShortMethodA,
4829     jni_CallNonvirtualIntMethod,
4830     jni_CallNonvirtualIntMethodV,
4831     jni_CallNonvirtualIntMethodA,
4832     jni_CallNonvirtualLongMethod,
4833     jni_CallNonvirtualLongMethodV,
4834     jni_CallNonvirtualLongMethodA,
4835     jni_CallNonvirtualFloatMethod,
4836     jni_CallNonvirtualFloatMethodV,
4837     jni_CallNonvirtualFloatMethodA,
4838     jni_CallNonvirtualDoubleMethod,
4839     jni_CallNonvirtualDoubleMethodV,
4840     jni_CallNonvirtualDoubleMethodA,
4841     jni_CallNonvirtualVoidMethod,
4842     jni_CallNonvirtualVoidMethodV,
4843     jni_CallNonvirtualVoidMethodA,
4844 
4845     jni_GetFieldID,
4846 
4847     jni_GetObjectField,
4848     jni_GetBooleanField,
4849     jni_GetByteField,
4850     jni_GetCharField,
4851     jni_GetShortField,
4852     jni_GetIntField,
4853     jni_GetLongField,
4854     jni_GetFloatField,
4855     jni_GetDoubleField,
4856 
4857     jni_SetObjectField,
4858     jni_SetBooleanField,
4859     jni_SetByteField,
4860     jni_SetCharField,
4861     jni_SetShortField,
4862     jni_SetIntField,
4863     jni_SetLongField,
4864     jni_SetFloatField,
4865     jni_SetDoubleField,
4866 
4867     jni_GetStaticMethodID,
4868 
4869     jni_CallStaticObjectMethod,
4870     jni_CallStaticObjectMethodV,
4871     jni_CallStaticObjectMethodA,
4872     jni_CallStaticBooleanMethod,
4873     jni_CallStaticBooleanMethodV,
4874     jni_CallStaticBooleanMethodA,
4875     jni_CallStaticByteMethod,
4876     jni_CallStaticByteMethodV,
4877     jni_CallStaticByteMethodA,
4878     jni_CallStaticCharMethod,
4879     jni_CallStaticCharMethodV,
4880     jni_CallStaticCharMethodA,
4881     jni_CallStaticShortMethod,
4882     jni_CallStaticShortMethodV,
4883     jni_CallStaticShortMethodA,
4884     jni_CallStaticIntMethod,
4885     jni_CallStaticIntMethodV,
4886     jni_CallStaticIntMethodA,
4887     jni_CallStaticLongMethod,
4888     jni_CallStaticLongMethodV,
4889     jni_CallStaticLongMethodA,
4890     jni_CallStaticFloatMethod,
4891     jni_CallStaticFloatMethodV,
4892     jni_CallStaticFloatMethodA,
4893     jni_CallStaticDoubleMethod,
4894     jni_CallStaticDoubleMethodV,
4895     jni_CallStaticDoubleMethodA,
4896     jni_CallStaticVoidMethod,
4897     jni_CallStaticVoidMethodV,
4898     jni_CallStaticVoidMethodA,
4899 
4900     jni_GetStaticFieldID,
4901 
4902     jni_GetStaticObjectField,
4903     jni_GetStaticBooleanField,
4904     jni_GetStaticByteField,
4905     jni_GetStaticCharField,
4906     jni_GetStaticShortField,
4907     jni_GetStaticIntField,
4908     jni_GetStaticLongField,
4909     jni_GetStaticFloatField,
4910     jni_GetStaticDoubleField,
4911 
4912     jni_SetStaticObjectField,
4913     jni_SetStaticBooleanField,
4914     jni_SetStaticByteField,
4915     jni_SetStaticCharField,
4916     jni_SetStaticShortField,
4917     jni_SetStaticIntField,
4918     jni_SetStaticLongField,
4919     jni_SetStaticFloatField,
4920     jni_SetStaticDoubleField,
4921 
4922     jni_NewString,
4923     jni_GetStringLength,
4924     jni_GetStringChars,
4925     jni_ReleaseStringChars,
4926 
4927     jni_NewStringUTF,
4928     jni_GetStringUTFLength,
4929     jni_GetStringUTFChars,
4930     jni_ReleaseStringUTFChars,
4931 
4932     jni_GetArrayLength,
4933 
4934     jni_NewObjectArray,
4935     jni_GetObjectArrayElement,
4936     jni_SetObjectArrayElement,
4937 
4938     jni_NewBooleanArray,
4939     jni_NewByteArray,
4940     jni_NewCharArray,
4941     jni_NewShortArray,
4942     jni_NewIntArray,
4943     jni_NewLongArray,
4944     jni_NewFloatArray,
4945     jni_NewDoubleArray,
4946 
4947     jni_GetBooleanArrayElements,
4948     jni_GetByteArrayElements,
4949     jni_GetCharArrayElements,
4950     jni_GetShortArrayElements,
4951     jni_GetIntArrayElements,
4952     jni_GetLongArrayElements,
4953     jni_GetFloatArrayElements,
4954     jni_GetDoubleArrayElements,
4955 
4956     jni_ReleaseBooleanArrayElements,
4957     jni_ReleaseByteArrayElements,
4958     jni_ReleaseCharArrayElements,
4959     jni_ReleaseShortArrayElements,
4960     jni_ReleaseIntArrayElements,
4961     jni_ReleaseLongArrayElements,
4962     jni_ReleaseFloatArrayElements,
4963     jni_ReleaseDoubleArrayElements,
4964 
4965     jni_GetBooleanArrayRegion,
4966     jni_GetByteArrayRegion,
4967     jni_GetCharArrayRegion,
4968     jni_GetShortArrayRegion,
4969     jni_GetIntArrayRegion,
4970     jni_GetLongArrayRegion,
4971     jni_GetFloatArrayRegion,
4972     jni_GetDoubleArrayRegion,
4973 
4974     jni_SetBooleanArrayRegion,
4975     jni_SetByteArrayRegion,
4976     jni_SetCharArrayRegion,
4977     jni_SetShortArrayRegion,
4978     jni_SetIntArrayRegion,
4979     jni_SetLongArrayRegion,
4980     jni_SetFloatArrayRegion,
4981     jni_SetDoubleArrayRegion,
4982 
4983     jni_RegisterNatives,
4984     jni_UnregisterNatives,
4985 
4986     jni_MonitorEnter,
4987     jni_MonitorExit,
4988 
4989     jni_GetJavaVM,
4990 
4991     jni_GetStringRegion,
4992     jni_GetStringUTFRegion,
4993 
4994     jni_GetPrimitiveArrayCritical,
4995     jni_ReleasePrimitiveArrayCritical,
4996 
4997     jni_GetStringCritical,
4998     jni_ReleaseStringCritical,
4999 
5000     jni_NewWeakGlobalRef,
5001     jni_DeleteWeakGlobalRef,
5002 
5003     jni_ExceptionCheck,
5004 
5005     jni_NewDirectByteBuffer,
5006     jni_GetDirectBufferAddress,
5007     jni_GetDirectBufferCapacity,
5008 
5009     // New 1_6 features
5010 
5011     jni_GetObjectRefType
5012 };
5013 
5014 
5015 // For jvmti use to modify jni function table.
5016 // Java threads in native contiues to run until it is transitioned
5017 // to VM at safepoint. Before the transition or before it is blocked
5018 // for safepoint it may access jni function table. VM could crash if
5019 // any java thread access the jni function table in the middle of memcpy.
5020 // To avoid this each function pointers are copied automically.
5021 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) {
5022   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
5023   intptr_t *a = (intptr_t *) jni_functions();
5024   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
5025   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
5026     Atomic::store_ptr(*b++, a++);
5027   }
5028 }
5029 
5030 void quicken_jni_functions() {
5031   // Replace Get<Primitive>Field with fast versions
5032   if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access()
5033       && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls
5034 #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2)
5035       // windows x86 currently needs SEH wrapper and the gain of the fast
5036       // versions currently isn't certain for server vm on uniprocessor.
5037       && os::is_MP()
5038 #endif
5039   ) {
5040     address func;
5041     func = JNI_FastGetField::generate_fast_get_boolean_field();
5042     if (func != (address)-1) {
5043       jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func;
5044     }
5045     func = JNI_FastGetField::generate_fast_get_byte_field();
5046     if (func != (address)-1) {
5047       jni_NativeInterface.GetByteField = (GetByteField_t)func;
5048     }
5049     func = JNI_FastGetField::generate_fast_get_char_field();
5050     if (func != (address)-1) {
5051       jni_NativeInterface.GetCharField = (GetCharField_t)func;
5052     }
5053     func = JNI_FastGetField::generate_fast_get_short_field();
5054     if (func != (address)-1) {
5055       jni_NativeInterface.GetShortField = (GetShortField_t)func;
5056     }
5057     func = JNI_FastGetField::generate_fast_get_int_field();
5058     if (func != (address)-1) {
5059       jni_NativeInterface.GetIntField = (GetIntField_t)func;
5060     }
5061     func = JNI_FastGetField::generate_fast_get_long_field();
5062     if (func != (address)-1) {
5063       jni_NativeInterface.GetLongField = (GetLongField_t)func;
5064     }
5065     func = JNI_FastGetField::generate_fast_get_float_field();
5066     if (func != (address)-1) {
5067       jni_NativeInterface.GetFloatField = (GetFloatField_t)func;
5068     }
5069     func = JNI_FastGetField::generate_fast_get_double_field();
5070     if (func != (address)-1) {
5071       jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func;
5072     }
5073   }
5074 }
5075 
5076 // Returns the function structure
5077 struct JNINativeInterface_* jni_functions() {
5078 #if INCLUDE_JNI_CHECK
5079   if (CheckJNICalls) return jni_functions_check();
5080 #endif // INCLUDE_JNI_CHECK
5081   return &jni_NativeInterface;
5082 }
5083 
5084 // Returns the function structure
5085 struct JNINativeInterface_* jni_functions_nocheck() {
5086   return &jni_NativeInterface;
5087 }
5088 
5089 static void post_thread_start_event(const JavaThread* jt) {
5090   assert(jt != NULL, "invariant");
5091   EventThreadStart event;
5092   if (event.should_commit()) {
5093     event.set_thread(JFR_THREAD_ID(jt));
5094     event.set_parentThread((traceid)0);
5095 #if INCLUDE_JFR
5096     if (EventThreadStart::is_stacktrace_enabled()) {
5097       jt->jfr_thread_local()->set_cached_stack_trace_id((traceid)0);
5098       event.commit();
5099       jt->jfr_thread_local()->clear_cached_stack_trace();
5100     } else
5101 #endif
5102     {
5103       event.commit();
5104     }
5105   }
5106 }
5107 
5108 // Invocation API
5109 
5110 
5111 // Forward declaration
5112 extern const struct JNIInvokeInterface_ jni_InvokeInterface;
5113 
5114 // Global invocation API vars
5115 volatile jint vm_created = 0;
5116 // Indicate whether it is safe to recreate VM
5117 volatile jint safe_to_recreate_vm = 1;
5118 struct JavaVM_ main_vm = {&jni_InvokeInterface};
5119 
5120 
5121 #define JAVASTACKSIZE (400 * 1024)    /* Default size of a thread java stack */
5122 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL };
5123 
5124 #ifndef USDT2
5125 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*);
5126 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint);
5127 #else /* USDT2 */
5128 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint
5129                     , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref));
5130 #endif /* USDT2 */
5131 
5132 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) {
5133 #ifndef USDT2
5134   HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_);
5135 #else /* USDT2 */
5136   HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY(
5137                                              args_);
5138 #endif /* USDT2 */
5139   JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_;
5140   jint ret = JNI_ERR;
5141   DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret);
5142 
5143   if (Threads::is_supported_jni_version(args->version)) {
5144     ret = JNI_OK;
5145   }
5146   // 1.1 style no longer supported in hotspot.
5147   // According the JNI spec, we should update args->version on return.
5148   // We also use the structure to communicate with launcher about default
5149   // stack size.
5150   if (args->version == JNI_VERSION_1_1) {
5151     args->version = JNI_VERSION_1_2;
5152     // javaStackSize is int in arguments structure
5153     assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow");
5154     args->javaStackSize = (jint)(ThreadStackSize * K);
5155   }
5156   return ret;
5157 }
5158 
5159 #ifndef PRODUCT
5160 
5161 #include "gc_implementation/shared/gcTimer.hpp"
5162 #include "gc_interface/collectedHeap.hpp"
5163 #if INCLUDE_ALL_GCS
5164 #include "gc_implementation/g1/heapRegionRemSet.hpp"
5165 #endif
5166 #include "memory/guardedMemory.hpp"
5167 #include "utilities/quickSort.hpp"
5168 #include "utilities/ostream.hpp"
5169 #if INCLUDE_VM_STRUCTS
5170 #include "runtime/vmStructs.hpp"
5171 #endif
5172 
5173 #define run_unit_test(unit_test_function_call)              \
5174   tty->print_cr("Running test: " #unit_test_function_call); \
5175   unit_test_function_call
5176 
5177 // Forward declaration
5178 void TestOS_test();
5179 void TestReservedSpace_test();
5180 void TestReserveMemorySpecial_test();
5181 void TestVirtualSpace_test();
5182 void TestMetaspaceAux_test();
5183 void SpaceManager_test_adjust_initial_chunk_size();
5184 void TestMetachunk_test();
5185 void TestVirtualSpaceNode_test();
5186 void TestNewSize_test();
5187 void TestKlass_test();
5188 void Test_linked_list();
5189 void TestResourcehash_test();
5190 void TestChunkedList_test();
5191 #if INCLUDE_ALL_GCS
5192 void TestOldFreeSpaceCalculation_test();
5193 void TestG1BiasedArray_test();
5194 void TestBufferingOopClosure_test();
5195 void TestCodeCacheRemSet_test();
5196 void FreeRegionList_test();
5197 void ChunkManager_test_list_index();
5198 #endif
5199 
5200 void execute_internal_vm_tests() {
5201   if (ExecuteInternalVMTests) {
5202     tty->print_cr("Running internal VM tests");
5203     run_unit_test(TestOS_test());
5204     run_unit_test(TestReservedSpace_test());
5205     run_unit_test(TestReserveMemorySpecial_test());
5206     run_unit_test(TestVirtualSpace_test());
5207     run_unit_test(TestMetaspaceAux_test());
5208     run_unit_test(TestMetachunk_test());
5209     run_unit_test(TestVirtualSpaceNode_test());
5210     run_unit_test(GlobalDefinitions::test_globals());
5211     run_unit_test(GlobalDefinitions::test_proper_unit());
5212     run_unit_test(GCTimerAllTest::all());
5213     run_unit_test(arrayOopDesc::test_max_array_length());
5214     run_unit_test(CollectedHeap::test_is_in());
5215     run_unit_test(QuickSort::test_quick_sort());
5216     run_unit_test(GuardedMemory::test_guarded_memory());
5217     run_unit_test(AltHashing::test_alt_hash());
5218     run_unit_test(test_loggc_filename());
5219     run_unit_test(test_snprintf());
5220     run_unit_test(TestNewSize_test());
5221     run_unit_test(TestKlass_test());
5222     run_unit_test(TestResourcehash_test());
5223     run_unit_test(Test_linked_list());
5224     run_unit_test(TestChunkedList_test());
5225     run_unit_test(ObjectMonitor::sanity_checks());
5226 #if INCLUDE_VM_STRUCTS
5227     run_unit_test(VMStructs::test());
5228 #endif
5229 #if INCLUDE_ALL_GCS
5230     run_unit_test(TestOldFreeSpaceCalculation_test());
5231     run_unit_test(TestG1BiasedArray_test());
5232     run_unit_test(HeapRegionRemSet::test_prt());
5233     run_unit_test(SpaceManager_test_adjust_initial_chunk_size());
5234     run_unit_test(ChunkManager_test_list_index());
5235     run_unit_test(TestBufferingOopClosure_test());
5236     run_unit_test(TestCodeCacheRemSet_test());
5237     if (UseG1GC) {
5238       run_unit_test(FreeRegionList_test());
5239     }
5240 #endif
5241     tty->print_cr("All internal VM tests passed");
5242   }
5243 }
5244 
5245 #undef run_unit_test
5246 
5247 #endif
5248 
5249 #ifndef USDT2
5250 HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args);
5251 DT_RETURN_MARK_DECL(CreateJavaVM, jint);
5252 #else /* USDT2 */
5253 DT_RETURN_MARK_DECL(CreateJavaVM, jint
5254                     , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref));
5255 #endif /* USDT2 */
5256 
5257 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
5258 #ifndef USDT2
5259   HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args);
5260 #else /* USDT2 */
5261   HOTSPOT_JNI_CREATEJAVAVM_ENTRY(
5262                                  (void **) vm, penv, args);
5263 #endif /* USDT2 */
5264 
5265   jint result = JNI_ERR;
5266   DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result);
5267 
5268   // We're about to use Atomic::xchg for synchronization.  Some Zero
5269   // platforms use the GCC builtin __sync_lock_test_and_set for this,
5270   // but __sync_lock_test_and_set is not guaranteed to do what we want
5271   // on all architectures.  So we check it works before relying on it.
5272 #if defined(ZERO) && defined(ASSERT)
5273   {
5274     jint a = 0xcafebabe;
5275     jint b = Atomic::xchg(0xdeadbeef, &a);
5276     void *c = &a;
5277     void *d = Atomic::xchg_ptr(&b, &c);
5278     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
5279     assert(c == &b && d == &a, "Atomic::xchg_ptr() works");
5280   }
5281 #endif // ZERO && ASSERT
5282 
5283   // At the moment it's only possible to have one Java VM,
5284   // since some of the runtime state is in global variables.
5285 
5286   // We cannot use our mutex locks here, since they only work on
5287   // Threads. We do an atomic compare and exchange to ensure only
5288   // one thread can call this method at a time
5289 
5290   // We use Atomic::xchg rather than Atomic::add/dec since on some platforms
5291   // the add/dec implementations are dependent on whether we are running
5292   // on a multiprocessor, and at this stage of initialization the os::is_MP
5293   // function used to determine this will always return false. Atomic::xchg
5294   // does not have this problem.
5295   if (Atomic::xchg(1, &vm_created) == 1) {
5296     return JNI_EEXIST;   // already created, or create attempt in progress
5297   }
5298   if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) {
5299     return JNI_ERR;  // someone tried and failed and retry not allowed.
5300   }
5301 
5302   assert(vm_created == 1, "vm_created is true during the creation");
5303 
5304   /**
5305    * Certain errors during initialization are recoverable and do not
5306    * prevent this method from being called again at a later time
5307    * (perhaps with different arguments).  However, at a certain
5308    * point during initialization if an error occurs we cannot allow
5309    * this function to be called again (or it will crash).  In those
5310    * situations, the 'canTryAgain' flag is set to false, which atomically
5311    * sets safe_to_recreate_vm to 1, such that any new call to
5312    * JNI_CreateJavaVM will immediately fail using the above logic.
5313    */
5314   bool can_try_again = true;
5315 
5316   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
5317   if (result == JNI_OK) {
5318     JavaThread *thread = JavaThread::current();
5319     /* thread is thread_in_vm here */
5320     *vm = (JavaVM *)(&main_vm);
5321     *(JNIEnv**)penv = thread->jni_environment();
5322 
5323     // Tracks the time application was running before GC
5324     RuntimeService::record_application_start();
5325 
5326     // Notify JVMTI
5327     if (JvmtiExport::should_post_thread_life()) {
5328        JvmtiExport::post_thread_start(thread);
5329     }
5330 
5331     post_thread_start_event(thread);
5332 
5333 #ifndef PRODUCT
5334   #ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
5335     #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
5336   #endif
5337 
5338     // Check if we should compile all classes on bootclasspath
5339     if (CompileTheWorld) ClassLoader::compile_the_world();
5340     if (ReplayCompiles) ciReplay::replay(thread);
5341 
5342     // Some platforms (like Win*) need a wrapper around these test
5343     // functions in order to properly handle error conditions.
5344     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(test_error_handler);
5345     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(execute_internal_vm_tests);
5346 #endif
5347 
5348     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
5349     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5350   } else {
5351     if (can_try_again) {
5352       // reset safe_to_recreate_vm to 1 so that retrial would be possible
5353       safe_to_recreate_vm = 1;
5354     }
5355 
5356     // Creation failed. We must reset vm_created
5357     *vm = 0;
5358     *(JNIEnv**)penv = 0;
5359     // reset vm_created last to avoid race condition. Use OrderAccess to
5360     // control both compiler and architectural-based reordering.
5361     OrderAccess::release_store(&vm_created, 0);
5362   }
5363 
5364   return result;
5365 }
5366 
5367 #ifndef USDT2
5368 HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \
5369   JavaVM**, jsize, jsize*);
5370 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint);
5371 #endif /* !USDT2 */
5372 
5373 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) {
5374   // See bug 4367188, the wrapper can sometimes cause VM crashes
5375   // JNIWrapper("GetCreatedJavaVMs");
5376 #ifndef USDT2
5377   HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \
5378     vm_buf, bufLen, numVMs);
5379 #else /* USDT2 */
5380   HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY(
5381                                       (void **) vm_buf, bufLen, (uintptr_t *) numVMs);
5382 #endif /* USDT2 */
5383   if (vm_created) {
5384     if (numVMs != NULL) *numVMs = 1;
5385     if (bufLen > 0)     *vm_buf = (JavaVM *)(&main_vm);
5386   } else {
5387     if (numVMs != NULL) *numVMs = 0;
5388   }
5389 #ifndef USDT2
5390   HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK);
5391 #else /* USDT2 */
5392   HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN(
5393                                     JNI_OK);
5394 #endif /* USDT2 */
5395   return JNI_OK;
5396 }
5397 
5398 extern "C" {
5399 
5400 #ifndef USDT2
5401 DT_RETURN_MARK_DECL(DestroyJavaVM, jint);
5402 #else /* USDT2 */
5403 DT_RETURN_MARK_DECL(DestroyJavaVM, jint
5404                     , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref));
5405 #endif /* USDT2 */
5406 
5407 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
5408 #ifndef USDT2
5409   DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm);
5410 #else /* USDT2 */
5411   HOTSPOT_JNI_DESTROYJAVAVM_ENTRY(
5412                                   vm);
5413 #endif /* USDT2 */
5414   jint res = JNI_ERR;
5415   DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res);
5416 
5417   if (!vm_created) {
5418     res = JNI_ERR;
5419     return res;
5420   }
5421 
5422   JNIWrapper("DestroyJavaVM");
5423   JNIEnv *env;
5424   JavaVMAttachArgs destroyargs;
5425   destroyargs.version = CurrentVersion;
5426   destroyargs.name = (char *)"DestroyJavaVM";
5427   destroyargs.group = NULL;
5428   res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs);
5429   if (res != JNI_OK) {
5430     return res;
5431   }
5432 
5433   // Since this is not a JVM_ENTRY we have to set the thread state manually before entering.
5434   JavaThread* thread = JavaThread::current();
5435   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
5436   if (Threads::destroy_vm()) {
5437     // Should not change thread state, VM is gone
5438     vm_created = false;
5439     res = JNI_OK;
5440     return res;
5441   } else {
5442     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5443     res = JNI_ERR;
5444     return res;
5445   }
5446 }
5447 
5448 
5449 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) {
5450   JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args;
5451 
5452   // Check below commented out from JDK1.2fcs as well
5453   /*
5454   if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) {
5455     return JNI_EVERSION;
5456   }
5457   */
5458 
5459   Thread* t = ThreadLocalStorage::get_thread_slow();
5460   if (t != NULL) {
5461     // If the thread has been attached this operation is a no-op
5462     *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
5463     return JNI_OK;
5464   }
5465 
5466   // Create a thread and mark it as attaching so it will be skipped by the
5467   // ThreadsListEnumerator - see CR 6404306
5468   JavaThread* thread = new JavaThread(true);
5469 
5470   // Set correct safepoint info. The thread is going to call into Java when
5471   // initializing the Java level thread object. Hence, the correct state must
5472   // be set in order for the Safepoint code to deal with it correctly.
5473   thread->set_thread_state(_thread_in_vm);
5474   // Must do this before initialize_thread_local_storage
5475   thread->record_stack_base_and_size();
5476 
5477   thread->initialize_thread_local_storage();
5478 
5479   if (!os::create_attached_thread(thread)) {
5480     delete thread;
5481     return JNI_ERR;
5482   }
5483   // Enable stack overflow checks
5484   thread->create_stack_guard_pages();
5485 
5486   thread->initialize_tlab();
5487 
5488   thread->cache_global_variables();
5489 
5490   // Crucial that we do not have a safepoint check for this thread, since it has
5491   // not been added to the Thread list yet.
5492   { Threads_lock->lock_without_safepoint_check();
5493     // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
5494     // avoid this thread trying to do a GC before it is added to the thread-list
5495     thread->set_active_handles(JNIHandleBlock::allocate_block());
5496     Threads::add(thread, daemon);
5497     Threads_lock->unlock();
5498   }
5499   // Create thread group and name info from attach arguments
5500   oop group = NULL;
5501   char* thread_name = NULL;
5502   if (args != NULL && Threads::is_supported_jni_version(args->version)) {
5503     group = JNIHandles::resolve(args->group);
5504     thread_name = args->name; // may be NULL
5505   }
5506   if (group == NULL) group = Universe::main_thread_group();
5507 
5508   // Create Java level thread object and attach it to this thread
5509   bool attach_failed = false;
5510   {
5511     EXCEPTION_MARK;
5512     HandleMark hm(THREAD);
5513     Handle thread_group(THREAD, group);
5514     thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD);
5515     if (HAS_PENDING_EXCEPTION) {
5516       CLEAR_PENDING_EXCEPTION;
5517       // cleanup outside the handle mark.
5518       attach_failed = true;
5519     }
5520   }
5521 
5522   if (attach_failed) {
5523     // Added missing cleanup
5524     thread->cleanup_failed_attach_current_thread();
5525     return JNI_ERR;
5526   }
5527 
5528   // mark the thread as no longer attaching
5529   // this uses a fence to push the change through so we don't have
5530   // to regrab the threads_lock
5531   thread->set_done_attaching_via_jni();
5532 
5533   // Set java thread status.
5534   java_lang_Thread::set_thread_status(thread->threadObj(),
5535               java_lang_Thread::RUNNABLE);
5536 
5537   // Notify the debugger
5538   if (JvmtiExport::should_post_thread_life()) {
5539     JvmtiExport::post_thread_start(thread);
5540   }
5541 
5542   post_thread_start_event(thread);
5543 
5544   *(JNIEnv**)penv = thread->jni_environment();
5545 
5546   // Now leaving the VM, so change thread_state. This is normally automatically taken care
5547   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
5548   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
5549   // needed.
5550 
5551   ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5552 
5553   // Perform any platform dependent FPU setup
5554   os::setup_fpu();
5555 
5556   return JNI_OK;
5557 }
5558 
5559 
5560 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
5561 #ifndef USDT2
5562   DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args);
5563 #else /* USDT2 */
5564   HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(
5565                                         vm, penv, _args);
5566 #endif /* USDT2 */
5567   if (!vm_created) {
5568 #ifndef USDT2
5569     DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR);
5570 #else /* USDT2 */
5571   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(
5572                                          (uint32_t) JNI_ERR);
5573 #endif /* USDT2 */
5574     return JNI_ERR;
5575   }
5576 
5577   JNIWrapper("AttachCurrentThread");
5578   jint ret = attach_current_thread(vm, penv, _args, false);
5579 #ifndef USDT2
5580   DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret);
5581 #else /* USDT2 */
5582   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(
5583                                          ret);
5584 #endif /* USDT2 */
5585   return ret;
5586 }
5587 
5588 
5589 jint JNICALL jni_DetachCurrentThread(JavaVM *vm)  {
5590 #ifndef USDT2
5591   DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm);
5592 #else /* USDT2 */
5593   HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(
5594                                         vm);
5595 #endif /* USDT2 */
5596   VM_Exit::block_if_vm_exited();
5597 
5598   JNIWrapper("DetachCurrentThread");
5599 
5600   // If the thread has been deattacted the operations is a no-op
5601   if (ThreadLocalStorage::thread() == NULL) {
5602 #ifndef USDT2
5603     DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK);
5604 #else /* USDT2 */
5605   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
5606                                          JNI_OK);
5607 #endif /* USDT2 */
5608     return JNI_OK;
5609   }
5610 
5611   JavaThread* thread = JavaThread::current();
5612   if (thread->has_last_Java_frame()) {
5613 #ifndef USDT2
5614     DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR);
5615 #else /* USDT2 */
5616   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
5617                                          (uint32_t) JNI_ERR);
5618 #endif /* USDT2 */
5619     // Can't detach a thread that's running java, that can't work.
5620     return JNI_ERR;
5621   }
5622 
5623   // Safepoint support. Have to do call-back to safepoint code, if in the
5624   // middel of a safepoint operation
5625   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
5626 
5627   // XXX: Note that JavaThread::exit() call below removes the guards on the
5628   // stack pages set up via enable_stack_{red,yellow}_zone() calls
5629   // above in jni_AttachCurrentThread. Unfortunately, while the setting
5630   // of the guards is visible in jni_AttachCurrentThread above,
5631   // the removal of the guards is buried below in JavaThread::exit()
5632   // here. The abstraction should be more symmetrically either exposed
5633   // or hidden (e.g. it could probably be hidden in the same
5634   // (platform-dependent) methods where we do alternate stack
5635   // maintenance work?)
5636   thread->exit(false, JavaThread::jni_detach);
5637   delete thread;
5638 
5639 #ifndef USDT2
5640   DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK);
5641 #else /* USDT2 */
5642   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(
5643                                          JNI_OK);
5644 #endif /* USDT2 */
5645   return JNI_OK;
5646 }
5647 
5648 #ifndef USDT2
5649 DT_RETURN_MARK_DECL(GetEnv, jint);
5650 #else /* USDT2 */
5651 DT_RETURN_MARK_DECL(GetEnv, jint
5652                     , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
5653 #endif /* USDT2 */
5654 
5655 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
5656 #ifndef USDT2
5657   DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version);
5658 #else /* USDT2 */
5659   HOTSPOT_JNI_GETENV_ENTRY(
5660                            vm, penv, version);
5661 #endif /* USDT2 */
5662   jint ret = JNI_ERR;
5663   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
5664 
5665   if (!vm_created) {
5666     *penv = NULL;
5667     ret = JNI_EDETACHED;
5668     return ret;
5669   }
5670 
5671   if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {
5672     return ret;
5673   }
5674 
5675 #ifndef JVMPI_VERSION_1
5676 // need these in order to be polite about older agents
5677 #define JVMPI_VERSION_1   ((jint)0x10000001)
5678 #define JVMPI_VERSION_1_1 ((jint)0x10000002)
5679 #define JVMPI_VERSION_1_2 ((jint)0x10000003)
5680 #endif // !JVMPI_VERSION_1
5681 
5682   Thread* thread = ThreadLocalStorage::thread();
5683   if (thread != NULL && thread->is_Java_thread()) {
5684     if (Threads::is_supported_jni_version_including_1_1(version)) {
5685       *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment();
5686       ret = JNI_OK;
5687       return ret;
5688 
5689     } else if (version == JVMPI_VERSION_1 ||
5690                version == JVMPI_VERSION_1_1 ||
5691                version == JVMPI_VERSION_1_2) {
5692       tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported.");
5693       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
5694       ret = JNI_EVERSION;
5695       return ret;
5696     } else if (JvmtiExport::is_jvmdi_version(version)) {
5697       tty->print_cr("FATAL ERROR: JVMDI is no longer supported.");
5698       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
5699       ret = JNI_EVERSION;
5700       return ret;
5701     } else {
5702       *penv = NULL;
5703       ret = JNI_EVERSION;
5704       return ret;
5705     }
5706   } else {
5707     *penv = NULL;
5708     ret = JNI_EDETACHED;
5709     return ret;
5710   }
5711 }
5712 
5713 
5714 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) {
5715 #ifndef USDT2
5716   DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args);
5717 #else /* USDT2 */
5718   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY(
5719                                                 vm, penv, _args);
5720 #endif /* USDT2 */
5721   if (!vm_created) {
5722 #ifndef USDT2
5723     DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR);
5724 #else /* USDT2 */
5725   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(
5726                                                  (uint32_t) JNI_ERR);
5727 #endif /* USDT2 */
5728     return JNI_ERR;
5729   }
5730 
5731   JNIWrapper("AttachCurrentThreadAsDaemon");
5732   jint ret = attach_current_thread(vm, penv, _args, true);
5733 #ifndef USDT2
5734   DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret);
5735 #else /* USDT2 */
5736   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(
5737                                                  ret);
5738 #endif /* USDT2 */
5739   return ret;
5740 }
5741 
5742 
5743 } // End extern "C"
5744 
5745 const struct JNIInvokeInterface_ jni_InvokeInterface = {
5746     NULL,
5747     NULL,
5748     NULL,
5749 
5750     jni_DestroyJavaVM,
5751     jni_AttachCurrentThread,
5752     jni_DetachCurrentThread,
5753     jni_GetEnv,
5754     jni_AttachCurrentThreadAsDaemon
5755 };