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