1 /*
   2  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2024 Red Hat, Inc.
   4  * Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  *
  25  */
  26 
  27 #include "precompiled.hpp"
  28 #include "ci/ciReplay.hpp"
  29 #include "classfile/altHashing.hpp"
  30 #include "classfile/classFileStream.hpp"
  31 #include "classfile/classLoader.hpp"
  32 #include "classfile/classLoadInfo.hpp"
  33 #include "classfile/javaClasses.hpp"
  34 #include "classfile/javaClasses.inline.hpp"
  35 #include "classfile/javaThreadStatus.hpp"
  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/modules.hpp"
  38 #include "classfile/symbolTable.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "compiler/compiler_globals.hpp"
  43 #include "gc/shared/collectedHeap.hpp"
  44 #include "gc/shared/gcLocker.inline.hpp"
  45 #include "gc/shared/stringdedup/stringDedup.hpp"
  46 #include "interpreter/linkResolver.hpp"
  47 #include "jni.h"
  48 #include "jvm.h"
  49 #include "logging/log.hpp"
  50 #include "memory/allocation.hpp"
  51 #include "memory/allocation.inline.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/resourceArea.hpp"
  54 #include "memory/universe.hpp"
  55 #include "nmt/memTracker.hpp"
  56 #include "oops/access.inline.hpp"
  57 #include "oops/arrayOop.hpp"
  58 #include "oops/instanceKlass.inline.hpp"
  59 #include "oops/instanceOop.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/markWord.hpp"
  62 #include "oops/method.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/symbol.hpp"
  67 #include "oops/typeArrayKlass.hpp"
  68 #include "oops/typeArrayOop.inline.hpp"
  69 #include "prims/jniCheck.hpp"
  70 #include "prims/jniExport.hpp"
  71 #include "prims/jniFastGetField.hpp"
  72 #include "prims/jvm_misc.hpp"
  73 #include "prims/jvmtiExport.hpp"
  74 #include "prims/jvmtiThreadState.hpp"
  75 #include "runtime/arguments.hpp"
  76 #include "runtime/atomic.hpp"
  77 #include "runtime/fieldDescriptor.inline.hpp"
  78 #include "runtime/handles.inline.hpp"
  79 #include "runtime/interfaceSupport.inline.hpp"
  80 #include "runtime/java.hpp"
  81 #include "runtime/javaCalls.hpp"
  82 #include "runtime/javaThread.inline.hpp"
  83 #include "runtime/jfieldIDWorkaround.hpp"
  84 #include "runtime/jniHandles.inline.hpp"
  85 #include "runtime/reflection.hpp"
  86 #include "runtime/safepointVerifiers.hpp"
  87 #include "runtime/sharedRuntime.hpp"
  88 #include "runtime/signature.hpp"
  89 #include "runtime/synchronizer.hpp"
  90 #include "runtime/thread.inline.hpp"
  91 #include "runtime/vmOperations.hpp"
  92 #include "services/runtimeService.hpp"
  93 #include "utilities/defaultStream.hpp"
  94 #include "utilities/dtrace.hpp"
  95 #include "utilities/events.hpp"
  96 #include "utilities/macros.hpp"
  97 #include "utilities/vmError.hpp"
  98 #if INCLUDE_JVMCI
  99 #include "jvmci/jvmciCompiler.hpp"
 100 #endif
 101 #if INCLUDE_JFR
 102 #include "jfr/jfr.hpp"
 103 #endif
 104 
 105 static jint CurrentVersion = JNI_VERSION_24;
 106 
 107 #if defined(_WIN32) && !defined(USE_VECTORED_EXCEPTION_HANDLING)
 108 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
 109 #endif
 110 
 111 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 112 // '-return' probe regardless of the return path is taken out of the function.
 113 // Methods that have multiple return paths use this to avoid having to
 114 // instrument each return path.  Methods that use CHECK or THROW must use this
 115 // since those macros can cause an immediate uninstrumented return.
 116 //
 117 // In order to get the return value, a reference to the variable containing
 118 // the return value must be passed to the constructor of the object, and
 119 // the return value must be set before return (since the mark object has
 120 // a reference to it).
 121 //
 122 // Example:
 123 // DT_RETURN_MARK_DECL(SomeFunc, int);
 124 // JNI_ENTRY(int, SomeFunc, ...)
 125 //   int return_value = 0;
 126 //   DT_RETURN_MARK(SomeFunc, int, (const int&)return_value);
 127 //   foo(CHECK_0)
 128 //   return_value = 5;
 129 //   return return_value;
 130 // JNI_END
 131 #define DT_RETURN_MARK_DECL(name, type, probe)                             \
 132   DTRACE_ONLY(                                                             \
 133     class DTraceReturnProbeMark_##name {                                   \
 134      public:                                                               \
 135       const type& _ret_ref;                                                \
 136       DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
 137       ~DTraceReturnProbeMark_##name() {                                    \
 138         probe;                                                             \
 139       }                                                                    \
 140     }                                                                      \
 141   )
 142 // Void functions are simpler since there's no return value
 143 #define DT_VOID_RETURN_MARK_DECL(name, probe)                              \
 144   DTRACE_ONLY(                                                             \
 145     class DTraceReturnProbeMark_##name {                                   \
 146      public:                                                               \
 147       ~DTraceReturnProbeMark_##name() {                                    \
 148         probe;                                                             \
 149       }                                                                    \
 150     }                                                                      \
 151   )
 152 
 153 // Place these macros in the function to mark the return.  Non-void
 154 // functions need the type and address of the return value.
 155 #define DT_RETURN_MARK(name, type, ref) \
 156   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) )
 157 #define DT_VOID_RETURN_MARK(name) \
 158   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark )
 159 
 160 
 161 // Use these to select distinct code for floating-point vs. non-floating point
 162 // situations.  Used from within common macros where we need slightly
 163 // different behavior for Float/Double
 164 #define FP_SELECT_Boolean(intcode, fpcode) intcode
 165 #define FP_SELECT_Byte(intcode, fpcode)    intcode
 166 #define FP_SELECT_Char(intcode, fpcode)    intcode
 167 #define FP_SELECT_Short(intcode, fpcode)   intcode
 168 #define FP_SELECT_Object(intcode, fpcode)  intcode
 169 #define FP_SELECT_Int(intcode, fpcode)     intcode
 170 #define FP_SELECT_Long(intcode, fpcode)    intcode
 171 #define FP_SELECT_Float(intcode, fpcode)   fpcode
 172 #define FP_SELECT_Double(intcode, fpcode)  fpcode
 173 #define FP_SELECT(TypeName, intcode, fpcode) \
 174   FP_SELECT_##TypeName(intcode, fpcode)
 175 
 176 // Choose DT_RETURN_MARK macros  based on the type: float/double -> void
 177 // (dtrace doesn't do FP yet)
 178 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe)    \
 179   FP_SELECT(TypeName, \
 180     DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) )
 181 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \
 182   FP_SELECT(TypeName, \
 183     DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) )
 184 
 185 
 186 // out-of-line helpers for class jfieldIDWorkaround:
 187 
 188 bool jfieldIDWorkaround::is_valid_jfieldID(Klass* k, jfieldID id) {
 189   if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) {
 190     uintptr_t as_uint = (uintptr_t) id;
 191     int offset = raw_instance_offset(id);
 192     if (is_checked_jfieldID(id)) {
 193       if (!klass_hash_ok(k, id)) {
 194         return false;
 195       }
 196     }
 197     return InstanceKlass::cast(k)->contains_field_offset(offset);
 198   } else {
 199     JNIid* result = (JNIid*) id;
 200 #ifdef ASSERT
 201     return result != nullptr && result->is_static_field_id();
 202 #else
 203     return result != nullptr;
 204 #endif
 205   }
 206 }
 207 
 208 
 209 intptr_t jfieldIDWorkaround::encode_klass_hash(Klass* k, int offset) {
 210   if (offset <= small_offset_mask) {
 211     Klass* field_klass = k;
 212     Klass* super_klass = field_klass->super();
 213     // With compressed oops the most super class with nonstatic fields would
 214     // be the owner of fields embedded in the header.
 215     while (InstanceKlass::cast(super_klass)->has_nonstatic_fields() &&
 216            InstanceKlass::cast(super_klass)->contains_field_offset(offset)) {
 217       field_klass = super_klass;   // super contains the field also
 218       super_klass = field_klass->super();
 219     }
 220     debug_only(NoSafepointVerifier nosafepoint;)
 221     uintptr_t klass_hash = field_klass->identity_hash();
 222     return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place;
 223   } else {
 224 #if 0
 225     #ifndef PRODUCT
 226     {
 227       ResourceMark rm;
 228       warning("VerifyJNIFields: long offset %d in %s", offset, k->external_name());
 229     }
 230     #endif
 231 #endif
 232     return 0;
 233   }
 234 }
 235 
 236 bool jfieldIDWorkaround::klass_hash_ok(Klass* k, jfieldID id) {
 237   uintptr_t as_uint = (uintptr_t) id;
 238   intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask;
 239   do {
 240     debug_only(NoSafepointVerifier nosafepoint;)
 241     // Could use a non-blocking query for identity_hash here...
 242     if ((k->identity_hash() & klass_mask) == klass_hash)
 243       return true;
 244     k = k->super();
 245   } while (k != nullptr);
 246   return false;
 247 }
 248 
 249 void jfieldIDWorkaround::verify_instance_jfieldID(Klass* k, jfieldID id) {
 250   guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" );
 251   uintptr_t as_uint = (uintptr_t) id;
 252   int offset = raw_instance_offset(id);
 253   if (VerifyJNIFields) {
 254     if (is_checked_jfieldID(id)) {
 255       guarantee(klass_hash_ok(k, id),
 256     "Bug in native code: jfieldID class must match object");
 257     } else {
 258 #if 0
 259       #ifndef PRODUCT
 260       if (Verbose) {
 261   ResourceMark rm;
 262   warning("VerifyJNIFields: unverified offset %d for %s", offset, k->external_name());
 263       }
 264       #endif
 265 #endif
 266     }
 267   }
 268   guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
 269       "Bug in native code: jfieldID offset must address interior of object");
 270 }
 271 
 272 // Implementation of JNI entries
 273 
 274 DT_RETURN_MARK_DECL(DefineClass, jclass
 275                     , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
 276 
 277 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
 278                                   const jbyte *buf, jsize bufLen))
 279   HOTSPOT_JNI_DEFINECLASS_ENTRY(
 280     env, (char*) name, loaderRef, (char*) buf, bufLen);
 281 
 282   jclass cls = nullptr;
 283   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 284 
 285   // Class resolution will get the class name from the .class stream if the name is null.
 286   TempNewSymbol class_name = name == nullptr ? nullptr :
 287     SystemDictionary::class_name_symbol(name, vmSymbols::java_lang_NoClassDefFoundError(),
 288                                         CHECK_NULL);
 289 
 290   ResourceMark rm(THREAD);
 291   ClassFileStream st((u1*)buf, bufLen, nullptr, ClassFileStream::verify);
 292   Handle class_loader (THREAD, JNIHandles::resolve(loaderRef));
 293   Handle protection_domain;
 294   ClassLoadInfo cl_info(protection_domain);
 295   Klass* k = SystemDictionary::resolve_from_stream(&st, class_name,
 296                                                    class_loader,
 297                                                    cl_info,
 298                                                    CHECK_NULL);
 299 
 300   if (log_is_enabled(Debug, class, resolve)) {
 301     trace_class_resolution(k);
 302   }
 303 
 304   cls = (jclass)JNIHandles::make_local(THREAD, k->java_mirror());
 305   return cls;
 306 JNI_END
 307 
 308 
 309 
 310 DT_RETURN_MARK_DECL(FindClass, jclass
 311                     , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref));
 312 
 313 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name))
 314   HOTSPOT_JNI_FINDCLASS_ENTRY(env, (char *)name);
 315 
 316   jclass result = nullptr;
 317   DT_RETURN_MARK(FindClass, jclass, (const jclass&)result);
 318 
 319   // This should be ClassNotFoundException imo.
 320   TempNewSymbol class_name =
 321     SystemDictionary::class_name_symbol(name, vmSymbols::java_lang_NoClassDefFoundError(),
 322                                         CHECK_NULL);
 323 
 324   //%note jni_3
 325   Handle protection_domain;
 326   // Find calling class
 327   Klass* k = thread->security_get_caller_class(0);
 328   // default to the system loader when no context
 329   Handle loader(THREAD, SystemDictionary::java_system_loader());
 330   if (k != nullptr) {
 331     // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed
 332     // in the correct class context.
 333     if (k->class_loader() == nullptr &&
 334         k->name() == vmSymbols::jdk_internal_loader_NativeLibraries()) {
 335       JavaValue result(T_OBJECT);
 336       JavaCalls::call_static(&result, k,
 337                              vmSymbols::getFromClass_name(),
 338                              vmSymbols::void_class_signature(),
 339                              CHECK_NULL);
 340       // When invoked from JNI_OnLoad, NativeLibraries::getFromClass returns
 341       // a non-null Class object.  When invoked from JNI_OnUnload,
 342       // it will return null to indicate no context.
 343       oop mirror = result.get_oop();
 344       if (mirror != nullptr) {
 345         Klass* fromClass = java_lang_Class::as_Klass(mirror);
 346         loader = Handle(THREAD, fromClass->class_loader());
 347         protection_domain = Handle(THREAD, fromClass->protection_domain());
 348       }
 349     } else {
 350       loader = Handle(THREAD, k->class_loader());
 351     }
 352   }
 353 
 354   result = find_class_from_class_loader(env, class_name, true, loader,
 355                                         protection_domain, true, thread);
 356 
 357   if (log_is_enabled(Debug, class, resolve) && result != nullptr) {
 358     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 359   }
 360 
 361   return result;
 362 JNI_END
 363 
 364 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
 365                     , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
 366 
 367 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
 368   HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(env, method);
 369 
 370   jmethodID ret = nullptr;
 371   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 372 
 373   // method is a handle to a java.lang.reflect.Method object
 374   oop reflected  = JNIHandles::resolve_non_null(method);
 375   oop mirror     = nullptr;
 376   int slot       = 0;
 377 
 378   if (reflected->klass() == vmClasses::reflect_Constructor_klass()) {
 379     mirror = java_lang_reflect_Constructor::clazz(reflected);
 380     slot   = java_lang_reflect_Constructor::slot(reflected);
 381   } else {
 382     assert(reflected->klass() == vmClasses::reflect_Method_klass(), "wrong type");
 383     mirror = java_lang_reflect_Method::clazz(reflected);
 384     slot   = java_lang_reflect_Method::slot(reflected);
 385   }
 386   Klass* k1 = java_lang_Class::as_Klass(mirror);
 387 
 388   // Make sure class is initialized before handing id's out to methods
 389   k1->initialize(CHECK_NULL);
 390   Method* m = InstanceKlass::cast(k1)->method_with_idnum(slot);
 391   ret = m==nullptr? nullptr : m->jmethod_id();  // return null if reflected method deleted
 392   return ret;
 393 JNI_END
 394 
 395 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
 396                     , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
 397 
 398 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
 399   HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(env, field);
 400 
 401   jfieldID ret = nullptr;
 402   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 403 
 404   // field is a handle to a java.lang.reflect.Field object
 405   oop reflected   = JNIHandles::resolve_non_null(field);
 406   oop mirror      = java_lang_reflect_Field::clazz(reflected);
 407   Klass* k1       = java_lang_Class::as_Klass(mirror);
 408   int slot        = java_lang_reflect_Field::slot(reflected);
 409   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 410 
 411   // Make sure class is initialized before handing id's out to fields
 412   k1->initialize(CHECK_NULL);
 413 
 414   // First check if this is a static field
 415   if (modifiers & JVM_ACC_STATIC) {
 416     int offset = InstanceKlass::cast(k1)->field_offset( slot );
 417     JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
 418     assert(id != nullptr, "corrupt Field object");
 419     debug_only(id->set_is_static_field_id();)
 420     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 421     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 422     return ret;
 423   }
 424 
 425   // The slot is the index of the field description in the field-array
 426   // The jfieldID is the offset of the field within the object
 427   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 428   int offset = InstanceKlass::cast(k1)->field_offset( slot );
 429   assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
 430   ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset);
 431   return ret;
 432 JNI_END
 433 
 434 
 435 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
 436                     , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
 437 
 438 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
 439   HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(env, cls, (uintptr_t) method_id, isStatic);
 440 
 441   jobject ret = nullptr;
 442   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 443 
 444   methodHandle m (THREAD, Method::resolve_jmethod_id(method_id));
 445   assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match");
 446   oop reflection_method;
 447   if (m->is_initializer()) {
 448     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
 449   } else {
 450     reflection_method = Reflection::new_method(m, false, CHECK_NULL);
 451   }
 452   ret = JNIHandles::make_local(THREAD, reflection_method);
 453   return ret;
 454 JNI_END
 455 
 456 DT_RETURN_MARK_DECL(GetSuperclass, jclass
 457                     , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
 458 
 459 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
 460   HOTSPOT_JNI_GETSUPERCLASS_ENTRY(env, sub);
 461 
 462   jclass obj = nullptr;
 463   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 464 
 465   oop mirror = JNIHandles::resolve_non_null(sub);
 466   // primitive classes return null
 467   if (java_lang_Class::is_primitive(mirror)) return nullptr;
 468 
 469   // Rules of Class.getSuperClass as implemented by KLass::java_super:
 470   // arrays return Object
 471   // interfaces return null
 472   // proper classes return Klass::super()
 473   Klass* k = java_lang_Class::as_Klass(mirror);
 474   if (k->is_interface()) return nullptr;
 475 
 476   // return mirror for superclass
 477   Klass* super = k->java_super();
 478   // super2 is the value computed by the compiler's getSuperClass intrinsic:
 479   debug_only(Klass* super2 = ( k->is_array_klass()
 480                                  ? vmClasses::Object_klass()
 481                                  : k->super() ) );
 482   assert(super == super2,
 483          "java_super computation depends on interface, array, other super");
 484   obj = (super == nullptr) ? nullptr : (jclass) JNIHandles::make_local(THREAD, super->java_mirror());
 485   return obj;
 486 JNI_END
 487 
 488 JNI_ENTRY_NO_PRESERVE(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super))
 489   HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY(env, sub, super);
 490 
 491   oop sub_mirror   = JNIHandles::resolve_non_null(sub);
 492   oop super_mirror = JNIHandles::resolve_non_null(super);
 493   if (java_lang_Class::is_primitive(sub_mirror) ||
 494       java_lang_Class::is_primitive(super_mirror)) {
 495     jboolean ret = (sub_mirror == super_mirror);
 496 
 497     HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(ret);
 498     return ret;
 499   }
 500   Klass* sub_klass   = java_lang_Class::as_Klass(sub_mirror);
 501   Klass* super_klass = java_lang_Class::as_Klass(super_mirror);
 502   assert(sub_klass != nullptr && super_klass != nullptr, "invalid arguments to jni_IsAssignableFrom");
 503   jboolean ret = sub_klass->is_subtype_of(super_klass) ?
 504                    JNI_TRUE : JNI_FALSE;
 505 
 506   HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(ret);
 507   return ret;
 508 JNI_END
 509 
 510 
 511 DT_RETURN_MARK_DECL(Throw, jint
 512                     , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
 513 
 514 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
 515   HOTSPOT_JNI_THROW_ENTRY(env, obj);
 516 
 517   jint ret = JNI_OK;
 518   DT_RETURN_MARK(Throw, jint, (const jint&)ret);
 519 
 520   THROW_OOP_(JNIHandles::resolve(obj), JNI_OK);
 521   ShouldNotReachHere();
 522   return 0;  // Mute compiler.
 523 JNI_END
 524 
 525 
 526 DT_RETURN_MARK_DECL(ThrowNew, jint
 527                     , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
 528 
 529 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
 530   HOTSPOT_JNI_THROWNEW_ENTRY(env, clazz, (char *) message);
 531 
 532   jint ret = JNI_OK;
 533   DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
 534 
 535   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
 536   Symbol*  name = k->name();
 537   Handle class_loader (THREAD,  k->class_loader());
 538   Handle protection_domain (THREAD, k->protection_domain());
 539   THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK);
 540   ShouldNotReachHere();
 541   return 0;  // Mute compiler.
 542 JNI_END
 543 
 544 
 545 // JNI functions only transform a pending async exception to a synchronous
 546 // exception in ExceptionOccurred and ExceptionCheck calls, since
 547 // delivering an async exception in other places won't change the native
 548 // code's control flow and would be harmful when native code further calls
 549 // JNI functions with a pending exception. Async exception is also checked
 550 // during the call, so ExceptionOccurred/ExceptionCheck won't return
 551 // false but deliver the async exception at the very end during
 552 // state transition.
 553 
 554 static void jni_check_async_exceptions(JavaThread *thread) {
 555   assert(thread == Thread::current(), "must be itself");
 556   if (thread->has_async_exception_condition()) {
 557     SafepointMechanism::process_if_requested_with_exit_check(thread, true /* check asyncs */);
 558   }
 559 }
 560 
 561 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
 562   HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY(env);
 563 
 564   jni_check_async_exceptions(thread);
 565   oop exception = thread->pending_exception();
 566   jthrowable ret = (jthrowable) JNIHandles::make_local(THREAD, exception);
 567 
 568   HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN(ret);
 569   return ret;
 570 JNI_END
 571 
 572 
 573 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env))
 574   HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY(env);
 575 
 576   if (thread->has_pending_exception()) {
 577     Handle ex(thread, thread->pending_exception());
 578     thread->clear_pending_exception();
 579     jio_fprintf(defaultStream::error_stream(), "Exception ");
 580     if (thread != nullptr && thread->threadObj() != nullptr) {
 581       ResourceMark rm(THREAD);
 582       jio_fprintf(defaultStream::error_stream(),
 583                   "in thread \"%s\" ", thread->name());
 584     }
 585     if (ex->is_a(vmClasses::Throwable_klass())) {
 586       JavaValue result(T_VOID);
 587       JavaCalls::call_virtual(&result,
 588                               ex,
 589                               vmClasses::Throwable_klass(),
 590                               vmSymbols::printStackTrace_name(),
 591                               vmSymbols::void_method_signature(),
 592                               THREAD);
 593       // If an exception is thrown in the call it gets thrown away. Not much
 594       // we can do with it. The native code that calls this, does not check
 595       // for the exception - hence, it might still be in the thread when DestroyVM gets
 596       // called, potentially causing a few asserts to trigger - since no pending exception
 597       // is expected.
 598       CLEAR_PENDING_EXCEPTION;
 599     } else {
 600       ResourceMark rm(THREAD);
 601       jio_fprintf(defaultStream::error_stream(),
 602                   ". Uncaught exception of type %s.",
 603                   ex->klass()->external_name());
 604     }
 605   }
 606 
 607   HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN();
 608 JNI_END
 609 
 610 
 611 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionClear(JNIEnv *env))
 612   HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY(env);
 613 
 614   // The jni code might be using this API to clear java thrown exception.
 615   // So just mark jvmti thread exception state as exception caught.
 616   JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state();
 617   if (state != nullptr && state->is_exception_detected()) {
 618     state->set_exception_caught();
 619   }
 620   thread->clear_pending_exception();
 621 
 622   HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN();
 623 JNI_END
 624 
 625 
 626 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg))
 627   HOTSPOT_JNI_FATALERROR_ENTRY(env, (char *) msg);
 628 
 629   tty->print_cr("FATAL ERROR in native method: %s", msg);
 630   thread->print_jni_stack();
 631   os::abort(); // Dump core and abort
 632 JNI_END
 633 
 634 
 635 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity))
 636   HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(env, capacity);
 637 
 638   //%note jni_11
 639   if (capacity < 0 ||
 640       ((MaxJNILocalCapacity > 0) && (capacity > MaxJNILocalCapacity))) {
 641     HOTSPOT_JNI_PUSHLOCALFRAME_RETURN((uint32_t)JNI_ERR);
 642     return JNI_ERR;
 643   }
 644 
 645   thread->push_jni_handle_block();
 646   jint ret = JNI_OK;
 647   HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(ret);
 648   return ret;
 649 JNI_END
 650 
 651 
 652 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result))
 653   HOTSPOT_JNI_POPLOCALFRAME_ENTRY(env, result);
 654 
 655   //%note jni_11
 656   Handle result_handle(thread, JNIHandles::resolve(result));
 657   JNIHandleBlock* old_handles = thread->active_handles();
 658   JNIHandleBlock* new_handles = old_handles->pop_frame_link();
 659   if (new_handles != nullptr) {
 660     // As a sanity check we only release the handle blocks if the pop_frame_link is not null.
 661     // This way code will still work if PopLocalFrame is called without a corresponding
 662     // PushLocalFrame call. Note that we set the pop_frame_link to null explicitly, otherwise
 663     // the release_block call will release the blocks.
 664     thread->set_active_handles(new_handles);
 665     old_handles->set_pop_frame_link(nullptr);              // clear link we won't release new_handles below
 666     JNIHandleBlock::release_block(old_handles, thread); // may block
 667     result = JNIHandles::make_local(thread, result_handle());
 668   }
 669   HOTSPOT_JNI_POPLOCALFRAME_RETURN(result);
 670   return result;
 671 JNI_END
 672 
 673 
 674 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref))
 675   HOTSPOT_JNI_NEWGLOBALREF_ENTRY(env, ref);
 676 
 677   Handle ref_handle(thread, JNIHandles::resolve(ref));
 678   jobject ret = JNIHandles::make_global(ref_handle, AllocFailStrategy::RETURN_NULL);
 679 
 680   HOTSPOT_JNI_NEWGLOBALREF_RETURN(ret);
 681   return ret;
 682 JNI_END
 683 
 684 // Must be JNI_ENTRY (with HandleMark)
 685 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref))
 686   HOTSPOT_JNI_DELETEGLOBALREF_ENTRY(env, ref);
 687 
 688   JNIHandles::destroy_global(ref);
 689 
 690   HOTSPOT_JNI_DELETEGLOBALREF_RETURN();
 691 JNI_END
 692 
 693 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj))
 694   HOTSPOT_JNI_DELETELOCALREF_ENTRY(env, obj);
 695 
 696   JNIHandles::destroy_local(obj);
 697 
 698   HOTSPOT_JNI_DELETELOCALREF_RETURN();
 699 JNI_END
 700 
 701 JNI_ENTRY_NO_PRESERVE(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2))
 702   HOTSPOT_JNI_ISSAMEOBJECT_ENTRY(env, r1, r2);
 703 
 704   jboolean ret = JNIHandles::is_same_object(r1, r2) ? JNI_TRUE : JNI_FALSE;
 705 
 706   HOTSPOT_JNI_ISSAMEOBJECT_RETURN(ret);
 707   return ret;
 708 JNI_END
 709 
 710 
 711 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref))
 712   HOTSPOT_JNI_NEWLOCALREF_ENTRY(env, ref);
 713 
 714   jobject ret = JNIHandles::make_local(THREAD, JNIHandles::resolve(ref),
 715                                        AllocFailStrategy::RETURN_NULL);
 716 
 717   HOTSPOT_JNI_NEWLOCALREF_RETURN(ret);
 718   return ret;
 719 JNI_END
 720 
 721 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity))
 722   HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY(env, capacity);
 723 
 724   jint ret;
 725   if (capacity >= 0 &&
 726       ((MaxJNILocalCapacity <= 0) || (capacity <= MaxJNILocalCapacity))) {
 727     ret = JNI_OK;
 728   } else {
 729     ret = JNI_ERR;
 730   }
 731 
 732   HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN(ret);
 733   return ret;
 734 JNI_END
 735 
 736 // Return the Handle Type
 737 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj))
 738   HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY(env, obj);
 739 
 740   jobjectRefType ret = JNIInvalidRefType;
 741   if (obj != nullptr) {
 742     ret = JNIHandles::handle_type(thread, obj);
 743   }
 744 
 745   HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN((void *) ret);
 746   return ret;
 747 JNI_END
 748 
 749 
 750 class JNI_ArgumentPusher : public SignatureIterator {
 751  protected:
 752   JavaCallArguments*  _arguments;
 753 
 754   void push_int(jint x)         { _arguments->push_int(x); }
 755   void push_long(jlong x)       { _arguments->push_long(x); }
 756   void push_float(jfloat x)     { _arguments->push_float(x); }
 757   void push_double(jdouble x)   { _arguments->push_double(x); }
 758   void push_object(jobject x)   { _arguments->push_jobject(x); }
 759 
 760   void push_boolean(jboolean b) {
 761     // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
 762     // 0 to JNI_FALSE.  Boolean return values from native are normalized the same in
 763     // TemplateInterpreterGenerator::generate_result_handler_for and
 764     // SharedRuntime::generate_native_wrapper.
 765     push_int(b == 0 ? JNI_FALSE : JNI_TRUE);
 766   }
 767 
 768   JNI_ArgumentPusher(Method* method)
 769     : SignatureIterator(method->signature(),
 770                         Fingerprinter(methodHandle(Thread::current(), method)).fingerprint())
 771   {
 772     _arguments = nullptr;
 773   }
 774 
 775  public:
 776   virtual void push_arguments_on(JavaCallArguments* arguments) = 0;
 777 };
 778 
 779 
 780 class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher {
 781   va_list _ap;
 782 
 783   void set_ap(va_list rap) {
 784     va_copy(_ap, rap);
 785   }
 786 
 787   friend class SignatureIterator;  // so do_parameters_on can call do_type
 788   void do_type(BasicType type) {
 789     switch (type) {
 790     // these are coerced to int when using va_arg
 791     case T_BYTE:
 792     case T_CHAR:
 793     case T_SHORT:
 794     case T_INT:         push_int(va_arg(_ap, jint)); break;
 795     case T_BOOLEAN:     push_boolean((jboolean) va_arg(_ap, jint)); break;
 796 
 797     // each of these paths is exercised by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
 798 
 799     case T_LONG:        push_long(va_arg(_ap, jlong)); break;
 800     // float is coerced to double w/ va_arg
 801     case T_FLOAT:       push_float((jfloat) va_arg(_ap, jdouble)); break;
 802     case T_DOUBLE:      push_double(va_arg(_ap, jdouble)); break;
 803 
 804     case T_ARRAY:
 805     case T_OBJECT:      push_object(va_arg(_ap, jobject)); break;
 806     default:            ShouldNotReachHere();
 807     }
 808   }
 809 
 810  public:
 811   JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
 812       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)) {
 813     set_ap(rap);
 814   }
 815 
 816   ~JNI_ArgumentPusherVaArg() {
 817     va_end(_ap);
 818   }
 819 
 820   virtual void push_arguments_on(JavaCallArguments* arguments) {
 821     _arguments = arguments;
 822     do_parameters_on(this);
 823   }
 824 };
 825 
 826 
 827 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher {
 828  protected:
 829   const jvalue *_ap;
 830 
 831   inline void set_ap(const jvalue *rap) { _ap = rap; }
 832 
 833   friend class SignatureIterator;  // so do_parameters_on can call do_type
 834   void do_type(BasicType type) {
 835     switch (type) {
 836     case T_CHAR:        push_int((_ap++)->c); break;
 837     case T_SHORT:       push_int((_ap++)->s); break;
 838     case T_BYTE:        push_int((_ap++)->b); break;
 839     case T_INT:         push_int((_ap++)->i); break;
 840     case T_BOOLEAN:     push_boolean((_ap++)->z); break;
 841     case T_LONG:        push_long((_ap++)->j); break;
 842     case T_FLOAT:       push_float((_ap++)->f); break;
 843     case T_DOUBLE:      push_double((_ap++)->d); break;
 844     case T_ARRAY:
 845     case T_OBJECT:      push_object((_ap++)->l); break;
 846     default:            ShouldNotReachHere();
 847     }
 848   }
 849 
 850  public:
 851   JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap)
 852       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)) {
 853     set_ap(rap);
 854   }
 855 
 856   virtual void push_arguments_on(JavaCallArguments* arguments) {
 857     _arguments = arguments;
 858     do_parameters_on(this);
 859   }
 860 };
 861 
 862 
 863 enum JNICallType {
 864   JNI_STATIC,
 865   JNI_VIRTUAL,
 866   JNI_NONVIRTUAL
 867 };
 868 
 869 
 870 
 871 static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) {
 872   methodHandle method(THREAD, Method::resolve_jmethod_id(method_id));
 873 
 874   // Create object to hold arguments for the JavaCall, and associate it with
 875   // the jni parser
 876   ResourceMark rm(THREAD);
 877   int number_of_parameters = method->size_of_parameters();
 878   JavaCallArguments java_args(number_of_parameters);
 879 
 880   assert(method->is_static(), "method should be static");
 881 
 882   // Fill out JavaCallArguments object
 883   args->push_arguments_on(&java_args);
 884   // Initialize result type
 885   result->set_type(args->return_type());
 886 
 887   // Invoke the method. Result is returned as oop.
 888   JavaCalls::call(result, method, &java_args, CHECK);
 889 
 890   // Convert result
 891   if (is_reference_type(result->get_type())) {
 892     result->set_jobject(JNIHandles::make_local(THREAD, result->get_oop()));
 893   }
 894 }
 895 
 896 
 897 static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) {
 898   oop recv = JNIHandles::resolve(receiver);
 899   if (recv == nullptr) {
 900     THROW(vmSymbols::java_lang_NullPointerException());
 901   }
 902   Handle h_recv(THREAD, recv);
 903 
 904   int number_of_parameters;
 905   Method* selected_method;
 906   {
 907     Method* m = Method::resolve_jmethod_id(method_id);
 908     number_of_parameters = m->size_of_parameters();
 909     InstanceKlass* holder = m->method_holder();
 910     if (call_type != JNI_VIRTUAL) {
 911         selected_method = m;
 912     } else if (!m->has_itable_index()) {
 913       // non-interface call -- for that little speed boost, don't handlize
 914       debug_only(NoSafepointVerifier nosafepoint;)
 915       // jni_GetMethodID makes sure class is linked and initialized
 916       // so m should have a valid vtable index.
 917       assert(m->valid_vtable_index(), "no valid vtable index");
 918       int vtbl_index = m->vtable_index();
 919       if (vtbl_index != Method::nonvirtual_vtable_index) {
 920         selected_method = h_recv->klass()->method_at_vtable(vtbl_index);
 921       } else {
 922         // final method
 923         selected_method = m;
 924       }
 925     } else {
 926       // interface call
 927       int itbl_index = m->itable_index();
 928       Klass* k = h_recv->klass();
 929       selected_method = InstanceKlass::cast(k)->method_at_itable(holder, itbl_index, CHECK);
 930     }
 931   }
 932 
 933   if (selected_method->is_abstract()) {
 934     ResourceMark rm(THREAD);
 935     THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), selected_method->name()->as_C_string());
 936   }
 937 
 938   methodHandle method(THREAD, selected_method);
 939 
 940   // Create object to hold arguments for the JavaCall, and associate it with
 941   // the jni parser
 942   ResourceMark rm(THREAD);
 943   JavaCallArguments java_args(number_of_parameters);
 944 
 945   // handle arguments
 946   assert(!method->is_static(), "method %s should not be static", method->name_and_sig_as_C_string());
 947   java_args.push_oop(h_recv); // Push jobject handle
 948 
 949   // Fill out JavaCallArguments object
 950   args->push_arguments_on(&java_args);
 951   // Initialize result type
 952   result->set_type(args->return_type());
 953 
 954   // Invoke the method. Result is returned as oop.
 955   JavaCalls::call(result, method, &java_args, CHECK);
 956 
 957   // Convert result
 958   if (is_reference_type(result->get_type())) {
 959     result->set_jobject(JNIHandles::make_local(THREAD, result->get_oop()));
 960   }
 961 }
 962 
 963 DT_RETURN_MARK_DECL(AllocObject, jobject
 964                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
 965 
 966 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
 967   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
 968 
 969   jobject ret = nullptr;
 970   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
 971 
 972   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
 973   ret = JNIHandles::make_local(THREAD, i);
 974   return ret;
 975 JNI_END
 976 
 977 DT_RETURN_MARK_DECL(NewObjectA, jobject
 978                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
 979 
 980 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
 981   HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
 982 
 983   jobject obj = nullptr;
 984   DT_RETURN_MARK(NewObjectA, jobject, (const jobject&)obj);
 985 
 986   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
 987   obj = JNIHandles::make_local(THREAD, i);
 988   JavaValue jvalue(T_VOID);
 989   JNI_ArgumentPusherArray ap(methodID, args);
 990   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
 991   return obj;
 992 JNI_END
 993 
 994 
 995 DT_RETURN_MARK_DECL(NewObjectV, jobject
 996                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
 997 
 998 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
 999   HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
1000 
1001   jobject obj = nullptr;
1002   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
1003 
1004   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
1005   obj = JNIHandles::make_local(THREAD, i);
1006   JavaValue jvalue(T_VOID);
1007   JNI_ArgumentPusherVaArg ap(methodID, args);
1008   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1009   return obj;
1010 JNI_END
1011 
1012 
1013 DT_RETURN_MARK_DECL(NewObject, jobject
1014                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1015 
1016 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1017   HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
1018 
1019   jobject obj = nullptr;
1020   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1021 
1022   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
1023   obj = JNIHandles::make_local(THREAD, i);
1024   va_list args;
1025   va_start(args, methodID);
1026   JavaValue jvalue(T_VOID);
1027   JNI_ArgumentPusherVaArg ap(methodID, args);
1028   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1029   va_end(args);
1030   return obj;
1031 JNI_END
1032 
1033 
1034 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1035   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj);
1036 
1037   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1038   jclass ret =
1039     (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
1040 
1041   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret);
1042   return ret;
1043 JNI_END
1044 
1045 JNI_ENTRY_NO_PRESERVE(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz))
1046   HOTSPOT_JNI_ISINSTANCEOF_ENTRY(env, obj, clazz);
1047 
1048   jboolean ret = JNI_TRUE;
1049   if (obj != nullptr) {
1050     ret = JNI_FALSE;
1051     Klass* k = java_lang_Class::as_Klass(
1052       JNIHandles::resolve_non_null(clazz));
1053     if (k != nullptr) {
1054       ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE;
1055     }
1056   }
1057 
1058   HOTSPOT_JNI_ISINSTANCEOF_RETURN(ret);
1059   return ret;
1060 JNI_END
1061 
1062 
1063 static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str,
1064                                const char *sig, bool is_static, TRAPS) {
1065   // %%%% This code should probably just call into a method in the LinkResolver
1066   //
1067   // The class should have been loaded (we have an instance of the class
1068   // passed in) so the method and signature should already be in the symbol
1069   // table.  If they're not there, the method doesn't exist.
1070   const char *name_to_probe = (name_str == nullptr)
1071                         ? vmSymbols::object_initializer_name()->as_C_string()
1072                         : name_str;
1073   TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe));
1074   TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig));
1075 
1076   if (name == nullptr || signature == nullptr) {
1077     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1078   }
1079 
1080   oop mirror = JNIHandles::resolve_non_null(clazz);
1081   Klass* klass = java_lang_Class::as_Klass(mirror);
1082 
1083   // Throw a NoSuchMethodError exception if we have an instance of a
1084   // primitive java.lang.Class
1085   if (java_lang_Class::is_primitive(mirror)) {
1086     ResourceMark rm(THREAD);
1087     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));
1088   }
1089 
1090   // Make sure class is linked and initialized before handing id's out to
1091   // Method*s.
1092   klass->initialize(CHECK_NULL);
1093 
1094   Method* m;
1095   if (name == vmSymbols::object_initializer_name() ||
1096       name == vmSymbols::class_initializer_name()) {
1097     // Never search superclasses for constructors
1098     if (klass->is_instance_klass()) {
1099       m = InstanceKlass::cast(klass)->find_method(name, signature);
1100     } else {
1101       m = nullptr;
1102     }
1103   } else {
1104     m = klass->lookup_method(name, signature);
1105     if (m == nullptr &&  klass->is_instance_klass()) {
1106       m = InstanceKlass::cast(klass)->lookup_method_in_ordered_interfaces(name, signature);
1107     }
1108   }
1109   if (m == nullptr || (m->is_static() != is_static)) {
1110     ResourceMark rm(THREAD);
1111     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), err_msg("%s%s.%s%s", is_static ? "static " : "", klass->signature_name(), name_str, sig));
1112   }
1113   return m->jmethod_id();
1114 }
1115 
1116 
1117 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz,
1118           const char *name, const char *sig))
1119   HOTSPOT_JNI_GETMETHODID_ENTRY(env, clazz, (char *) name, (char *) sig);
1120   jmethodID ret = get_method_id(env, clazz, name, sig, false, thread);
1121   HOTSPOT_JNI_GETMETHODID_RETURN((uintptr_t) ret);
1122   return ret;
1123 JNI_END
1124 
1125 
1126 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz,
1127           const char *name, const char *sig))
1128   HOTSPOT_JNI_GETSTATICMETHODID_ENTRY(env, (char *) clazz, (char *) name, (char *)sig);
1129   jmethodID ret = get_method_id(env, clazz, name, sig, true, thread);
1130   HOTSPOT_JNI_GETSTATICMETHODID_RETURN((uintptr_t) ret);
1131   return ret;
1132 JNI_END
1133 
1134 
1135 
1136 //
1137 // Calling Methods
1138 //
1139 
1140 
1141 #define DEFINE_CALLMETHOD(ResultType, Result, Tag \
1142                           , EntryProbe, ReturnProbe)    \
1143 \
1144   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \
1145                           , ReturnProbe);                          \
1146 \
1147 JNI_ENTRY(ResultType, \
1148           jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \
1149 \
1150   EntryProbe; \
1151   ResultType ret{}; \
1152   DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \
1153                      (const ResultType&)ret);\
1154 \
1155   va_list args; \
1156   va_start(args, methodID); \
1157   JavaValue jvalue(Tag); \
1158   JNI_ArgumentPusherVaArg ap(methodID, args); \
1159   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_(ResultType{})); \
1160   va_end(args); \
1161   ret = jvalue.get_##ResultType(); \
1162   return ret;\
1163 JNI_END
1164 
1165 // the runtime type of subword integral basic types is integer
1166 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN
1167                   , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1168                   HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref))
1169 DEFINE_CALLMETHOD(jbyte,    Byte,    T_BYTE
1170                   , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1171                   HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref))
1172 DEFINE_CALLMETHOD(jchar,    Char,    T_CHAR
1173                   , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1174                   HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref))
1175 DEFINE_CALLMETHOD(jshort,   Short,   T_SHORT
1176                   , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1177                   HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref))
1178 
1179 DEFINE_CALLMETHOD(jobject,  Object,  T_OBJECT
1180                   , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1181                   HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref))
1182 DEFINE_CALLMETHOD(jint,     Int,     T_INT,
1183                   HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1184                   HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref))
1185 DEFINE_CALLMETHOD(jlong,    Long,    T_LONG
1186                   , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1187                   HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref))
1188 // Float and double probes don't return value because dtrace doesn't currently support it
1189 DEFINE_CALLMETHOD(jfloat,   Float,   T_FLOAT
1190                   , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1191                   HOTSPOT_JNI_CALLFLOATMETHOD_RETURN())
1192 DEFINE_CALLMETHOD(jdouble,  Double,  T_DOUBLE
1193                   , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1194                   HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN())
1195 
1196 #define DEFINE_CALLMETHODV(ResultType, Result, Tag \
1197                           , EntryProbe, ReturnProbe)    \
1198 \
1199   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \
1200                           , ReturnProbe);                          \
1201 \
1202 JNI_ENTRY(ResultType, \
1203           jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \
1204 \
1205   EntryProbe;\
1206   ResultType ret{}; \
1207   DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \
1208                      (const ResultType&)ret);\
1209 \
1210   JavaValue jvalue(Tag); \
1211   JNI_ArgumentPusherVaArg ap(methodID, args); \
1212   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_(ResultType{})); \
1213   ret = jvalue.get_##ResultType(); \
1214   return ret;\
1215 JNI_END
1216 
1217 // the runtime type of subword integral basic types is integer
1218 DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN
1219                   , HOTSPOT_JNI_CALLBOOLEANMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1220                   HOTSPOT_JNI_CALLBOOLEANMETHODV_RETURN(_ret_ref))
1221 DEFINE_CALLMETHODV(jbyte,    Byte,    T_BYTE
1222                   , HOTSPOT_JNI_CALLBYTEMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1223                   HOTSPOT_JNI_CALLBYTEMETHODV_RETURN(_ret_ref))
1224 DEFINE_CALLMETHODV(jchar,    Char,    T_CHAR
1225                   , HOTSPOT_JNI_CALLCHARMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1226                   HOTSPOT_JNI_CALLCHARMETHODV_RETURN(_ret_ref))
1227 DEFINE_CALLMETHODV(jshort,   Short,   T_SHORT
1228                   , HOTSPOT_JNI_CALLSHORTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1229                   HOTSPOT_JNI_CALLSHORTMETHODV_RETURN(_ret_ref))
1230 
1231 DEFINE_CALLMETHODV(jobject,  Object,  T_OBJECT
1232                   , HOTSPOT_JNI_CALLOBJECTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1233                   HOTSPOT_JNI_CALLOBJECTMETHODV_RETURN(_ret_ref))
1234 DEFINE_CALLMETHODV(jint,     Int,     T_INT,
1235                   HOTSPOT_JNI_CALLINTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1236                   HOTSPOT_JNI_CALLINTMETHODV_RETURN(_ret_ref))
1237 DEFINE_CALLMETHODV(jlong,    Long,    T_LONG
1238                   , HOTSPOT_JNI_CALLLONGMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1239                   HOTSPOT_JNI_CALLLONGMETHODV_RETURN(_ret_ref))
1240 // Float and double probes don't return value because dtrace doesn't currently support it
1241 DEFINE_CALLMETHODV(jfloat,   Float,   T_FLOAT
1242                   , HOTSPOT_JNI_CALLFLOATMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1243                   HOTSPOT_JNI_CALLFLOATMETHODV_RETURN())
1244 DEFINE_CALLMETHODV(jdouble,  Double,  T_DOUBLE
1245                   , HOTSPOT_JNI_CALLDOUBLEMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1246                   HOTSPOT_JNI_CALLDOUBLEMETHODV_RETURN())
1247 
1248 #define DEFINE_CALLMETHODA(ResultType, Result, Tag \
1249                           , EntryProbe, ReturnProbe)    \
1250 \
1251   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \
1252                           , ReturnProbe);                          \
1253 \
1254 JNI_ENTRY(ResultType, \
1255           jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \
1256   EntryProbe; \
1257   ResultType ret{}; \
1258   DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \
1259                      (const ResultType&)ret);\
1260 \
1261   JavaValue jvalue(Tag); \
1262   JNI_ArgumentPusherArray ap(methodID, args); \
1263   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_(ResultType{})); \
1264   ret = jvalue.get_##ResultType(); \
1265   return ret;\
1266 JNI_END
1267 
1268 // the runtime type of subword integral basic types is integer
1269 DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN
1270                   , HOTSPOT_JNI_CALLBOOLEANMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1271                   HOTSPOT_JNI_CALLBOOLEANMETHODA_RETURN(_ret_ref))
1272 DEFINE_CALLMETHODA(jbyte,    Byte,    T_BYTE
1273                   , HOTSPOT_JNI_CALLBYTEMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1274                   HOTSPOT_JNI_CALLBYTEMETHODA_RETURN(_ret_ref))
1275 DEFINE_CALLMETHODA(jchar,    Char,    T_CHAR
1276                   , HOTSPOT_JNI_CALLCHARMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1277                   HOTSPOT_JNI_CALLCHARMETHODA_RETURN(_ret_ref))
1278 DEFINE_CALLMETHODA(jshort,   Short,   T_SHORT
1279                   , HOTSPOT_JNI_CALLSHORTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1280                   HOTSPOT_JNI_CALLSHORTMETHODA_RETURN(_ret_ref))
1281 
1282 DEFINE_CALLMETHODA(jobject,  Object,  T_OBJECT
1283                   , HOTSPOT_JNI_CALLOBJECTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1284                   HOTSPOT_JNI_CALLOBJECTMETHODA_RETURN(_ret_ref))
1285 DEFINE_CALLMETHODA(jint,     Int,     T_INT,
1286                   HOTSPOT_JNI_CALLINTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1287                   HOTSPOT_JNI_CALLINTMETHODA_RETURN(_ret_ref))
1288 DEFINE_CALLMETHODA(jlong,    Long,    T_LONG
1289                   , HOTSPOT_JNI_CALLLONGMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1290                   HOTSPOT_JNI_CALLLONGMETHODA_RETURN(_ret_ref))
1291 // Float and double probes don't return value because dtrace doesn't currently support it
1292 DEFINE_CALLMETHODA(jfloat,   Float,   T_FLOAT
1293                   , HOTSPOT_JNI_CALLFLOATMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1294                   HOTSPOT_JNI_CALLFLOATMETHODA_RETURN())
1295 DEFINE_CALLMETHODA(jdouble,  Double,  T_DOUBLE
1296                   , HOTSPOT_JNI_CALLDOUBLEMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1297                   HOTSPOT_JNI_CALLDOUBLEMETHODA_RETURN())
1298 
1299 DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN());
1300 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN());
1301 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN());
1302 
1303 
1304 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...))
1305   HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY(env, obj, (uintptr_t) methodID);
1306   DT_VOID_RETURN_MARK(CallVoidMethod);
1307 
1308   va_list args;
1309   va_start(args, methodID);
1310   JavaValue jvalue(T_VOID);
1311   JNI_ArgumentPusherVaArg ap(methodID, args);
1312   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1313   va_end(args);
1314 JNI_END
1315 
1316 
1317 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args))
1318   HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY(env, obj, (uintptr_t) methodID);
1319   DT_VOID_RETURN_MARK(CallVoidMethodV);
1320 
1321   JavaValue jvalue(T_VOID);
1322   JNI_ArgumentPusherVaArg ap(methodID, args);
1323   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1324 JNI_END
1325 
1326 
1327 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args))
1328   HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY(env, obj, (uintptr_t) methodID);
1329   DT_VOID_RETURN_MARK(CallVoidMethodA);
1330 
1331   JavaValue jvalue(T_VOID);
1332   JNI_ArgumentPusherArray ap(methodID, args);
1333   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1334 JNI_END
1335 
1336 
1337 
1338 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \
1339                                     , EntryProbe, ReturnProbe)      \
1340 \
1341   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \
1342                           , ReturnProbe);\
1343 \
1344 JNI_ENTRY(ResultType, \
1345           jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \
1346 \
1347   EntryProbe;\
1348   ResultType ret;\
1349   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \
1350                      (const ResultType&)ret);\
1351 \
1352   va_list args; \
1353   va_start(args, methodID); \
1354   JavaValue jvalue(Tag); \
1355   JNI_ArgumentPusherVaArg ap(methodID, args); \
1356   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_(ResultType{})); \
1357   va_end(args); \
1358   ret = jvalue.get_##ResultType(); \
1359   return ret;\
1360 JNI_END
1361 
1362 // the runtime type of subword integral basic types is integer
1363 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN
1364                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1365                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref))
1366 DEFINE_CALLNONVIRTUALMETHOD(jbyte,    Byte,    T_BYTE
1367                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1368                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref))
1369 DEFINE_CALLNONVIRTUALMETHOD(jchar,    Char,    T_CHAR
1370                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1371                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref))
1372 DEFINE_CALLNONVIRTUALMETHOD(jshort,   Short,   T_SHORT
1373                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1374                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref))
1375 
1376 DEFINE_CALLNONVIRTUALMETHOD(jobject,  Object,  T_OBJECT
1377                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1378                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref))
1379 DEFINE_CALLNONVIRTUALMETHOD(jint,     Int,     T_INT
1380                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1381                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref))
1382 DEFINE_CALLNONVIRTUALMETHOD(jlong,    Long,    T_LONG
1383                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1384 // Float and double probes don't return value because dtrace doesn't currently support it
1385                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref))
1386 DEFINE_CALLNONVIRTUALMETHOD(jfloat,   Float,   T_FLOAT
1387                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1388                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN())
1389 DEFINE_CALLNONVIRTUALMETHOD(jdouble,  Double,  T_DOUBLE
1390                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1391                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN())
1392 
1393 #define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \
1394                                     , EntryProbe, ReturnProbe)      \
1395 \
1396   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \
1397                           , ReturnProbe);\
1398 \
1399 JNI_ENTRY(ResultType, \
1400           jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \
1401 \
1402   EntryProbe;\
1403   ResultType ret;\
1404   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \
1405                      (const ResultType&)ret);\
1406 \
1407   JavaValue jvalue(Tag); \
1408   JNI_ArgumentPusherVaArg ap(methodID, args); \
1409   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_(ResultType{})); \
1410   ret = jvalue.get_##ResultType(); \
1411   return ret;\
1412 JNI_END
1413 
1414 // the runtime type of subword integral basic types is integer
1415 DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN
1416                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1417                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref))
1418 DEFINE_CALLNONVIRTUALMETHODV(jbyte,    Byte,    T_BYTE
1419                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1420                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref))
1421 DEFINE_CALLNONVIRTUALMETHODV(jchar,    Char,    T_CHAR
1422                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1423                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref))
1424 DEFINE_CALLNONVIRTUALMETHODV(jshort,   Short,   T_SHORT
1425                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1426                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref))
1427 
1428 DEFINE_CALLNONVIRTUALMETHODV(jobject,  Object,  T_OBJECT
1429                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1430                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref))
1431 DEFINE_CALLNONVIRTUALMETHODV(jint,     Int,     T_INT
1432                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1433                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref))
1434 DEFINE_CALLNONVIRTUALMETHODV(jlong,    Long,    T_LONG
1435                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1436 // Float and double probes don't return value because dtrace doesn't currently support it
1437                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref))
1438 DEFINE_CALLNONVIRTUALMETHODV(jfloat,   Float,   T_FLOAT
1439                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1440                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN())
1441 DEFINE_CALLNONVIRTUALMETHODV(jdouble,  Double,  T_DOUBLE
1442                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1443                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN())
1444 
1445 #define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \
1446                                     , EntryProbe, ReturnProbe)      \
1447 \
1448   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \
1449                           , ReturnProbe);\
1450 \
1451 JNI_ENTRY(ResultType, \
1452           jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \
1453 \
1454   EntryProbe;\
1455   ResultType ret;\
1456   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \
1457                      (const ResultType&)ret);\
1458 \
1459   JavaValue jvalue(Tag); \
1460   JNI_ArgumentPusherArray ap(methodID, args); \
1461   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_(ResultType{})); \
1462   ret = jvalue.get_##ResultType(); \
1463   return ret;\
1464 JNI_END
1465 
1466 // the runtime type of subword integral basic types is integer
1467 DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN
1468                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1469                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref))
1470 DEFINE_CALLNONVIRTUALMETHODA(jbyte,    Byte,    T_BYTE
1471                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1472                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref))
1473 DEFINE_CALLNONVIRTUALMETHODA(jchar,    Char,    T_CHAR
1474                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1475                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref))
1476 DEFINE_CALLNONVIRTUALMETHODA(jshort,   Short,   T_SHORT
1477                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1478                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref))
1479 
1480 DEFINE_CALLNONVIRTUALMETHODA(jobject,  Object,  T_OBJECT
1481                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1482                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref))
1483 DEFINE_CALLNONVIRTUALMETHODA(jint,     Int,     T_INT
1484                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1485                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref))
1486 DEFINE_CALLNONVIRTUALMETHODA(jlong,    Long,    T_LONG
1487                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1488 // Float and double probes don't return value because dtrace doesn't currently support it
1489                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref))
1490 DEFINE_CALLNONVIRTUALMETHODA(jfloat,   Float,   T_FLOAT
1491                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1492                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN())
1493 DEFINE_CALLNONVIRTUALMETHODA(jdouble,  Double,  T_DOUBLE
1494                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1495                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN())
1496 
1497 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod
1498                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN());
1499 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV
1500                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN());
1501 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA
1502                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN());
1503 
1504 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...))
1505   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY(env, obj, cls, (uintptr_t) methodID);
1506   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod);
1507 
1508   va_list args;
1509   va_start(args, methodID);
1510   JavaValue jvalue(T_VOID);
1511   JNI_ArgumentPusherVaArg ap(methodID, args);
1512   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
1513   va_end(args);
1514 JNI_END
1515 
1516 
1517 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args))
1518   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY(
1519                env, obj, cls, (uintptr_t) methodID);
1520   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV);
1521 
1522   JavaValue jvalue(T_VOID);
1523   JNI_ArgumentPusherVaArg ap(methodID, args);
1524   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
1525 JNI_END
1526 
1527 
1528 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args))
1529   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY(
1530                 env, obj, cls, (uintptr_t) methodID);
1531   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA);
1532   JavaValue jvalue(T_VOID);
1533   JNI_ArgumentPusherArray ap(methodID, args);
1534   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
1535 JNI_END
1536 
1537 
1538 
1539 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \
1540                                 , EntryProbe, ResultProbe) \
1541 \
1542   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \
1543                           , ResultProbe);                               \
1544 \
1545 JNI_ENTRY(ResultType, \
1546           jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \
1547 \
1548   EntryProbe; \
1549   ResultType ret{}; \
1550   DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \
1551                      (const ResultType&)ret);\
1552 \
1553   va_list args; \
1554   va_start(args, methodID); \
1555   JavaValue jvalue(Tag); \
1556   JNI_ArgumentPusherVaArg ap(methodID, args); \
1557   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK_(ResultType{})); \
1558   va_end(args); \
1559   ret = jvalue.get_##ResultType(); \
1560   return ret;\
1561 JNI_END
1562 
1563 // the runtime type of subword integral basic types is integer
1564 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN
1565                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1566                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref));
1567 DEFINE_CALLSTATICMETHOD(jbyte,    Byte,    T_BYTE
1568                         , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1569                         HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref));
1570 DEFINE_CALLSTATICMETHOD(jchar,    Char,    T_CHAR
1571                         , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1572                         HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref));
1573 DEFINE_CALLSTATICMETHOD(jshort,   Short,   T_SHORT
1574                         , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1575                         HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref));
1576 
1577 DEFINE_CALLSTATICMETHOD(jobject,  Object,  T_OBJECT
1578                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1579                         HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref));
1580 DEFINE_CALLSTATICMETHOD(jint,     Int,     T_INT
1581                         , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1582                         HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref));
1583 DEFINE_CALLSTATICMETHOD(jlong,    Long,    T_LONG
1584                         , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1585                         HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref));
1586 // Float and double probes don't return value because dtrace doesn't currently support it
1587 DEFINE_CALLSTATICMETHOD(jfloat,   Float,   T_FLOAT
1588                         , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1589                         HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN());
1590 DEFINE_CALLSTATICMETHOD(jdouble,  Double,  T_DOUBLE
1591                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1592                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN());
1593 
1594 #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \
1595                                 , EntryProbe, ResultProbe) \
1596 \
1597   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \
1598                           , ResultProbe);                               \
1599 \
1600 JNI_ENTRY(ResultType, \
1601           jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
1602 \
1603   EntryProbe; \
1604   ResultType ret{}; \
1605   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
1606                      (const ResultType&)ret);\
1607 \
1608   JavaValue jvalue(Tag); \
1609   JNI_ArgumentPusherVaArg ap(methodID, args); \
1610   /* Make sure class is initialized before trying to invoke its method */ \
1611   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); \
1612   k->initialize(CHECK_(ResultType{})); \
1613   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK_(ResultType{})); \
1614   va_end(args); \
1615   ret = jvalue.get_##ResultType(); \
1616   return ret;\
1617 JNI_END
1618 
1619 // the runtime type of subword integral basic types is integer
1620 DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN
1621                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1622                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref));
1623 DEFINE_CALLSTATICMETHODV(jbyte,    Byte,    T_BYTE
1624                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1625                         HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref));
1626 DEFINE_CALLSTATICMETHODV(jchar,    Char,    T_CHAR
1627                         , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1628                         HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref));
1629 DEFINE_CALLSTATICMETHODV(jshort,   Short,   T_SHORT
1630                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1631                         HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref));
1632 
1633 DEFINE_CALLSTATICMETHODV(jobject,  Object,  T_OBJECT
1634                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1635                         HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref));
1636 DEFINE_CALLSTATICMETHODV(jint,     Int,     T_INT
1637                         , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1638                         HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref));
1639 DEFINE_CALLSTATICMETHODV(jlong,    Long,    T_LONG
1640                         , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1641                         HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref));
1642 // Float and double probes don't return value because dtrace doesn't currently support it
1643 DEFINE_CALLSTATICMETHODV(jfloat,   Float,   T_FLOAT
1644                         , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1645                         HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN());
1646 DEFINE_CALLSTATICMETHODV(jdouble,  Double,  T_DOUBLE
1647                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1648                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN());
1649 
1650 #define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \
1651                                 , EntryProbe, ResultProbe) \
1652 \
1653   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \
1654                           , ResultProbe);                               \
1655 \
1656 JNI_ENTRY(ResultType, \
1657           jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \
1658 \
1659   EntryProbe; \
1660   ResultType ret{}; \
1661   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \
1662                      (const ResultType&)ret);\
1663 \
1664   JavaValue jvalue(Tag); \
1665   JNI_ArgumentPusherArray ap(methodID, args); \
1666   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK_(ResultType{})); \
1667   ret = jvalue.get_##ResultType(); \
1668   return ret;\
1669 JNI_END
1670 
1671 // the runtime type of subword integral basic types is integer
1672 DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN
1673                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1674                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref));
1675 DEFINE_CALLSTATICMETHODA(jbyte,    Byte,    T_BYTE
1676                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1677                         HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref));
1678 DEFINE_CALLSTATICMETHODA(jchar,    Char,    T_CHAR
1679                         , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1680                         HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref));
1681 DEFINE_CALLSTATICMETHODA(jshort,   Short,   T_SHORT
1682                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1683                         HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref));
1684 
1685 DEFINE_CALLSTATICMETHODA(jobject,  Object,  T_OBJECT
1686                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1687                         HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref));
1688 DEFINE_CALLSTATICMETHODA(jint,     Int,     T_INT
1689                         , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1690                         HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref));
1691 DEFINE_CALLSTATICMETHODA(jlong,    Long,    T_LONG
1692                         , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1693                         HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref));
1694 // Float and double probes don't return value because dtrace doesn't currently support it
1695 DEFINE_CALLSTATICMETHODA(jfloat,   Float,   T_FLOAT
1696                         , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1697                         HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN());
1698 DEFINE_CALLSTATICMETHODA(jdouble,  Double,  T_DOUBLE
1699                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1700                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN());
1701 
1702 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod
1703                          , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN());
1704 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV
1705                          , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN());
1706 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA
1707                          , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN());
1708 
1709 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...))
1710   HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY(env, cls, (uintptr_t) methodID);
1711   DT_VOID_RETURN_MARK(CallStaticVoidMethod);
1712 
1713   va_list args;
1714   va_start(args, methodID);
1715   JavaValue jvalue(T_VOID);
1716   JNI_ArgumentPusherVaArg ap(methodID, args);
1717   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK);
1718   va_end(args);
1719 JNI_END
1720 
1721 
1722 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args))
1723   HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY(env, cls, (uintptr_t) methodID);
1724   DT_VOID_RETURN_MARK(CallStaticVoidMethodV);
1725 
1726   JavaValue jvalue(T_VOID);
1727   JNI_ArgumentPusherVaArg ap(methodID, args);
1728   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK);
1729 JNI_END
1730 
1731 
1732 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args))
1733   HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY(env, cls, (uintptr_t) methodID);
1734   DT_VOID_RETURN_MARK(CallStaticVoidMethodA);
1735 
1736   JavaValue jvalue(T_VOID);
1737   JNI_ArgumentPusherArray ap(methodID, args);
1738   jni_invoke_static(env, &jvalue, nullptr, JNI_STATIC, methodID, &ap, CHECK);
1739 JNI_END
1740 
1741 
1742 //
1743 // Accessing Fields
1744 //
1745 
1746 
1747 DT_RETURN_MARK_DECL(GetFieldID, jfieldID
1748                     , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref));
1749 
1750 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz,
1751           const char *name, const char *sig))
1752   HOTSPOT_JNI_GETFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
1753   jfieldID ret = nullptr;
1754   DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret);
1755 
1756   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1757 
1758   // The class should have been loaded (we have an instance of the class
1759   // passed in) so the field and signature should already be in the symbol
1760   // table.  If they're not there, the field doesn't exist.
1761   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1762   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1763   if (fieldname == nullptr || signame == nullptr) {
1764     ResourceMark rm;
1765     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1766   }
1767 
1768   // Make sure class is initialized before handing id's out to fields
1769   k->initialize(CHECK_NULL);
1770 
1771   fieldDescriptor fd;
1772   if (!k->is_instance_klass() ||
1773       !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
1774     ResourceMark rm;
1775     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), err_msg("%s.%s %s", k->external_name(), name, sig));
1776   }
1777 
1778   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
1779   // It may also have hash bits for k, if VerifyJNIFields is turned on.
1780   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
1781   return ret;
1782 JNI_END
1783 
1784 
1785 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
1786   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
1787   oop o = JNIHandles::resolve_non_null(obj);
1788   Klass* k = o->klass();
1789   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1790   // Keep JVMTI addition small and only check enabled flag here.
1791   // jni_GetField_probe() assumes that is okay to create handles.
1792   if (JvmtiExport::should_post_field_access()) {
1793     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
1794   }
1795   oop loaded_obj = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(o, offset);
1796   jobject ret = JNIHandles::make_local(THREAD, loaded_obj);
1797   HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
1798   return ret;
1799 JNI_END
1800 
1801 
1802 
1803 #define DEFINE_GETFIELD(Return,Fieldname,Result \
1804   , EntryProbe, ReturnProbe) \
1805 \
1806   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
1807   , ReturnProbe); \
1808 \
1809 JNI_ENTRY_NO_PRESERVE(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
1810 \
1811   EntryProbe; \
1812   Return ret = 0;\
1813   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
1814 \
1815   oop o = JNIHandles::resolve_non_null(obj); \
1816   Klass* k = o->klass(); \
1817   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
1818   /* Keep JVMTI addition small and only check enabled flag here.       */ \
1819   if (JvmtiExport::should_post_field_access()) { \
1820     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); \
1821   } \
1822   ret = o->Fieldname##_field(offset); \
1823   return ret; \
1824 JNI_END
1825 
1826 DEFINE_GETFIELD(jboolean, bool,   Boolean
1827                 , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1828                 HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref))
1829 DEFINE_GETFIELD(jbyte,    byte,   Byte
1830                 , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1831                 HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref))
1832 DEFINE_GETFIELD(jchar,    char,   Char
1833                 , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1834                 HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref))
1835 DEFINE_GETFIELD(jshort,   short,  Short
1836                 , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1837                 HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref))
1838 DEFINE_GETFIELD(jint,     int,    Int
1839                 , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1840                 HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref))
1841 DEFINE_GETFIELD(jlong,    long,   Long
1842                 , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1843                 HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref))
1844 // Float and double probes don't return value because dtrace doesn't currently support it
1845 DEFINE_GETFIELD(jfloat,   float,  Float
1846                 , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1847                 HOTSPOT_JNI_GETFLOATFIELD_RETURN())
1848 DEFINE_GETFIELD(jdouble,  double, Double
1849                 , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1850                 HOTSPOT_JNI_GETDOUBLEFIELD_RETURN())
1851 
1852 address jni_GetBooleanField_addr() {
1853   return (address)jni_GetBooleanField;
1854 }
1855 address jni_GetByteField_addr() {
1856   return (address)jni_GetByteField;
1857 }
1858 address jni_GetCharField_addr() {
1859   return (address)jni_GetCharField;
1860 }
1861 address jni_GetShortField_addr() {
1862   return (address)jni_GetShortField;
1863 }
1864 address jni_GetIntField_addr() {
1865   return (address)jni_GetIntField;
1866 }
1867 address jni_GetLongField_addr() {
1868   return (address)jni_GetLongField;
1869 }
1870 address jni_GetFloatField_addr() {
1871   return (address)jni_GetFloatField;
1872 }
1873 address jni_GetDoubleField_addr() {
1874   return (address)jni_GetDoubleField;
1875 }
1876 
1877 JNI_ENTRY_NO_PRESERVE(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value))
1878   HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID, value);
1879   oop o = JNIHandles::resolve_non_null(obj);
1880   Klass* k = o->klass();
1881   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1882   // Keep JVMTI addition small and only check enabled flag here.
1883   if (JvmtiExport::should_post_field_modification()) {
1884     jvalue field_value;
1885     field_value.l = value;
1886     o = JvmtiExport::jni_SetField_probe(thread, obj, o, k, fieldID, false, JVM_SIGNATURE_CLASS, (jvalue *)&field_value);
1887   }
1888   HeapAccess<ON_UNKNOWN_OOP_REF>::oop_store_at(o, offset, JNIHandles::resolve(value));
1889   HOTSPOT_JNI_SETOBJECTFIELD_RETURN();
1890 JNI_END
1891 
1892 // TODO: make this a template
1893 
1894 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \
1895                         , EntryProbe, ReturnProbe) \
1896 \
1897 JNI_ENTRY_NO_PRESERVE(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
1898 \
1899   EntryProbe; \
1900 \
1901   oop o = JNIHandles::resolve_non_null(obj); \
1902   Klass* k = o->klass(); \
1903   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
1904   /* Keep JVMTI addition small and only check enabled flag here.       */ \
1905   if (JvmtiExport::should_post_field_modification()) { \
1906     jvalue field_value; \
1907     field_value.unionType = value; \
1908     o = JvmtiExport::jni_SetField_probe(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \
1909   } \
1910   o->Fieldname##_field_put(offset, value); \
1911   ReturnProbe; \
1912 JNI_END
1913 
1914 DEFINE_SETFIELD(jboolean, bool,   Boolean, JVM_SIGNATURE_BOOLEAN, z
1915                 , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
1916                 HOTSPOT_JNI_SETBOOLEANFIELD_RETURN())
1917 DEFINE_SETFIELD(jbyte,    byte,   Byte,    JVM_SIGNATURE_BYTE, b
1918                 , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
1919                 HOTSPOT_JNI_SETBYTEFIELD_RETURN())
1920 DEFINE_SETFIELD(jchar,    char,   Char,    JVM_SIGNATURE_CHAR, c
1921                 , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
1922                 HOTSPOT_JNI_SETCHARFIELD_RETURN())
1923 DEFINE_SETFIELD(jshort,   short,  Short,   JVM_SIGNATURE_SHORT, s
1924                 , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
1925                 HOTSPOT_JNI_SETSHORTFIELD_RETURN())
1926 DEFINE_SETFIELD(jint,     int,    Int,     JVM_SIGNATURE_INT, i
1927                 , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
1928                 HOTSPOT_JNI_SETINTFIELD_RETURN())
1929 DEFINE_SETFIELD(jlong,    long,   Long,    JVM_SIGNATURE_LONG, j
1930                 , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
1931                 HOTSPOT_JNI_SETLONGFIELD_RETURN())
1932 // Float and double probes don't return value because dtrace doesn't currently support it
1933 DEFINE_SETFIELD(jfloat,   float,  Float,   JVM_SIGNATURE_FLOAT, f
1934                 , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1935                 HOTSPOT_JNI_SETFLOATFIELD_RETURN())
1936 DEFINE_SETFIELD(jdouble,  double, Double,  JVM_SIGNATURE_DOUBLE, d
1937                 , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
1938                 HOTSPOT_JNI_SETDOUBLEFIELD_RETURN())
1939 
1940 DT_RETURN_MARK_DECL(ToReflectedField, jobject
1941                     , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref));
1942 
1943 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic))
1944   HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY(env, cls, (uintptr_t) fieldID, isStatic);
1945   jobject ret = nullptr;
1946   DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret);
1947 
1948   fieldDescriptor fd;
1949   bool found = false;
1950   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1951 
1952   assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID");
1953 
1954   if (isStatic) {
1955     // Static field. The fieldID a JNIid specifying the field holder and the offset within the Klass*.
1956     JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
1957     assert(id->is_static_field_id(), "invalid static field id");
1958     found = id->find_local_field(&fd);
1959   } else {
1960     // Non-static field. The fieldID is really the offset of the field within the instanceOop.
1961     int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1962     found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, &fd);
1963   }
1964   assert(found, "bad fieldID passed into jni_ToReflectedField");
1965   oop reflected = Reflection::new_field(&fd, CHECK_NULL);
1966   ret = JNIHandles::make_local(THREAD, reflected);
1967   return ret;
1968 JNI_END
1969 
1970 
1971 //
1972 // Accessing Static Fields
1973 //
1974 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID
1975                     , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref));
1976 
1977 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz,
1978           const char *name, const char *sig))
1979   HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
1980   jfieldID ret = nullptr;
1981   DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret);
1982 
1983   // The class should have been loaded (we have an instance of the class
1984   // passed in) so the field and signature should already be in the symbol
1985   // table.  If they're not there, the field doesn't exist.
1986   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
1987   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
1988   if (fieldname == nullptr || signame == nullptr) {
1989     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
1990   }
1991   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1992   // Make sure class is initialized before handing id's out to static fields
1993   k->initialize(CHECK_NULL);
1994 
1995   fieldDescriptor fd;
1996   if (!k->is_instance_klass() ||
1997       !InstanceKlass::cast(k)->find_field(fieldname, signame, true, &fd)) {
1998     THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
1999   }
2000 
2001   // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
2002   JNIid* id = fd.field_holder()->jni_id_for(fd.offset());
2003   debug_only(id->set_is_static_field_id();)
2004 
2005   debug_only(id->verify(fd.field_holder()));
2006 
2007   ret = jfieldIDWorkaround::to_static_jfieldID(id);
2008   return ret;
2009 JNI_END
2010 
2011 
2012 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID))
2013   HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID);
2014 #if INCLUDE_JNI_CHECK
2015   DEBUG_ONLY(Klass* param_k = jniCheck::validate_class(thread, clazz);)
2016 #endif // INCLUDE_JNI_CHECK
2017   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2018   assert(id->is_static_field_id(), "invalid static field id");
2019   // Keep JVMTI addition small and only check enabled flag here.
2020   // jni_GetField_probe() assumes that is okay to create handles.
2021   if (JvmtiExport::should_post_field_access()) {
2022     JvmtiExport::jni_GetField_probe(thread, nullptr, nullptr, id->holder(), fieldID, true);
2023   }
2024   jobject ret = JNIHandles::make_local(THREAD, id->holder()->java_mirror()->obj_field(id->offset()));
2025   HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN(ret);
2026   return ret;
2027 JNI_END
2028 
2029 
2030 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \
2031                               , EntryProbe, ReturnProbe) \
2032 \
2033   DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \
2034                           , ReturnProbe);                                          \
2035 \
2036 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \
2037   EntryProbe; \
2038   Return ret = 0;\
2039   DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \
2040                      (const Return&)ret);\
2041   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
2042   assert(id->is_static_field_id(), "invalid static field id"); \
2043   /* Keep JVMTI addition small and only check enabled flag here. */ \
2044   /* jni_GetField_probe() assumes that is okay to create handles. */ \
2045   if (JvmtiExport::should_post_field_access()) { \
2046     JvmtiExport::jni_GetField_probe(thread, nullptr, nullptr, id->holder(), fieldID, true); \
2047   } \
2048   ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \
2049   return ret;\
2050 JNI_END
2051 
2052 DEFINE_GETSTATICFIELD(jboolean, bool,   Boolean
2053                       , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref))
2054 DEFINE_GETSTATICFIELD(jbyte,    byte,   Byte
2055                       , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref)   )
2056 DEFINE_GETSTATICFIELD(jchar,    char,   Char
2057                       , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref)   )
2058 DEFINE_GETSTATICFIELD(jshort,   short,  Short
2059                       , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref)  )
2060 DEFINE_GETSTATICFIELD(jint,     int,    Int
2061                       , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),     HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref)    )
2062 DEFINE_GETSTATICFIELD(jlong,    long,   Long
2063                       , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref)   )
2064 // Float and double probes don't return value because dtrace doesn't currently support it
2065 DEFINE_GETSTATICFIELD(jfloat,   float,  Float
2066                       , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN()          )
2067 DEFINE_GETSTATICFIELD(jdouble,  double, Double
2068                       , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),  HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN()         )
2069 
2070 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value))
2071  HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value);
2072   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2073   assert(id->is_static_field_id(), "invalid static field id");
2074   // Keep JVMTI addition small and only check enabled flag here.
2075   // jni_SetField_probe() assumes that is okay to create handles.
2076   if (JvmtiExport::should_post_field_modification()) {
2077     jvalue field_value;
2078     field_value.l = value;
2079     JvmtiExport::jni_SetField_probe(thread, nullptr, nullptr, id->holder(), fieldID, true, JVM_SIGNATURE_CLASS, (jvalue *)&field_value);
2080   }
2081   id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value));
2082   HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN();
2083 JNI_END
2084 
2085 
2086 
2087 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \
2088                               , EntryProbe, ReturnProbe) \
2089 \
2090 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \
2091   EntryProbe; \
2092 \
2093   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
2094   assert(id->is_static_field_id(), "invalid static field id"); \
2095   /* Keep JVMTI addition small and only check enabled flag here. */ \
2096   /* jni_SetField_probe() assumes that is okay to create handles. */ \
2097   if (JvmtiExport::should_post_field_modification()) { \
2098     jvalue field_value; \
2099     field_value.unionType = value; \
2100     JvmtiExport::jni_SetField_probe(thread, nullptr, nullptr, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \
2101   } \
2102   id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \
2103   ReturnProbe;\
2104 JNI_END
2105 
2106 DEFINE_SETSTATICFIELD(jboolean, bool,   Boolean, JVM_SIGNATURE_BOOLEAN, z
2107                       , HOTSPOT_JNI_SETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value),
2108                       HOTSPOT_JNI_SETSTATICBOOLEANFIELD_RETURN())
2109 DEFINE_SETSTATICFIELD(jbyte,    byte,   Byte,    JVM_SIGNATURE_BYTE, b
2110                       , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2111                       HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN())
2112 DEFINE_SETSTATICFIELD(jchar,    char,   Char,    JVM_SIGNATURE_CHAR, c
2113                       , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2114                       HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN())
2115 DEFINE_SETSTATICFIELD(jshort,   short,  Short,   JVM_SIGNATURE_SHORT, s
2116                       , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2117                       HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN())
2118 DEFINE_SETSTATICFIELD(jint,     int,    Int,     JVM_SIGNATURE_INT, i
2119                       , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2120                       HOTSPOT_JNI_SETSTATICINTFIELD_RETURN())
2121 DEFINE_SETSTATICFIELD(jlong,    long,   Long,    JVM_SIGNATURE_LONG, j
2122                       , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2123                       HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN())
2124 // Float and double probes don't return value because dtrace doesn't currently support it
2125 DEFINE_SETSTATICFIELD(jfloat,   float,  Float,   JVM_SIGNATURE_FLOAT, f
2126                       , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
2127                       HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN())
2128 DEFINE_SETSTATICFIELD(jdouble,  double, Double,  JVM_SIGNATURE_DOUBLE, d
2129                       , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
2130                       HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN())
2131 
2132 //
2133 // String Operations
2134 //
2135 
2136 // Unicode Interface
2137 
2138 DT_RETURN_MARK_DECL(NewString, jstring
2139                     , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref));
2140 
2141 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len))
2142  HOTSPOT_JNI_NEWSTRING_ENTRY(env, (uint16_t *) unicodeChars, len);
2143   jstring ret = nullptr;
2144   DT_RETURN_MARK(NewString, jstring, (const jstring&)ret);
2145   oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL);
2146   ret = (jstring) JNIHandles::make_local(THREAD, string);
2147   return ret;
2148 JNI_END
2149 
2150 
2151 JNI_ENTRY_NO_PRESERVE(jsize, jni_GetStringLength(JNIEnv *env, jstring string))
2152   HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY(env, string);
2153   jsize ret = 0;
2154   oop s = JNIHandles::resolve_non_null(string);
2155   ret = java_lang_String::length(s);
2156  HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(ret);
2157   return ret;
2158 JNI_END
2159 
2160 
2161 JNI_ENTRY_NO_PRESERVE(const jchar*, jni_GetStringChars(
2162   JNIEnv *env, jstring string, jboolean *isCopy))
2163  HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(env, string, (uintptr_t *) isCopy);
2164   jchar* buf = nullptr;
2165   oop s = JNIHandles::resolve_non_null(string);
2166   typeArrayOop s_value = java_lang_String::value(s);
2167   if (s_value != nullptr) {
2168     int s_len = java_lang_String::length(s, s_value);
2169     bool is_latin1 = java_lang_String::is_latin1(s);
2170     buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
2171     /* JNI Specification states return null on OOM */
2172     if (buf != nullptr) {
2173       if (s_len > 0) {
2174         if (!is_latin1) {
2175           ArrayAccess<>::arraycopy_to_native(s_value, (size_t) typeArrayOopDesc::element_offset<jchar>(0),
2176                                              buf, s_len);
2177         } else {
2178           for (int i = 0; i < s_len; i++) {
2179             buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
2180           }
2181         }
2182       }
2183       buf[s_len] = 0;
2184       //%note jni_5
2185       if (isCopy != nullptr) {
2186         *isCopy = JNI_TRUE;
2187       }
2188     }
2189   }
2190   HOTSPOT_JNI_GETSTRINGCHARS_RETURN(buf);
2191   return buf;
2192 JNI_END
2193 
2194 
2195 JNI_ENTRY_NO_PRESERVE(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars))
2196   HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY(env, str, (uint16_t *) chars);
2197   //%note jni_6
2198   if (chars != nullptr) {
2199     // Since String objects are supposed to be immutable, don't copy any
2200     // new data back.  A bad user will have to go after the char array.
2201     FreeHeap((void*) chars);
2202   }
2203   HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN();
2204 JNI_END
2205 
2206 
2207 // UTF Interface
2208 
2209 DT_RETURN_MARK_DECL(NewStringUTF, jstring
2210                     , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref));
2211 
2212 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes))
2213   HOTSPOT_JNI_NEWSTRINGUTF_ENTRY(env, (char *) bytes);
2214   jstring ret;
2215   DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret);
2216 
2217   oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL);
2218   ret = (jstring) JNIHandles::make_local(THREAD, result);
2219   return ret;
2220 JNI_END
2221 
2222 
2223 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string))
2224   HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY(env, string);
2225   oop java_string = JNIHandles::resolve_non_null(string);
2226   jsize ret = java_lang_String::utf8_length_as_int(java_string);
2227   HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN(ret);
2228   return ret;
2229 JNI_END
2230 
2231 JNI_ENTRY(jlong, jni_GetStringUTFLengthAsLong(JNIEnv *env, jstring string))
2232   HOTSPOT_JNI_GETSTRINGUTFLENGTHASLONG_ENTRY(env, string);
2233   oop java_string = JNIHandles::resolve_non_null(string);
2234   size_t ret = java_lang_String::utf8_length(java_string);
2235   HOTSPOT_JNI_GETSTRINGUTFLENGTHASLONG_RETURN(ret);
2236 return checked_cast<jlong>(ret);
2237 JNI_END
2238 
2239 
2240 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy))
2241  HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY(env, string, (uintptr_t *) isCopy);
2242   char* result = nullptr;
2243   oop java_string = JNIHandles::resolve_non_null(string);
2244   typeArrayOop s_value = java_lang_String::value(java_string);
2245   if (s_value != nullptr) {
2246     size_t length = java_lang_String::utf8_length(java_string, s_value);
2247     // JNI Specification states return null on OOM.
2248     // The resulting sequence doesn't have to be NUL-terminated but we do.
2249     result = AllocateHeap(length + 1, mtInternal, AllocFailStrategy::RETURN_NULL);
2250     if (result != nullptr) {
2251       java_lang_String::as_utf8_string(java_string, s_value, result, length + 1);
2252       if (isCopy != nullptr) {
2253         *isCopy = JNI_TRUE;
2254       }
2255     }
2256   }
2257  HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN(result);
2258   return result;
2259 JNI_END
2260 
2261 
2262 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars))
2263  HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY(env, str, (char *) chars);
2264   if (chars != nullptr) {
2265     FreeHeap((char*) chars);
2266   }
2267 HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN();
2268 JNI_END
2269 
2270 
2271 JNI_ENTRY_NO_PRESERVE(jsize, jni_GetArrayLength(JNIEnv *env, jarray array))
2272  HOTSPOT_JNI_GETARRAYLENGTH_ENTRY(env, array);
2273   arrayOop a = arrayOop(JNIHandles::resolve_non_null(array));
2274   assert(a->is_array(), "must be array");
2275   jsize ret = a->length();
2276  HOTSPOT_JNI_GETARRAYLENGTH_RETURN(ret);
2277   return ret;
2278 JNI_END
2279 
2280 
2281 //
2282 // Object Array Operations
2283 //
2284 
2285 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray
2286                     , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref));
2287 
2288 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement))
2289  HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY(env, length, elementClass, initialElement);
2290   jobjectArray ret = nullptr;
2291   DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret);
2292   Klass* ek = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(elementClass));
2293   Klass* ak = ek->array_klass(CHECK_NULL);
2294   ObjArrayKlass::cast(ak)->initialize(CHECK_NULL);
2295   objArrayOop result = ObjArrayKlass::cast(ak)->allocate(length, CHECK_NULL);
2296   oop initial_value = JNIHandles::resolve(initialElement);
2297   if (initial_value != nullptr) {  // array already initialized with null
2298     for (int index = 0; index < length; index++) {
2299       result->obj_at_put(index, initial_value);
2300     }
2301   }
2302   ret = (jobjectArray) JNIHandles::make_local(THREAD, result);
2303   return ret;
2304 JNI_END
2305 
2306 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject
2307                     , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref));
2308 
2309 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index))
2310  HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(env, array, index);
2311   jobject ret = nullptr;
2312   DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret);
2313   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2314   if (a->is_within_bounds(index)) {
2315     ret = JNIHandles::make_local(THREAD, a->obj_at(index));
2316     return ret;
2317   } else {
2318     ResourceMark rm(THREAD);
2319     stringStream ss;
2320     ss.print("Index %d out of bounds for length %d", index, a->length());
2321     THROW_MSG_NULL(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2322   }
2323 JNI_END
2324 
2325 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement
2326                          , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN());
2327 
2328 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value))
2329  HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(env, array, index, value);
2330   DT_VOID_RETURN_MARK(SetObjectArrayElement);
2331 
2332   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2333   oop v = JNIHandles::resolve(value);
2334   if (a->is_within_bounds(index)) {
2335     if (v == nullptr || v->is_a(ObjArrayKlass::cast(a->klass())->element_klass())) {
2336       a->obj_at_put(index, v);
2337     } else {
2338       ResourceMark rm(THREAD);
2339       stringStream ss;
2340       Klass *bottom_kl = ObjArrayKlass::cast(a->klass())->bottom_klass();
2341       ss.print("type mismatch: can not store %s to %s[%d]",
2342                v->klass()->external_name(),
2343                bottom_kl->is_typeArray_klass() ? type2name_tab[ArrayKlass::cast(bottom_kl)->element_type()] : bottom_kl->external_name(),
2344                index);
2345       for (int dims = ArrayKlass::cast(a->klass())->dimension(); dims > 1; --dims) {
2346         ss.print("[]");
2347       }
2348       THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());
2349     }
2350   } else {
2351     ResourceMark rm(THREAD);
2352     stringStream ss;
2353     ss.print("Index %d out of bounds for length %d", index, a->length());
2354     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2355   }
2356 JNI_END
2357 
2358 
2359 
2360 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \
2361                               ,EntryProbe,ReturnProbe)  \
2362 \
2363   DT_RETURN_MARK_DECL(New##Result##Array, Return \
2364                       , ReturnProbe); \
2365 \
2366 JNI_ENTRY(Return, \
2367           jni_New##Result##Array(JNIEnv *env, jsize len)) \
2368   EntryProbe; \
2369   Return ret = nullptr;\
2370   DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
2371 \
2372   oop obj= oopFactory::Allocator(len, CHECK_NULL); \
2373   ret = (Return) JNIHandles::make_local(THREAD, obj); \
2374   return ret;\
2375 JNI_END
2376 
2377 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray,   Boolean,
2378                       HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len),
2379                       HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref))
2380 DEFINE_NEWSCALARARRAY(jbyteArray,    new_byteArray,   Byte,
2381                       HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len),
2382                       HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref))
2383 DEFINE_NEWSCALARARRAY(jshortArray,   new_shortArray,  Short,
2384                       HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len),
2385                       HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref))
2386 DEFINE_NEWSCALARARRAY(jcharArray,    new_charArray,   Char,
2387                       HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len),
2388                       HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref))
2389 DEFINE_NEWSCALARARRAY(jintArray,     new_intArray,    Int,
2390                       HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len),
2391                       HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref))
2392 DEFINE_NEWSCALARARRAY(jlongArray,    new_longArray,   Long,
2393                       HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len),
2394                       HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref))
2395 DEFINE_NEWSCALARARRAY(jfloatArray,   new_floatArray,  Float,
2396                       HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len),
2397                       HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref))
2398 DEFINE_NEWSCALARARRAY(jdoubleArray,  new_doubleArray, Double,
2399                       HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len),
2400                       HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref))
2401 
2402 // Return an address which will fault if the caller writes to it.
2403 
2404 static char* get_bad_address() {
2405   static char* bad_address = nullptr;
2406   if (bad_address == nullptr) {
2407     size_t size = os::vm_allocation_granularity();
2408     bad_address = os::reserve_memory(size);
2409     if (bad_address != nullptr) {
2410       os::protect_memory(bad_address, size, os::MEM_PROT_READ,
2411                          /*is_committed*/false);
2412       MemTracker::record_virtual_memory_tag((void*)bad_address, mtInternal);
2413     }
2414   }
2415   return bad_address;
2416 }
2417 
2418 
2419 
2420 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \
2421                                       , EntryProbe, ReturnProbe) \
2422 \
2423 JNI_ENTRY_NO_PRESERVE(ElementType*, \
2424           jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
2425   EntryProbe; \
2426   /* allocate an chunk of memory in c land */ \
2427   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2428   ElementType* result; \
2429   int len = a->length(); \
2430   if (len == 0) { \
2431     if (isCopy != nullptr) { \
2432       *isCopy = JNI_FALSE; \
2433     } \
2434     /* Empty array: legal but useless, can't return null. \
2435      * Return a pointer to something useless. \
2436      * Avoid asserts in typeArrayOop. */ \
2437     result = (ElementType*)get_bad_address(); \
2438   } else { \
2439     /* JNI Specification states return null on OOM */                    \
2440     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
2441     if (result != nullptr) {                                             \
2442       /* copy the array to the c chunk */                                \
2443       ArrayAccess<>::arraycopy_to_native(a, typeArrayOopDesc::element_offset<ElementType>(0), \
2444                                          result, len);                   \
2445       if (isCopy) {                                                      \
2446         *isCopy = JNI_TRUE;                                              \
2447       }                                                                  \
2448     }                                                                    \
2449   } \
2450   ReturnProbe; \
2451   return result; \
2452 JNI_END
2453 
2454 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2455                               , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2456                               HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result))
2457 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2458                               , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2459                               HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result))
2460 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2461                               , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
2462                               HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result))
2463 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2464                               , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
2465                               HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result))
2466 DEFINE_GETSCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
2467                               , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2468                               HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result))
2469 DEFINE_GETSCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
2470                               , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2471                               HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result)))
2472 // Float and double probes don't return value because dtrace doesn't currently support it
2473 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
2474                               , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2475                               HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result))
2476 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
2477                               , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2478                               HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result))
2479 
2480 
2481 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \
2482                                           , EntryProbe, ReturnProbe);\
2483 \
2484 JNI_ENTRY_NO_PRESERVE(void, \
2485           jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
2486                                              ElementType *buf, jint mode)) \
2487   EntryProbe; \
2488   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2489   int len = a->length(); \
2490   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
2491     if ((mode == 0) || (mode == JNI_COMMIT)) { \
2492       ArrayAccess<>::arraycopy_from_native(buf, a, typeArrayOopDesc::element_offset<ElementType>(0), len); \
2493     } \
2494     if ((mode == 0) || (mode == JNI_ABORT)) { \
2495       FreeHeap(buf); \
2496     } \
2497   } \
2498   ReturnProbe; \
2499 JNI_END
2500 
2501 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2502                                   , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
2503                                   HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN())
2504 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2505                                   , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode),
2506                                   HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN())
2507 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2508                                   ,  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2509                                   HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN())
2510 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2511                                   ,  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2512                                   HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN())
2513 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
2514                                   , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode),
2515                                   HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN())
2516 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
2517                                   , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
2518                                   HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN())
2519 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
2520                                   , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode),
2521                                   HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN())
2522 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
2523                                   , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode),
2524                                   HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN())
2525 
2526 static void check_bounds(jsize start, jsize copy_len, jsize array_len, TRAPS) {
2527   ResourceMark rm(THREAD);
2528   if (copy_len < 0) {
2529     stringStream ss;
2530     ss.print("Length %d is negative", copy_len);
2531     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2532   } else if (start < 0 || (start > array_len - copy_len)) {
2533     stringStream ss;
2534     ss.print("Array region %d.." INT64_FORMAT " out of bounds for length %d",
2535              start, (int64_t)start+(int64_t)copy_len, array_len);
2536     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
2537   }
2538 }
2539 
2540 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2541                                     , EntryProbe, ReturnProbe); \
2542   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \
2543                            , ReturnProbe); \
2544 \
2545 JNI_ENTRY(void, \
2546 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2547              jsize len, ElementType *buf)) \
2548   EntryProbe; \
2549   DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
2550   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2551   check_bounds(start, len, src->length(), CHECK); \
2552   if (len > 0) {    \
2553     ArrayAccess<>::arraycopy_to_native(src, typeArrayOopDesc::element_offset<ElementType>(start), buf, len); \
2554   } \
2555 JNI_END
2556 
2557 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool
2558                             , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2559                             HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN());
2560 DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte
2561                             ,  HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2562                             HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN());
2563 DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short
2564                             , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2565                             HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN());
2566 DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char
2567                             ,  HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf),
2568                             HOTSPOT_JNI_GETCHARARRAYREGION_RETURN());
2569 DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int
2570                             , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf),
2571                             HOTSPOT_JNI_GETINTARRAYREGION_RETURN());
2572 DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long
2573                             ,  HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2574                             HOTSPOT_JNI_GETLONGARRAYREGION_RETURN());
2575 DEFINE_GETSCALARARRAYREGION(T_FLOAT,   jfloat,  Float,   float
2576                             , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
2577                             HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN());
2578 DEFINE_GETSCALARARRAYREGION(T_DOUBLE,  jdouble, Double,  double
2579                             , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2580                             HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN());
2581 
2582 
2583 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2584                                     , EntryProbe, ReturnProbe); \
2585   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \
2586                            ,ReturnProbe);           \
2587 \
2588 JNI_ENTRY(void, \
2589 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2590              jsize len, const ElementType *buf)) \
2591   EntryProbe; \
2592   DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
2593   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2594   check_bounds(start, len, dst->length(), CHECK); \
2595   if (len > 0) { \
2596     ArrayAccess<>::arraycopy_from_native(buf, dst, typeArrayOopDesc::element_offset<ElementType>(start), len); \
2597   } \
2598 JNI_END
2599 
2600 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool
2601                             , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf),
2602                             HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN())
2603 DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte
2604                             , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2605                             HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN())
2606 DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short
2607                             , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2608                             HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
2609 DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char
2610                             , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2611                             HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
2612 DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int
2613                             , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
2614                             HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
2615 DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long
2616                             , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2617                             HOTSPOT_JNI_SETLONGARRAYREGION_RETURN())
2618 DEFINE_SETSCALARARRAYREGION(T_FLOAT,   jfloat,   Float,   float
2619                             , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
2620                             HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN())
2621 DEFINE_SETSCALARARRAYREGION(T_DOUBLE,  jdouble,  Double,  double
2622                             , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2623                             HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN())
2624 
2625 
2626 DT_RETURN_MARK_DECL(RegisterNatives, jint
2627                     , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref));
2628 
2629 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
2630                                     const JNINativeMethod *methods,
2631                                     jint nMethods))
2632   HOTSPOT_JNI_REGISTERNATIVES_ENTRY(env, clazz, (void *) methods, nMethods);
2633   jint ret = 0;
2634   DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
2635 
2636   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2637 
2638   // There are no restrictions on native code registering native methods,
2639   // which allows agents to redefine the bindings to native methods, however
2640   // we issue a warning if any code running outside of the boot/platform
2641   // loader is rebinding any native methods in classes loaded by the
2642   // boot/platform loader that are in named modules. That will catch changes
2643   // to platform classes while excluding classes added to the bootclasspath.
2644   bool do_warning = false;
2645 
2646   // Only instanceKlasses can have native methods
2647   if (k->is_instance_klass()) {
2648     oop cl = k->class_loader();
2649     InstanceKlass* ik = InstanceKlass::cast(k);
2650     // Check for a platform class
2651     if ((cl ==  nullptr || SystemDictionary::is_platform_class_loader(cl)) &&
2652         ik->module()->is_named()) {
2653       Klass* caller = thread->security_get_caller_class(1);
2654       // If no caller class, or caller class has a different loader, then
2655       // issue a warning below.
2656       do_warning = (caller == nullptr) || caller->class_loader() != cl;
2657     }
2658   }
2659 
2660 
2661   for (int index = 0; index < nMethods; index++) {
2662     const char* meth_name = methods[index].name;
2663     const char* meth_sig = methods[index].signature;
2664     int meth_name_len = (int)strlen(meth_name);
2665 
2666     // The class should have been loaded (we have an instance of the class
2667     // passed in) so the method and signature should already be in the symbol
2668     // table.  If they're not there, the method doesn't exist.
2669     TempNewSymbol  name = SymbolTable::probe(meth_name, meth_name_len);
2670     TempNewSymbol  signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig));
2671 
2672     if (name == nullptr || signature == nullptr) {
2673       ResourceMark rm(THREAD);
2674       stringStream st;
2675       st.print("Method %s.%s%s not found", k->external_name(), meth_name, meth_sig);
2676       // Must return negative value on failure
2677       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1);
2678     }
2679 
2680     if (do_warning) {
2681       ResourceMark rm(THREAD);
2682       log_warning(jni, resolve)("Re-registering of platform native method: %s.%s%s "
2683               "from code in a different classloader", k->external_name(), meth_name, meth_sig);
2684     }
2685 
2686     bool res = Method::register_native(k, name, signature,
2687                                        (address) methods[index].fnPtr, THREAD);
2688     if (!res) {
2689       ret = -1;
2690       break;
2691     }
2692   }
2693   return ret;
2694 JNI_END
2695 
2696 
2697 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz))
2698  HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(env, clazz);
2699   Klass* k   = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2700   //%note jni_2
2701   if (k->is_instance_klass()) {
2702     for (int index = 0; index < InstanceKlass::cast(k)->methods()->length(); index++) {
2703       Method* m = InstanceKlass::cast(k)->methods()->at(index);
2704       if (m->is_native()) {
2705         m->clear_native_function();
2706         m->set_signature_handler(nullptr);
2707       }
2708     }
2709   }
2710  HOTSPOT_JNI_UNREGISTERNATIVES_RETURN(0);
2711   return 0;
2712 JNI_END
2713 
2714 //
2715 // Monitor functions
2716 //
2717 
2718 DT_RETURN_MARK_DECL(MonitorEnter, jint
2719                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
2720 
2721 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
2722  HOTSPOT_JNI_MONITORENTER_ENTRY(env, jobj);
2723   jint ret = JNI_ERR;
2724   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
2725 
2726   // If the object is null, we can't do anything with it
2727   if (jobj == nullptr) {
2728     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2729   }
2730 
2731   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
2732   ObjectSynchronizer::jni_enter(obj, thread);
2733   return JNI_OK;
2734 JNI_END
2735 
2736 DT_RETURN_MARK_DECL(MonitorExit, jint
2737                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
2738 
2739 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
2740  HOTSPOT_JNI_MONITOREXIT_ENTRY(env, jobj);
2741   jint ret = JNI_ERR;
2742   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
2743 
2744   // Don't do anything with a null object
2745   if (jobj == nullptr) {
2746     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
2747   }
2748 
2749   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
2750   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
2751   return JNI_OK;
2752 JNI_END
2753 
2754 //
2755 // Extensions
2756 //
2757 
2758 DT_VOID_RETURN_MARK_DECL(GetStringRegion
2759                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
2760 
2761 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
2762  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(env, string, start, len, buf);
2763   DT_VOID_RETURN_MARK(GetStringRegion);
2764   oop s = JNIHandles::resolve_non_null(string);
2765   typeArrayOop s_value = java_lang_String::value(s);
2766   int s_len = java_lang_String::length(s, s_value);
2767   if (start < 0 || len < 0 || start > s_len - len) {
2768     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
2769   } else {
2770     if (len > 0) {
2771       bool is_latin1 = java_lang_String::is_latin1(s);
2772       if (!is_latin1) {
2773         ArrayAccess<>::arraycopy_to_native(s_value, typeArrayOopDesc::element_offset<jchar>(start),
2774                                            buf, len);
2775       } else {
2776         for (int i = 0; i < len; i++) {
2777           buf[i] = ((jchar) s_value->byte_at(i + start)) & 0xff;
2778         }
2779       }
2780     }
2781   }
2782 JNI_END
2783 
2784 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion
2785                          , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN());
2786 
2787 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf))
2788  HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(env, string, start, len, buf);
2789   DT_VOID_RETURN_MARK(GetStringUTFRegion);
2790   oop s = JNIHandles::resolve_non_null(string);
2791   typeArrayOop s_value = java_lang_String::value(s);
2792   int s_len = java_lang_String::length(s, s_value);
2793   if (start < 0 || len < 0 || start > s_len - len) {
2794     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
2795   } else {
2796     //%note jni_7
2797     if (len > 0) {
2798       // Assume the buffer is large enough as the JNI spec. does not require user error checking
2799       java_lang_String::as_utf8_string(s, s_value, start, len, buf, INT_MAX);
2800       // as_utf8_string null-terminates the result string
2801     } else {
2802       // JDK null-terminates the buffer even in len is zero
2803       if (buf != nullptr) {
2804         buf[0] = 0;
2805       }
2806     }
2807   }
2808 JNI_END
2809 
2810 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
2811  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(env, array, (uintptr_t *) isCopy);
2812   Handle a(thread, JNIHandles::resolve_non_null(array));
2813   assert(a->is_typeArray(), "just checking");
2814 
2815   // Pin object
2816   Universe::heap()->pin_object(thread, a());
2817 
2818   BasicType type = TypeArrayKlass::cast(a->klass())->element_type();
2819   void* ret = arrayOop(a())->base(type);
2820   if (isCopy != nullptr) {
2821     *isCopy = JNI_FALSE;
2822   }
2823  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(ret);
2824   return ret;
2825 JNI_END
2826 
2827 
2828 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
2829   HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(env, array, carray, mode);
2830   // Unpin object
2831   Universe::heap()->unpin_object(thread, JNIHandles::resolve_non_null(array));
2832 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN();
2833 JNI_END
2834 
2835 
2836 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
2837   HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(env, string, (uintptr_t *) isCopy);
2838   oop s = JNIHandles::resolve_non_null(string);
2839   jchar* ret;
2840   if (!java_lang_String::is_latin1(s)) {
2841     typeArrayHandle s_value(thread, java_lang_String::value(s));
2842 
2843     // Pin value array
2844     Universe::heap()->pin_object(thread, s_value());
2845 
2846     ret = (jchar*) s_value->base(T_CHAR);
2847     if (isCopy != nullptr) *isCopy = JNI_FALSE;
2848   } else {
2849     // Inflate latin1 encoded string to UTF16
2850     typeArrayOop s_value = java_lang_String::value(s);
2851     int s_len = java_lang_String::length(s, s_value);
2852     ret = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
2853     /* JNI Specification states return null on OOM */
2854     if (ret != nullptr) {
2855       for (int i = 0; i < s_len; i++) {
2856         ret[i] = ((jchar) s_value->byte_at(i)) & 0xff;
2857       }
2858       ret[s_len] = 0;
2859     }
2860     if (isCopy != nullptr) *isCopy = JNI_TRUE;
2861   }
2862  HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN((uint16_t *) ret);
2863   return ret;
2864 JNI_END
2865 
2866 
2867 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
2868   HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(env, str, (uint16_t *) chars);
2869   oop s = JNIHandles::resolve_non_null(str);
2870   bool is_latin1 = java_lang_String::is_latin1(s);
2871 
2872   if (is_latin1) {
2873     // For latin1 string, free jchar array allocated by earlier call to GetStringCritical.
2874     // This assumes that ReleaseStringCritical bookends GetStringCritical.
2875     FREE_C_HEAP_ARRAY(jchar, chars);
2876   } else {
2877     // StringDedup can have replaced the value array, so don't fetch the array from 's'.
2878     // Instead, we calculate the address based on the jchar array exposed with GetStringCritical.
2879     oop value = cast_to_oop((address)chars - arrayOopDesc::base_offset_in_bytes(T_CHAR));
2880 
2881     // Unpin value array
2882     Universe::heap()->unpin_object(thread, value);
2883   }
2884 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN();
2885 JNI_END
2886 
2887 
2888 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
2889   HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(env, ref);
2890   Handle ref_handle(thread, JNIHandles::resolve(ref));
2891   jweak ret = JNIHandles::make_weak_global(ref_handle, AllocFailStrategy::RETURN_NULL);
2892   if (ret == nullptr && ref_handle.not_null()) {
2893     THROW_OOP_(Universe::out_of_memory_error_c_heap(), nullptr);
2894   }
2895   HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(ret);
2896   return ret;
2897 JNI_END
2898 
2899 // Must be JNI_ENTRY (with HandleMark)
2900 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref))
2901   HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY(env, ref);
2902   JNIHandles::destroy_weak_global(ref);
2903   HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN();
2904 JNI_END
2905 
2906 
2907 JNI_ENTRY_NO_PRESERVE(jboolean, jni_ExceptionCheck(JNIEnv *env))
2908  HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY(env);
2909   jni_check_async_exceptions(thread);
2910   jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE;
2911  HOTSPOT_JNI_EXCEPTIONCHECK_RETURN(ret);
2912   return ret;
2913 JNI_END
2914 
2915 
2916 // Initialization state for three routines below relating to
2917 // java.nio.DirectBuffers
2918 static          int directBufferSupportInitializeStarted = 0;
2919 static volatile int directBufferSupportInitializeEnded   = 0;
2920 static volatile int directBufferSupportInitializeFailed  = 0;
2921 static jclass    bufferClass                 = nullptr;
2922 static jclass    directBufferClass           = nullptr;
2923 static jclass    directByteBufferClass       = nullptr;
2924 static jmethodID directByteBufferConstructor = nullptr;
2925 static jfieldID  directBufferAddressField    = nullptr;
2926 static jfieldID  bufferCapacityField         = nullptr;
2927 
2928 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) {
2929   Handle loader;            // null (bootstrap) loader
2930   Handle protection_domain; // null protection domain
2931 
2932   TempNewSymbol sym = SymbolTable::new_symbol(name);
2933   jclass result =  find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL);
2934 
2935   if (log_is_enabled(Debug, class, resolve) && result != nullptr) {
2936     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
2937   }
2938   return result;
2939 }
2940 
2941 // These lookups are done with the null (bootstrap) ClassLoader to
2942 // circumvent any security checks that would be done by jni_FindClass.
2943 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env))
2944 {
2945   if ((bufferClass           = lookupOne(env, "java/nio/Buffer", thread))           == nullptr) { return false; }
2946   if ((directBufferClass     = lookupOne(env, "sun/nio/ch/DirectBuffer", thread))   == nullptr) { return false; }
2947   if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == nullptr) { return false; }
2948   return true;
2949 }
2950 JNI_END
2951 
2952 
2953 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
2954   if (directBufferSupportInitializeFailed) {
2955     return false;
2956   }
2957 
2958   if (Atomic::cmpxchg(&directBufferSupportInitializeStarted, 0, 1) == 0) {
2959     if (!lookupDirectBufferClasses(env)) {
2960       directBufferSupportInitializeFailed = 1;
2961       return false;
2962     }
2963 
2964     // Make global references for these
2965     bufferClass           = (jclass) env->NewGlobalRef(bufferClass);
2966     directBufferClass     = (jclass) env->NewGlobalRef(directBufferClass);
2967     directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
2968 
2969     // Global refs will be null if out-of-memory (no exception is pending)
2970     if (bufferClass == nullptr || directBufferClass == nullptr || directByteBufferClass == nullptr) {
2971       directBufferSupportInitializeFailed = 1;
2972       return false;
2973     }
2974 
2975     // Get needed field and method IDs
2976     directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JJ)V");
2977     if (env->ExceptionCheck()) {
2978       env->ExceptionClear();
2979       directBufferSupportInitializeFailed = 1;
2980       return false;
2981     }
2982     directBufferAddressField    = env->GetFieldID(bufferClass, "address", "J");
2983     if (env->ExceptionCheck()) {
2984       env->ExceptionClear();
2985       directBufferSupportInitializeFailed = 1;
2986       return false;
2987     }
2988     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
2989     if (env->ExceptionCheck()) {
2990       env->ExceptionClear();
2991       directBufferSupportInitializeFailed = 1;
2992       return false;
2993     }
2994 
2995     if ((directByteBufferConstructor == nullptr) ||
2996         (directBufferAddressField    == nullptr) ||
2997         (bufferCapacityField         == nullptr)) {
2998       directBufferSupportInitializeFailed = 1;
2999       return false;
3000     }
3001 
3002     directBufferSupportInitializeEnded = 1;
3003   } else {
3004     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
3005       os::naked_yield();
3006     }
3007   }
3008 
3009   return !directBufferSupportInitializeFailed;
3010 }
3011 
3012 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
3013 {
3014   // thread_from_jni_environment() will block if VM is gone.
3015   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3016 
3017  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(env, address, capacity);
3018 
3019   if (!directBufferSupportInitializeEnded) {
3020     if (!initializeDirectBufferSupport(env, thread)) {
3021       HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(nullptr);
3022       return nullptr;
3023     }
3024   }
3025 
3026   // Being paranoid about accidental sign extension on address
3027   jlong addr = (jlong) ((uintptr_t) address);
3028   jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, capacity);
3029   HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(ret);
3030   return ret;
3031 }
3032 
3033 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*
3034                     , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref));
3035 
3036 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
3037 {
3038   // thread_from_jni_environment() will block if VM is gone.
3039   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3040 
3041   HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY(env, buf);
3042   void* ret = nullptr;
3043   DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret);
3044 
3045   if (!directBufferSupportInitializeEnded) {
3046     if (!initializeDirectBufferSupport(env, thread)) {
3047       return nullptr;
3048     }
3049   }
3050 
3051   if ((buf != nullptr) && (!env->IsInstanceOf(buf, directBufferClass))) {
3052     return nullptr;
3053   }
3054 
3055   ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField);
3056   return ret;
3057 }
3058 
3059 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong
3060                     , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref));
3061 
3062 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf)
3063 {
3064   // thread_from_jni_environment() will block if VM is gone.
3065   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3066 
3067   HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY(env, buf);
3068   jlong ret = -1;
3069   DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret);
3070 
3071   if (!directBufferSupportInitializeEnded) {
3072     if (!initializeDirectBufferSupport(env, thread)) {
3073       ret = 0;
3074       return ret;
3075     }
3076   }
3077 
3078   if (buf == nullptr) {
3079     return -1;
3080   }
3081 
3082   if (!env->IsInstanceOf(buf, directBufferClass)) {
3083     return -1;
3084   }
3085 
3086   // NOTE that capacity is currently an int in the implementation
3087   ret = env->GetIntField(buf, bufferCapacityField);
3088   return ret;
3089 }
3090 
3091 
3092 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
3093   HOTSPOT_JNI_GETVERSION_ENTRY(env);
3094   HOTSPOT_JNI_GETVERSION_RETURN(CurrentVersion);
3095   return CurrentVersion;
3096 JNI_END
3097 
3098 extern struct JavaVM_ main_vm;
3099 
3100 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
3101   HOTSPOT_JNI_GETJAVAVM_ENTRY(env, (void **) vm);
3102   *vm  = (JavaVM *)(&main_vm);
3103   HOTSPOT_JNI_GETJAVAVM_RETURN(JNI_OK);
3104   return JNI_OK;
3105 JNI_END
3106 
3107 
3108 JNI_ENTRY(jobject, jni_GetModule(JNIEnv* env, jclass clazz))
3109   return Modules::get_module(clazz, THREAD);
3110 JNI_END
3111 
3112 JNI_ENTRY(jboolean, jni_IsVirtualThread(JNIEnv* env, jobject obj))
3113   oop thread_obj = JNIHandles::resolve_external_guard(obj);
3114   if (thread_obj != nullptr && thread_obj->is_a(vmClasses::BaseVirtualThread_klass())) {
3115     return JNI_TRUE;
3116   } else {
3117     return JNI_FALSE;
3118   }
3119 JNI_END
3120 
3121 
3122 // Structure containing all jni functions
3123 struct JNINativeInterface_ jni_NativeInterface = {
3124     nullptr,
3125     nullptr,
3126     nullptr,
3127 
3128     nullptr,
3129 
3130     jni_GetVersion,
3131 
3132     jni_DefineClass,
3133     jni_FindClass,
3134 
3135     jni_FromReflectedMethod,
3136     jni_FromReflectedField,
3137 
3138     jni_ToReflectedMethod,
3139 
3140     jni_GetSuperclass,
3141     jni_IsAssignableFrom,
3142 
3143     jni_ToReflectedField,
3144 
3145     jni_Throw,
3146     jni_ThrowNew,
3147     jni_ExceptionOccurred,
3148     jni_ExceptionDescribe,
3149     jni_ExceptionClear,
3150     jni_FatalError,
3151 
3152     jni_PushLocalFrame,
3153     jni_PopLocalFrame,
3154 
3155     jni_NewGlobalRef,
3156     jni_DeleteGlobalRef,
3157     jni_DeleteLocalRef,
3158     jni_IsSameObject,
3159 
3160     jni_NewLocalRef,
3161     jni_EnsureLocalCapacity,
3162 
3163     jni_AllocObject,
3164     jni_NewObject,
3165     jni_NewObjectV,
3166     jni_NewObjectA,
3167 
3168     jni_GetObjectClass,
3169     jni_IsInstanceOf,
3170 
3171     jni_GetMethodID,
3172 
3173     jni_CallObjectMethod,
3174     jni_CallObjectMethodV,
3175     jni_CallObjectMethodA,
3176     jni_CallBooleanMethod,
3177     jni_CallBooleanMethodV,
3178     jni_CallBooleanMethodA,
3179     jni_CallByteMethod,
3180     jni_CallByteMethodV,
3181     jni_CallByteMethodA,
3182     jni_CallCharMethod,
3183     jni_CallCharMethodV,
3184     jni_CallCharMethodA,
3185     jni_CallShortMethod,
3186     jni_CallShortMethodV,
3187     jni_CallShortMethodA,
3188     jni_CallIntMethod,
3189     jni_CallIntMethodV,
3190     jni_CallIntMethodA,
3191     jni_CallLongMethod,
3192     jni_CallLongMethodV,
3193     jni_CallLongMethodA,
3194     jni_CallFloatMethod,
3195     jni_CallFloatMethodV,
3196     jni_CallFloatMethodA,
3197     jni_CallDoubleMethod,
3198     jni_CallDoubleMethodV,
3199     jni_CallDoubleMethodA,
3200     jni_CallVoidMethod,
3201     jni_CallVoidMethodV,
3202     jni_CallVoidMethodA,
3203 
3204     jni_CallNonvirtualObjectMethod,
3205     jni_CallNonvirtualObjectMethodV,
3206     jni_CallNonvirtualObjectMethodA,
3207     jni_CallNonvirtualBooleanMethod,
3208     jni_CallNonvirtualBooleanMethodV,
3209     jni_CallNonvirtualBooleanMethodA,
3210     jni_CallNonvirtualByteMethod,
3211     jni_CallNonvirtualByteMethodV,
3212     jni_CallNonvirtualByteMethodA,
3213     jni_CallNonvirtualCharMethod,
3214     jni_CallNonvirtualCharMethodV,
3215     jni_CallNonvirtualCharMethodA,
3216     jni_CallNonvirtualShortMethod,
3217     jni_CallNonvirtualShortMethodV,
3218     jni_CallNonvirtualShortMethodA,
3219     jni_CallNonvirtualIntMethod,
3220     jni_CallNonvirtualIntMethodV,
3221     jni_CallNonvirtualIntMethodA,
3222     jni_CallNonvirtualLongMethod,
3223     jni_CallNonvirtualLongMethodV,
3224     jni_CallNonvirtualLongMethodA,
3225     jni_CallNonvirtualFloatMethod,
3226     jni_CallNonvirtualFloatMethodV,
3227     jni_CallNonvirtualFloatMethodA,
3228     jni_CallNonvirtualDoubleMethod,
3229     jni_CallNonvirtualDoubleMethodV,
3230     jni_CallNonvirtualDoubleMethodA,
3231     jni_CallNonvirtualVoidMethod,
3232     jni_CallNonvirtualVoidMethodV,
3233     jni_CallNonvirtualVoidMethodA,
3234 
3235     jni_GetFieldID,
3236 
3237     jni_GetObjectField,
3238     jni_GetBooleanField,
3239     jni_GetByteField,
3240     jni_GetCharField,
3241     jni_GetShortField,
3242     jni_GetIntField,
3243     jni_GetLongField,
3244     jni_GetFloatField,
3245     jni_GetDoubleField,
3246 
3247     jni_SetObjectField,
3248     jni_SetBooleanField,
3249     jni_SetByteField,
3250     jni_SetCharField,
3251     jni_SetShortField,
3252     jni_SetIntField,
3253     jni_SetLongField,
3254     jni_SetFloatField,
3255     jni_SetDoubleField,
3256 
3257     jni_GetStaticMethodID,
3258 
3259     jni_CallStaticObjectMethod,
3260     jni_CallStaticObjectMethodV,
3261     jni_CallStaticObjectMethodA,
3262     jni_CallStaticBooleanMethod,
3263     jni_CallStaticBooleanMethodV,
3264     jni_CallStaticBooleanMethodA,
3265     jni_CallStaticByteMethod,
3266     jni_CallStaticByteMethodV,
3267     jni_CallStaticByteMethodA,
3268     jni_CallStaticCharMethod,
3269     jni_CallStaticCharMethodV,
3270     jni_CallStaticCharMethodA,
3271     jni_CallStaticShortMethod,
3272     jni_CallStaticShortMethodV,
3273     jni_CallStaticShortMethodA,
3274     jni_CallStaticIntMethod,
3275     jni_CallStaticIntMethodV,
3276     jni_CallStaticIntMethodA,
3277     jni_CallStaticLongMethod,
3278     jni_CallStaticLongMethodV,
3279     jni_CallStaticLongMethodA,
3280     jni_CallStaticFloatMethod,
3281     jni_CallStaticFloatMethodV,
3282     jni_CallStaticFloatMethodA,
3283     jni_CallStaticDoubleMethod,
3284     jni_CallStaticDoubleMethodV,
3285     jni_CallStaticDoubleMethodA,
3286     jni_CallStaticVoidMethod,
3287     jni_CallStaticVoidMethodV,
3288     jni_CallStaticVoidMethodA,
3289 
3290     jni_GetStaticFieldID,
3291 
3292     jni_GetStaticObjectField,
3293     jni_GetStaticBooleanField,
3294     jni_GetStaticByteField,
3295     jni_GetStaticCharField,
3296     jni_GetStaticShortField,
3297     jni_GetStaticIntField,
3298     jni_GetStaticLongField,
3299     jni_GetStaticFloatField,
3300     jni_GetStaticDoubleField,
3301 
3302     jni_SetStaticObjectField,
3303     jni_SetStaticBooleanField,
3304     jni_SetStaticByteField,
3305     jni_SetStaticCharField,
3306     jni_SetStaticShortField,
3307     jni_SetStaticIntField,
3308     jni_SetStaticLongField,
3309     jni_SetStaticFloatField,
3310     jni_SetStaticDoubleField,
3311 
3312     jni_NewString,
3313     jni_GetStringLength,
3314     jni_GetStringChars,
3315     jni_ReleaseStringChars,
3316 
3317     jni_NewStringUTF,
3318     jni_GetStringUTFLength,
3319     jni_GetStringUTFChars,
3320     jni_ReleaseStringUTFChars,
3321 
3322     jni_GetArrayLength,
3323 
3324     jni_NewObjectArray,
3325     jni_GetObjectArrayElement,
3326     jni_SetObjectArrayElement,
3327 
3328     jni_NewBooleanArray,
3329     jni_NewByteArray,
3330     jni_NewCharArray,
3331     jni_NewShortArray,
3332     jni_NewIntArray,
3333     jni_NewLongArray,
3334     jni_NewFloatArray,
3335     jni_NewDoubleArray,
3336 
3337     jni_GetBooleanArrayElements,
3338     jni_GetByteArrayElements,
3339     jni_GetCharArrayElements,
3340     jni_GetShortArrayElements,
3341     jni_GetIntArrayElements,
3342     jni_GetLongArrayElements,
3343     jni_GetFloatArrayElements,
3344     jni_GetDoubleArrayElements,
3345 
3346     jni_ReleaseBooleanArrayElements,
3347     jni_ReleaseByteArrayElements,
3348     jni_ReleaseCharArrayElements,
3349     jni_ReleaseShortArrayElements,
3350     jni_ReleaseIntArrayElements,
3351     jni_ReleaseLongArrayElements,
3352     jni_ReleaseFloatArrayElements,
3353     jni_ReleaseDoubleArrayElements,
3354 
3355     jni_GetBooleanArrayRegion,
3356     jni_GetByteArrayRegion,
3357     jni_GetCharArrayRegion,
3358     jni_GetShortArrayRegion,
3359     jni_GetIntArrayRegion,
3360     jni_GetLongArrayRegion,
3361     jni_GetFloatArrayRegion,
3362     jni_GetDoubleArrayRegion,
3363 
3364     jni_SetBooleanArrayRegion,
3365     jni_SetByteArrayRegion,
3366     jni_SetCharArrayRegion,
3367     jni_SetShortArrayRegion,
3368     jni_SetIntArrayRegion,
3369     jni_SetLongArrayRegion,
3370     jni_SetFloatArrayRegion,
3371     jni_SetDoubleArrayRegion,
3372 
3373     jni_RegisterNatives,
3374     jni_UnregisterNatives,
3375 
3376     jni_MonitorEnter,
3377     jni_MonitorExit,
3378 
3379     jni_GetJavaVM,
3380 
3381     jni_GetStringRegion,
3382     jni_GetStringUTFRegion,
3383 
3384     jni_GetPrimitiveArrayCritical,
3385     jni_ReleasePrimitiveArrayCritical,
3386 
3387     jni_GetStringCritical,
3388     jni_ReleaseStringCritical,
3389 
3390     jni_NewWeakGlobalRef,
3391     jni_DeleteWeakGlobalRef,
3392 
3393     jni_ExceptionCheck,
3394 
3395     jni_NewDirectByteBuffer,
3396     jni_GetDirectBufferAddress,
3397     jni_GetDirectBufferCapacity,
3398 
3399     // New 1_6 features
3400 
3401     jni_GetObjectRefType,
3402 
3403     // Module features
3404 
3405     jni_GetModule,
3406 
3407     // Virtual threads
3408 
3409     jni_IsVirtualThread,
3410 
3411     // Large UTF8 support
3412 
3413     jni_GetStringUTFLengthAsLong
3414 };
3415 
3416 
3417 // For jvmti use to modify jni function table.
3418 // Java threads in native contiues to run until it is transitioned
3419 // to VM at safepoint. Before the transition or before it is blocked
3420 // for safepoint it may access jni function table. VM could crash if
3421 // any java thread access the jni function table in the middle of memcpy.
3422 // To avoid this each function pointers are copied automically.
3423 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) {
3424   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
3425   intptr_t *a = (intptr_t *) jni_functions();
3426   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
3427   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
3428     Atomic::store(a++, *b++);
3429   }
3430 }
3431 
3432 void quicken_jni_functions() {
3433   // Replace Get<Primitive>Field with fast versions
3434   if (UseFastJNIAccessors && !VerifyJNIFields && !CheckJNICalls) {
3435     address func;
3436     func = JNI_FastGetField::generate_fast_get_boolean_field();
3437     if (func != (address)-1) {
3438       jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func;
3439     }
3440     func = JNI_FastGetField::generate_fast_get_byte_field();
3441     if (func != (address)-1) {
3442       jni_NativeInterface.GetByteField = (GetByteField_t)func;
3443     }
3444     func = JNI_FastGetField::generate_fast_get_char_field();
3445     if (func != (address)-1) {
3446       jni_NativeInterface.GetCharField = (GetCharField_t)func;
3447     }
3448     func = JNI_FastGetField::generate_fast_get_short_field();
3449     if (func != (address)-1) {
3450       jni_NativeInterface.GetShortField = (GetShortField_t)func;
3451     }
3452     func = JNI_FastGetField::generate_fast_get_int_field();
3453     if (func != (address)-1) {
3454       jni_NativeInterface.GetIntField = (GetIntField_t)func;
3455     }
3456     func = JNI_FastGetField::generate_fast_get_long_field();
3457     if (func != (address)-1) {
3458       jni_NativeInterface.GetLongField = (GetLongField_t)func;
3459     }
3460     func = JNI_FastGetField::generate_fast_get_float_field();
3461     if (func != (address)-1) {
3462       jni_NativeInterface.GetFloatField = (GetFloatField_t)func;
3463     }
3464     func = JNI_FastGetField::generate_fast_get_double_field();
3465     if (func != (address)-1) {
3466       jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func;
3467     }
3468   }
3469 }
3470 
3471 // Returns the function structure
3472 struct JNINativeInterface_* jni_functions() {
3473 #if INCLUDE_JNI_CHECK
3474   if (CheckJNICalls) return jni_functions_check();
3475 #endif // INCLUDE_JNI_CHECK
3476   return &jni_NativeInterface;
3477 }
3478 
3479 // Returns the function structure
3480 struct JNINativeInterface_* jni_functions_nocheck() {
3481   return &jni_NativeInterface;
3482 }
3483 
3484 
3485 // Invocation API
3486 
3487 
3488 // Forward declaration
3489 extern const struct JNIInvokeInterface_ jni_InvokeInterface;
3490 
3491 // Global invocation API vars
3492 enum VM_Creation_State {
3493   NOT_CREATED = 0,
3494   IN_PROGRESS,  // Most JNI operations are permitted during this phase to
3495                 // allow for initialization actions by libraries and agents.
3496   COMPLETE
3497 };
3498 
3499 volatile VM_Creation_State vm_created = NOT_CREATED;
3500 
3501 // Indicate whether it is safe to recreate VM. Recreation is only
3502 // possible after a failed initial creation attempt in some cases.
3503 volatile int safe_to_recreate_vm = 1;
3504 struct JavaVM_ main_vm = {&jni_InvokeInterface};
3505 
3506 
3507 #define JAVASTACKSIZE (400 * 1024)    /* Default size of a thread java stack */
3508 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL };
3509 
3510 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint
3511                     , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref));
3512 
3513 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) {
3514   HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY(args_);
3515   JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_;
3516   jint ret = JNI_ERR;
3517   DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret);
3518 
3519   if (Threads::is_supported_jni_version(args->version)) {
3520     ret = JNI_OK;
3521   }
3522   // 1.1 style no longer supported in hotspot.
3523   // According the JNI spec, we should update args->version on return.
3524   // We also use the structure to communicate with launcher about default
3525   // stack size.
3526   if (args->version == JNI_VERSION_1_1) {
3527     args->version = JNI_VERSION_1_2;
3528     // javaStackSize is int in arguments structure
3529     assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow");
3530     args->javaStackSize = (jint)(ThreadStackSize * K);
3531   }
3532   return ret;
3533 }
3534 
3535 DT_RETURN_MARK_DECL(CreateJavaVM, jint
3536                     , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref));
3537 
3538 static jint JNI_CreateJavaVM_inner(JavaVM **vm, void **penv, void *args) {
3539   HOTSPOT_JNI_CREATEJAVAVM_ENTRY((void **) vm, penv, args);
3540 
3541   jint result = JNI_ERR;
3542   DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result);
3543 
3544   // We're about to use Atomic::xchg for synchronization.  Some Zero
3545   // platforms use the GCC builtin __sync_lock_test_and_set for this,
3546   // but __sync_lock_test_and_set is not guaranteed to do what we want
3547   // on all architectures.  So we check it works before relying on it.
3548 #if defined(ZERO) && defined(ASSERT)
3549   {
3550     jint a = 0xcafebabe;
3551     jint b = Atomic::xchg(&a, (jint) 0xdeadbeef);
3552     void *c = &a;
3553     void *d = Atomic::xchg(&c, &b);
3554     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
3555     assert(c == &b && d == &a, "Atomic::xchg() works");
3556   }
3557 #endif // ZERO && ASSERT
3558 
3559   // At the moment it's only possible to have one Java VM,
3560   // since some of the runtime state is in global variables.
3561 
3562   // We cannot use our mutex locks here, since they only work on
3563   // Threads. We do an atomic compare and exchange to ensure only
3564   // one thread can call this method at a time
3565 
3566   // We use Atomic::xchg rather than Atomic::add/dec since on some platforms
3567   // the add/dec implementations are dependent on whether we are running
3568   // on a multiprocessor Atomic::xchg does not have this problem.
3569   if (Atomic::xchg(&vm_created, IN_PROGRESS) != NOT_CREATED) {
3570     return JNI_EEXIST;   // already created, or create attempt in progress
3571   }
3572 
3573   // If a previous creation attempt failed but can be retried safely,
3574   // then safe_to_recreate_vm will have been reset to 1 after being
3575   // cleared here. If a previous creation attempt succeeded and we then
3576   // destroyed that VM, we will be prevented from trying to recreate
3577   // the VM in the same process, as the value will still be 0.
3578   if (Atomic::xchg(&safe_to_recreate_vm, 0) == 0) {
3579     return JNI_ERR;
3580   }
3581 
3582   /**
3583    * Certain errors during initialization are recoverable and do not
3584    * prevent this method from being called again at a later time
3585    * (perhaps with different arguments).  However, at a certain
3586    * point during initialization if an error occurs we cannot allow
3587    * this function to be called again (or it will crash).  In those
3588    * situations, the 'canTryAgain' flag is set to false, which atomically
3589    * sets safe_to_recreate_vm to 1, such that any new call to
3590    * JNI_CreateJavaVM will immediately fail using the above logic.
3591    */
3592   bool can_try_again = true;
3593 
3594   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
3595   if (result == JNI_OK) {
3596     JavaThread *thread = JavaThread::current();
3597     assert(!thread->has_pending_exception(), "should have returned not OK");
3598     // thread is thread_in_vm here
3599     *vm = (JavaVM *)(&main_vm);
3600     *(JNIEnv**)penv = thread->jni_environment();
3601     // mark creation complete for other JNI ops
3602     Atomic::release_store(&vm_created, COMPLETE);
3603 
3604 #if INCLUDE_JVMCI
3605     if (EnableJVMCI) {
3606       if (UseJVMCICompiler) {
3607         // JVMCI is initialized on a CompilerThread
3608         if (BootstrapJVMCI) {
3609           JavaThread* THREAD = thread; // For exception macros.
3610           JVMCICompiler* compiler = JVMCICompiler::instance(true, CATCH);
3611           compiler->bootstrap(THREAD);
3612           if (HAS_PENDING_EXCEPTION) {
3613             HandleMark hm(THREAD);
3614             vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3615           }
3616         }
3617       }
3618     }
3619 #endif
3620 
3621     // Notify JVMTI
3622     if (JvmtiExport::should_post_thread_life()) {
3623        JvmtiExport::post_thread_start(thread);
3624     }
3625 
3626     JFR_ONLY(Jfr::on_thread_start(thread);)
3627 
3628     if (ReplayCompiles) ciReplay::replay(thread);
3629 
3630 #ifdef ASSERT
3631     // Some platforms (like Win*) need a wrapper around these test
3632     // functions in order to properly handle error conditions.
3633     if (ErrorHandlerTest != 0) {
3634       VMError::controlled_crash(ErrorHandlerTest);
3635     }
3636 #endif
3637 
3638     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
3639     ThreadStateTransition::transition_from_vm(thread, _thread_in_native);
3640     MACOS_AARCH64_ONLY(thread->enable_wx(WXExec));
3641   } else {
3642     // If create_vm exits because of a pending exception, exit with that
3643     // exception.  In the future when we figure out how to reclaim memory,
3644     // we may be able to exit with JNI_ERR and allow the calling application
3645     // to continue.
3646     if (Universe::is_fully_initialized()) {
3647       // otherwise no pending exception possible - VM will already have aborted
3648       Thread* current = Thread::current_or_null();
3649       if (current != nullptr) {
3650         JavaThread* THREAD = JavaThread::cast(current); // For exception macros.
3651         assert(HAS_PENDING_EXCEPTION, "must be - else no current thread exists");
3652         HandleMark hm(THREAD);
3653         vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3654       }
3655     }
3656 
3657     if (can_try_again) {
3658       // reset safe_to_recreate_vm to 1 so that retrial would be possible
3659       safe_to_recreate_vm = 1;
3660     }
3661 
3662     // Creation failed. We must reset vm_created
3663     *vm = nullptr;
3664     *(JNIEnv**)penv = nullptr;
3665     // reset vm_created last to avoid race condition. Use OrderAccess to
3666     // control both compiler and architectural-based reordering.
3667     assert(vm_created == IN_PROGRESS, "must be");
3668     Atomic::release_store(&vm_created, NOT_CREATED);
3669   }
3670 
3671   // Flush stdout and stderr before exit.
3672   fflush(stdout);
3673   fflush(stderr);
3674 
3675   return result;
3676 
3677 }
3678 
3679 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
3680   jint result = JNI_ERR;
3681   // On Windows, let CreateJavaVM run with SEH protection
3682 #if defined(_WIN32) && !defined(USE_VECTORED_EXCEPTION_HANDLING)
3683   __try {
3684 #endif
3685     result = JNI_CreateJavaVM_inner(vm, penv, args);
3686 #if defined(_WIN32) && !defined(USE_VECTORED_EXCEPTION_HANDLING)
3687   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
3688     // Nothing to do.
3689   }
3690 #endif
3691   return result;
3692 }
3693 
3694 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) {
3695   HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY((void **) vm_buf, bufLen, (uintptr_t *) numVMs);
3696 
3697   if (vm_created == COMPLETE) {
3698     if (numVMs != nullptr) *numVMs = 1;
3699     if (bufLen > 0)     *vm_buf = (JavaVM *)(&main_vm);
3700   } else {
3701     if (numVMs != nullptr) *numVMs = 0;
3702   }
3703   HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN(JNI_OK);
3704   return JNI_OK;
3705 }
3706 
3707 extern "C" {
3708 
3709 DT_RETURN_MARK_DECL(DestroyJavaVM, jint
3710                     , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref));
3711 
3712 static jint JNICALL jni_DestroyJavaVM_inner(JavaVM *vm) {
3713   HOTSPOT_JNI_DESTROYJAVAVM_ENTRY(vm);
3714   jint res = JNI_ERR;
3715   DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res);
3716 
3717   if (vm_created == NOT_CREATED) {
3718     res = JNI_ERR;
3719     return res;
3720   }
3721 
3722   JNIEnv *env;
3723   JavaVMAttachArgs destroyargs;
3724   destroyargs.version = CurrentVersion;
3725   destroyargs.name = (char *)"DestroyJavaVM";
3726   destroyargs.group = nullptr;
3727   res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs);
3728   if (res != JNI_OK) {
3729     return res;
3730   }
3731 
3732   JavaThread* thread = JavaThread::current();
3733 
3734   // Make sure we are actually in a newly attached thread, with no
3735   // existing Java frame.
3736   if (thread->has_last_Java_frame()) {
3737     return JNI_ERR;
3738   }
3739 
3740   // Since this is not a JVM_ENTRY we have to set the thread state manually before entering.
3741 
3742   // We are going to VM, change W^X state to the expected one.
3743   MACOS_AARCH64_ONLY(WXMode oldmode = thread->enable_wx(WXWrite));
3744 
3745   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
3746   Threads::destroy_vm();
3747   // Don't bother restoring thread state, VM is gone.
3748   vm_created = NOT_CREATED;
3749   return JNI_OK;
3750 }
3751 
3752 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
3753   jint result = JNI_ERR;
3754   // On Windows, we need SEH protection
3755 #if defined(_WIN32) && !defined(USE_VECTORED_EXCEPTION_HANDLING)
3756   __try {
3757 #endif
3758     result = jni_DestroyJavaVM_inner(vm);
3759 #if defined(_WIN32) && !defined(USE_VECTORED_EXCEPTION_HANDLING)
3760   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
3761     // Nothing to do.
3762   }
3763 #endif
3764   return result;
3765 }
3766 
3767 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) {
3768   JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args;
3769 
3770   // Check below commented out from JDK1.2fcs as well
3771   /*
3772   if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) {
3773     return JNI_EVERSION;
3774   }
3775   */
3776 
3777   Thread* t = Thread::current_or_null();
3778   if (t != nullptr) {
3779     // If executing from an atexit hook we may be in the VMThread.
3780     if (t->is_Java_thread()) {
3781       // If the thread has been attached this operation is a no-op
3782       *(JNIEnv**)penv = JavaThread::cast(t)->jni_environment();
3783       return JNI_OK;
3784     } else {
3785       return JNI_ERR;
3786     }
3787   }
3788 
3789   // Create a thread and mark it as attaching so it will be skipped by the
3790   // ThreadsListEnumerator - see CR 6404306
3791   JavaThread* thread = JavaThread::create_attaching_thread();
3792 
3793   // Set correct safepoint info. The thread is going to call into Java when
3794   // initializing the Java level thread object. Hence, the correct state must
3795   // be set in order for the Safepoint code to deal with it correctly.
3796   thread->set_thread_state(_thread_in_vm);
3797   thread->record_stack_base_and_size();
3798   thread->register_thread_stack_with_NMT();
3799   thread->initialize_thread_current();
3800   MACOS_AARCH64_ONLY(thread->init_wx());
3801 
3802   if (!os::create_attached_thread(thread)) {
3803     thread->smr_delete();
3804     return JNI_ERR;
3805   }
3806   // Enable stack overflow checks
3807   thread->stack_overflow_state()->create_stack_guard_pages();
3808 
3809   thread->initialize_tlab();
3810 
3811   thread->cache_global_variables();
3812 
3813   // This thread will not do a safepoint check, since it has
3814   // not been added to the Thread list yet.
3815   { MutexLocker ml(Threads_lock);
3816     // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
3817     // avoid this thread trying to do a GC before it is added to the thread-list
3818     thread->set_active_handles(JNIHandleBlock::allocate_block());
3819     Threads::add(thread, daemon);
3820   }
3821   // Create thread group and name info from attach arguments
3822   oop group = nullptr;
3823   char* thread_name = nullptr;
3824   if (args != nullptr && Threads::is_supported_jni_version(args->version)) {
3825     group = JNIHandles::resolve(args->group);
3826     thread_name = args->name; // may be null
3827   }
3828   if (group == nullptr) group = Universe::main_thread_group();
3829 
3830   // Create Java level thread object and attach it to this thread
3831   bool attach_failed = false;
3832   {
3833     EXCEPTION_MARK;
3834     HandleMark hm(THREAD);
3835     Handle thread_group(THREAD, group);
3836     thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD);
3837     if (HAS_PENDING_EXCEPTION) {
3838       CLEAR_PENDING_EXCEPTION;
3839       // cleanup outside the handle mark.
3840       attach_failed = true;
3841     }
3842   }
3843 
3844   if (attach_failed) {
3845     // Added missing cleanup
3846     thread->cleanup_failed_attach_current_thread(daemon);
3847     return JNI_ERR;
3848   }
3849 
3850   // mark the thread as no longer attaching
3851   // this uses a fence to push the change through so we don't have
3852   // to regrab the threads_lock
3853   thread->set_done_attaching_via_jni();
3854 
3855   // Set java thread status.
3856   java_lang_Thread::set_thread_status(thread->threadObj(),
3857               JavaThreadStatus::RUNNABLE);
3858 
3859   // Notify the debugger
3860   if (JvmtiExport::should_post_thread_life()) {
3861     JvmtiExport::post_thread_start(thread);
3862   }
3863 
3864   JFR_ONLY(Jfr::on_thread_start(thread);)
3865 
3866   *(JNIEnv**)penv = thread->jni_environment();
3867 
3868   // Now leaving the VM, so change thread_state. This is normally automatically taken care
3869   // of in the JVM_ENTRY. But in this situation we have to do it manually.
3870   ThreadStateTransition::transition_from_vm(thread, _thread_in_native);
3871   MACOS_AARCH64_ONLY(thread->enable_wx(WXExec));
3872 
3873   // Perform any platform dependent FPU setup
3874   os::setup_fpu();
3875 
3876   return JNI_OK;
3877 }
3878 
3879 
3880 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
3881   HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(vm, penv, _args);
3882   if (vm_created == NOT_CREATED) {
3883     // Not sure how we could possibly get here.
3884     HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
3885     return JNI_ERR;
3886   }
3887 
3888   jint ret = attach_current_thread(vm, penv, _args, false);
3889   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(ret);
3890   return ret;
3891 }
3892 
3893 
3894 jint JNICALL jni_DetachCurrentThread(JavaVM *vm)  {
3895   HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(vm);
3896   if (vm_created == NOT_CREATED) {
3897     // Not sure how we could possibly get here.
3898     HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_ERR);
3899     return JNI_ERR;
3900   }
3901 
3902   Thread* current = Thread::current_or_null();
3903 
3904   // If the thread has already been detached the operation is a no-op
3905   if (current == nullptr) {
3906     HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
3907     return JNI_OK;
3908   }
3909 
3910   // If executing from an atexit hook we may be in the VMThread.
3911   if (!current->is_Java_thread()) {
3912     HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
3913     return JNI_ERR;
3914   }
3915 
3916   VM_Exit::block_if_vm_exited();
3917 
3918   JavaThread* thread = JavaThread::cast(current);
3919   if (thread->has_last_Java_frame()) {
3920     HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
3921     // Can't detach a thread that's running java, that can't work.
3922     return JNI_ERR;
3923   }
3924 
3925   // We are going to VM, change W^X state to the expected one.
3926   MACOS_AARCH64_ONLY(thread->enable_wx(WXWrite));
3927 
3928   // Safepoint support. Have to do call-back to safepoint code, if in the
3929   // middle of a safepoint operation
3930   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
3931 
3932   // XXX: Note that JavaThread::exit() call below removes the guards on the
3933   // stack pages set up via enable_stack_{red,yellow}_zone() calls
3934   // above in jni_AttachCurrentThread. Unfortunately, while the setting
3935   // of the guards is visible in jni_AttachCurrentThread above,
3936   // the removal of the guards is buried below in JavaThread::exit()
3937   // here. The abstraction should be more symmetrically either exposed
3938   // or hidden (e.g. it could probably be hidden in the same
3939   // (platform-dependent) methods where we do alternate stack
3940   // maintenance work?)
3941   thread->exit(false, JavaThread::jni_detach);
3942   thread->smr_delete();
3943 
3944   // Go to the execute mode, the initial state of the thread on creation.
3945   // Use os interface as the thread is not a JavaThread anymore.
3946   MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXExec));
3947 
3948   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
3949   return JNI_OK;
3950 }
3951 
3952 DT_RETURN_MARK_DECL(GetEnv, jint
3953                     , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
3954 
3955 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
3956   HOTSPOT_JNI_GETENV_ENTRY(vm, penv, version);
3957   jint ret = JNI_ERR;
3958   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
3959 
3960   if (vm_created == NOT_CREATED) {
3961     *penv = nullptr;
3962     ret = JNI_EDETACHED;
3963     return ret;
3964   }
3965 
3966   if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {
3967     return ret;
3968   }
3969 
3970 #ifndef JVMPI_VERSION_1
3971 // need these in order to be polite about older agents
3972 #define JVMPI_VERSION_1   ((jint)0x10000001)
3973 #define JVMPI_VERSION_1_1 ((jint)0x10000002)
3974 #define JVMPI_VERSION_1_2 ((jint)0x10000003)
3975 #endif // !JVMPI_VERSION_1
3976 
3977   Thread* thread = Thread::current_or_null();
3978   if (thread != nullptr && thread->is_Java_thread()) {
3979     if (Threads::is_supported_jni_version_including_1_1(version)) {
3980       *(JNIEnv**)penv = JavaThread::cast(thread)->jni_environment();
3981       ret = JNI_OK;
3982       return ret;
3983 
3984     } else if (version == JVMPI_VERSION_1 ||
3985                version == JVMPI_VERSION_1_1 ||
3986                version == JVMPI_VERSION_1_2) {
3987       tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported.");
3988       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
3989       ret = JNI_EVERSION;
3990       return ret;
3991     } else if (JvmtiExport::is_jvmdi_version(version)) {
3992       tty->print_cr("FATAL ERROR: JVMDI is no longer supported.");
3993       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
3994       ret = JNI_EVERSION;
3995       return ret;
3996     } else {
3997       *penv = nullptr;
3998       ret = JNI_EVERSION;
3999       return ret;
4000     }
4001   } else {
4002     *penv = nullptr;
4003     ret = JNI_EDETACHED;
4004     return ret;
4005   }
4006 }
4007 
4008 
4009 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) {
4010   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY(vm, penv, _args);
4011   if (vm_created == NOT_CREATED) {
4012     // Not sure how we could possibly get here.
4013     HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN((uint32_t) JNI_ERR);
4014     return JNI_ERR;
4015   }
4016 
4017   jint ret = attach_current_thread(vm, penv, _args, true);
4018   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(ret);
4019   return ret;
4020 }
4021 
4022 
4023 } // End extern "C"
4024 
4025 const struct JNIInvokeInterface_ jni_InvokeInterface = {
4026     nullptr,
4027     nullptr,
4028     nullptr,
4029 
4030     jni_DestroyJavaVM,
4031     jni_AttachCurrentThread,
4032     jni_DetachCurrentThread,
4033     jni_GetEnv,
4034     jni_AttachCurrentThreadAsDaemon
4035 };