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