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