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