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