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