rev 49674 : 8198285: More consistent Access API for arraycopy

   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012 Red Hat, Inc.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "jni.h"
  28 #include "jvm.h"
  29 #include "ci/ciReplay.hpp"
  30 #include "classfile/altHashing.hpp"
  31 #include "classfile/classFileStream.hpp"
  32 #include "classfile/classLoader.hpp"
  33 #include "classfile/javaClasses.hpp"
  34 #include "classfile/javaClasses.inline.hpp"
  35 #include "classfile/modules.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "gc/shared/gcLocker.inline.hpp"
  40 #include "interpreter/linkResolver.hpp"
  41 #include "memory/allocation.hpp"
  42 #include "memory/allocation.inline.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "memory/universe.hpp"
  46 #include "oops/access.inline.hpp"
  47 #include "oops/arrayOop.inline.hpp"
  48 #include "oops/instanceKlass.hpp"
  49 #include "oops/instanceOop.hpp"
  50 #include "oops/markOop.hpp"
  51 #include "oops/method.hpp"
  52 #include "oops/objArrayKlass.hpp"
  53 #include "oops/objArrayOop.inline.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/symbol.hpp"
  56 #include "oops/typeArrayKlass.hpp"
  57 #include "oops/typeArrayOop.inline.hpp"
  58 #include "prims/jniCheck.hpp"
  59 #include "prims/jniExport.hpp"
  60 #include "prims/jniFastGetField.hpp"
  61 #include "prims/jvm_misc.hpp"
  62 #include "prims/jvmtiExport.hpp"
  63 #include "prims/jvmtiThreadState.hpp"
  64 #include "runtime/atomic.hpp"
  65 #include "runtime/compilationPolicy.hpp"
  66 #include "runtime/fieldDescriptor.hpp"
  67 #include "runtime/handles.inline.hpp"
  68 #include "runtime/interfaceSupport.inline.hpp"
  69 #include "runtime/java.hpp"
  70 #include "runtime/javaCalls.hpp"
  71 #include "runtime/jfieldIDWorkaround.hpp"
  72 #include "runtime/jniHandles.inline.hpp"
  73 #include "runtime/orderAccess.inline.hpp"
  74 #include "runtime/reflection.hpp"
  75 #include "runtime/safepointVerifiers.hpp"
  76 #include "runtime/sharedRuntime.hpp"
  77 #include "runtime/signature.hpp"
  78 #include "runtime/thread.inline.hpp"
  79 #include "runtime/vm_operations.hpp"
  80 #include "services/memTracker.hpp"
  81 #include "services/runtimeService.hpp"
  82 #include "trace/traceMacros.hpp"
  83 #include "trace/tracing.hpp"
  84 #include "utilities/defaultStream.hpp"
  85 #include "utilities/dtrace.hpp"
  86 #include "utilities/events.hpp"
  87 #include "utilities/histogram.hpp"
  88 #include "utilities/internalVMTests.hpp"
  89 #include "utilities/macros.hpp"
  90 #include "utilities/vmError.hpp"
  91 #if INCLUDE_JVMCI
  92 #include "jvmci/jvmciCompiler.hpp"
  93 #include "jvmci/jvmciRuntime.hpp"
  94 #endif
  95 
  96 static jint CurrentVersion = JNI_VERSION_10;
  97 
  98 #ifdef _WIN32
  99 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
 100 #endif
 101 
 102 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 103 // '-return' probe regardless of the return path is taken out of the function.
 104 // Methods that have multiple return paths use this to avoid having to
 105 // instrument each return path.  Methods that use CHECK or THROW must use this
 106 // since those macros can cause an immedate uninstrumented return.
 107 //
 108 // In order to get the return value, a reference to the variable containing
 109 // the return value must be passed to the contructor of the object, and
 110 // the return value must be set before return (since the mark object has
 111 // a reference to it).
 112 //
 113 // Example:
 114 // DT_RETURN_MARK_DECL(SomeFunc, int);
 115 // JNI_ENTRY(int, SomeFunc, ...)
 116 //   int return_value = 0;
 117 //   DT_RETURN_MARK(SomeFunc, int, (const int&)return_value);
 118 //   foo(CHECK_0)
 119 //   return_value = 5;
 120 //   return return_value;
 121 // JNI_END
 122 #define DT_RETURN_MARK_DECL(name, type, probe)                             \
 123   DTRACE_ONLY(                                                             \
 124     class DTraceReturnProbeMark_##name {                                   \
 125      public:                                                               \
 126       const type& _ret_ref;                                                \
 127       DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {}         \
 128       ~DTraceReturnProbeMark_##name() {                                    \
 129         probe;                                                             \
 130       }                                                                    \
 131     }                                                                      \
 132   )
 133 // Void functions are simpler since there's no return value
 134 #define DT_VOID_RETURN_MARK_DECL(name, probe)                              \
 135   DTRACE_ONLY(                                                             \
 136     class DTraceReturnProbeMark_##name {                                   \
 137      public:                                                               \
 138       ~DTraceReturnProbeMark_##name() {                                    \
 139         probe;                                                             \
 140       }                                                                    \
 141     }                                                                      \
 142   )
 143 
 144 // Place these macros in the function to mark the return.  Non-void
 145 // functions need the type and address of the return value.
 146 #define DT_RETURN_MARK(name, type, ref) \
 147   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) )
 148 #define DT_VOID_RETURN_MARK(name) \
 149   DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark )
 150 
 151 
 152 // Use these to select distinct code for floating-point vs. non-floating point
 153 // situations.  Used from within common macros where we need slightly
 154 // different behavior for Float/Double
 155 #define FP_SELECT_Boolean(intcode, fpcode) intcode
 156 #define FP_SELECT_Byte(intcode, fpcode)    intcode
 157 #define FP_SELECT_Char(intcode, fpcode)    intcode
 158 #define FP_SELECT_Short(intcode, fpcode)   intcode
 159 #define FP_SELECT_Object(intcode, fpcode)  intcode
 160 #define FP_SELECT_Int(intcode, fpcode)     intcode
 161 #define FP_SELECT_Long(intcode, fpcode)    intcode
 162 #define FP_SELECT_Float(intcode, fpcode)   fpcode
 163 #define FP_SELECT_Double(intcode, fpcode)  fpcode
 164 #define FP_SELECT(TypeName, intcode, fpcode) \
 165   FP_SELECT_##TypeName(intcode, fpcode)
 166 
 167 // Choose DT_RETURN_MARK macros  based on the type: float/double -> void
 168 // (dtrace doesn't do FP yet)
 169 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe)    \
 170   FP_SELECT(TypeName, \
 171     DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) )
 172 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \
 173   FP_SELECT(TypeName, \
 174     DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) )
 175 
 176 
 177 // out-of-line helpers for class jfieldIDWorkaround:
 178 
 179 bool jfieldIDWorkaround::is_valid_jfieldID(Klass* k, jfieldID id) {
 180   if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) {
 181     uintptr_t as_uint = (uintptr_t) id;
 182     intptr_t offset = raw_instance_offset(id);
 183     if (is_checked_jfieldID(id)) {
 184       if (!klass_hash_ok(k, id)) {
 185         return false;
 186       }
 187     }
 188     return InstanceKlass::cast(k)->contains_field_offset(offset);
 189   } else {
 190     JNIid* result = (JNIid*) id;
 191 #ifdef ASSERT
 192     return result != NULL && result->is_static_field_id();
 193 #else
 194     return result != NULL;
 195 #endif
 196   }
 197 }
 198 
 199 
 200 intptr_t jfieldIDWorkaround::encode_klass_hash(Klass* k, intptr_t offset) {
 201   if (offset <= small_offset_mask) {
 202     Klass* field_klass = k;
 203     Klass* super_klass = field_klass->super();
 204     // With compressed oops the most super class with nonstatic fields would
 205     // be the owner of fields embedded in the header.
 206     while (InstanceKlass::cast(super_klass)->has_nonstatic_fields() &&
 207            InstanceKlass::cast(super_klass)->contains_field_offset(offset)) {
 208       field_klass = super_klass;   // super contains the field also
 209       super_klass = field_klass->super();
 210     }
 211     debug_only(NoSafepointVerifier nosafepoint;)
 212     uintptr_t klass_hash = field_klass->identity_hash();
 213     return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place;
 214   } else {
 215 #if 0
 216     #ifndef PRODUCT
 217     {
 218       ResourceMark rm;
 219       warning("VerifyJNIFields: long offset %d in %s", offset, k->external_name());
 220     }
 221     #endif
 222 #endif
 223     return 0;
 224   }
 225 }
 226 
 227 bool jfieldIDWorkaround::klass_hash_ok(Klass* k, jfieldID id) {
 228   uintptr_t as_uint = (uintptr_t) id;
 229   intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask;
 230   do {
 231     debug_only(NoSafepointVerifier nosafepoint;)
 232     // Could use a non-blocking query for identity_hash here...
 233     if ((k->identity_hash() & klass_mask) == klass_hash)
 234       return true;
 235     k = k->super();
 236   } while (k != NULL);
 237   return false;
 238 }
 239 
 240 void jfieldIDWorkaround::verify_instance_jfieldID(Klass* k, jfieldID id) {
 241   guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" );
 242   uintptr_t as_uint = (uintptr_t) id;
 243   intptr_t offset = raw_instance_offset(id);
 244   if (VerifyJNIFields) {
 245     if (is_checked_jfieldID(id)) {
 246       guarantee(klass_hash_ok(k, id),
 247     "Bug in native code: jfieldID class must match object");
 248     } else {
 249 #if 0
 250       #ifndef PRODUCT
 251       if (Verbose) {
 252   ResourceMark rm;
 253   warning("VerifyJNIFields: unverified offset %d for %s", offset, k->external_name());
 254       }
 255       #endif
 256 #endif
 257     }
 258   }
 259   guarantee(InstanceKlass::cast(k)->contains_field_offset(offset),
 260       "Bug in native code: jfieldID offset must address interior of object");
 261 }
 262 
 263 // Wrapper to trace JNI functions
 264 
 265 #ifdef ASSERT
 266   Histogram* JNIHistogram;
 267   static volatile int JNIHistogram_lock = 0;
 268 
 269   class JNIHistogramElement : public HistogramElement {
 270     public:
 271      JNIHistogramElement(const char* name);
 272   };
 273 
 274   JNIHistogramElement::JNIHistogramElement(const char* elementName) {
 275     _name = elementName;
 276     uintx count = 0;
 277 
 278     while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) {
 279       while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) {
 280         count +=1;
 281         if ( (WarnOnStalledSpinLock > 0)
 282           && (count % WarnOnStalledSpinLock == 0)) {
 283           warning("JNIHistogram_lock seems to be stalled");
 284         }
 285       }
 286      }
 287 
 288 
 289     if(JNIHistogram == NULL)
 290       JNIHistogram = new Histogram("JNI Call Counts",100);
 291 
 292     JNIHistogram->add_element(this);
 293     Atomic::dec(&JNIHistogram_lock);
 294   }
 295 
 296   #define JNICountWrapper(arg)                                     \
 297      static JNIHistogramElement* e = new JNIHistogramElement(arg); \
 298       /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \
 299      if (e != NULL) e->increment_count()
 300   #define JNIWrapper(arg) JNICountWrapper(arg);
 301 #else
 302   #define JNIWrapper(arg)
 303 #endif
 304 
 305 
 306 // Implementation of JNI entries
 307 
 308 DT_RETURN_MARK_DECL(DefineClass, jclass
 309                     , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref));
 310 
 311 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef,
 312                                   const jbyte *buf, jsize bufLen))
 313   JNIWrapper("DefineClass");
 314 
 315   HOTSPOT_JNI_DEFINECLASS_ENTRY(
 316     env, (char*) name, loaderRef, (char*) buf, bufLen);
 317 
 318   jclass cls = NULL;
 319   DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls);
 320 
 321   TempNewSymbol class_name = NULL;
 322   // Since exceptions can be thrown, class initialization can take place
 323   // if name is NULL no check for class name in .class stream has to be made.
 324   if (name != NULL) {
 325     const int str_len = (int)strlen(name);
 326     if (str_len > Symbol::max_length()) {
 327       // It's impossible to create this class;  the name cannot fit
 328       // into the constant pool.
 329       Exceptions::fthrow(THREAD_AND_LOCATION,
 330                          vmSymbols::java_lang_NoClassDefFoundError(),
 331                          "Class name exceeds maximum length of %d: %s",
 332                          Symbol::max_length(),
 333                          name);
 334       return 0;
 335     }
 336     class_name = SymbolTable::new_symbol(name, CHECK_NULL);
 337   }
 338   ResourceMark rm(THREAD);
 339   ClassFileStream st((u1*)buf, bufLen, NULL, ClassFileStream::verify);
 340   Handle class_loader (THREAD, JNIHandles::resolve(loaderRef));
 341 
 342   if (UsePerfData && !class_loader.is_null()) {
 343     // check whether the current caller thread holds the lock or not.
 344     // If not, increment the corresponding counter
 345     if (ObjectSynchronizer::
 346         query_lock_ownership((JavaThread*)THREAD, class_loader) !=
 347         ObjectSynchronizer::owner_self) {
 348       ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc();
 349     }
 350   }
 351   Klass* k = SystemDictionary::resolve_from_stream(class_name,
 352                                                    class_loader,
 353                                                    Handle(),
 354                                                    &st,
 355                                                    CHECK_NULL);
 356 
 357   if (log_is_enabled(Debug, class, resolve) && k != NULL) {
 358     trace_class_resolution(k);
 359   }
 360 
 361   cls = (jclass)JNIHandles::make_local(
 362     env, k->java_mirror());
 363   return cls;
 364 JNI_END
 365 
 366 
 367 
 368 static bool first_time_FindClass = true;
 369 
 370 DT_RETURN_MARK_DECL(FindClass, jclass
 371                     , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref));
 372 
 373 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name))
 374   JNIWrapper("FindClass");
 375 
 376   HOTSPOT_JNI_FINDCLASS_ENTRY(env, (char *)name);
 377 
 378   jclass result = NULL;
 379   DT_RETURN_MARK(FindClass, jclass, (const jclass&)result);
 380 
 381   // Remember if we are the first invocation of jni_FindClass
 382   bool first_time = first_time_FindClass;
 383   first_time_FindClass = false;
 384 
 385   // Sanity check the name:  it cannot be null or larger than the maximum size
 386   // name we can fit in the constant pool.
 387   if (name == NULL) {
 388     THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), "No class name given");
 389   }
 390   if ((int)strlen(name) > Symbol::max_length()) {
 391     Exceptions::fthrow(THREAD_AND_LOCATION,
 392                        vmSymbols::java_lang_NoClassDefFoundError(),
 393                        "Class name exceeds maximum length of %d: %s",
 394                        Symbol::max_length(),
 395                        name);
 396     return 0;
 397   }
 398 
 399   //%note jni_3
 400   Handle protection_domain;
 401   // Find calling class
 402   Klass* k = thread->security_get_caller_class(0);
 403   // default to the system loader when no context
 404   Handle loader(THREAD, SystemDictionary::java_system_loader());
 405   if (k != NULL) {
 406     // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed
 407     // in the correct class context.
 408     if (k->class_loader() == NULL &&
 409         k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) {
 410       JavaValue result(T_OBJECT);
 411       JavaCalls::call_static(&result, k,
 412                              vmSymbols::getFromClass_name(),
 413                              vmSymbols::void_class_signature(),
 414                              CHECK_NULL);
 415       // When invoked from JNI_OnLoad, NativeLibrary::getFromClass returns
 416       // a non-NULL Class object.  When invoked from JNI_OnUnload,
 417       // it will return NULL to indicate no context.
 418       oop mirror = (oop) result.get_jobject();
 419       if (mirror != NULL) {
 420         Klass* fromClass = java_lang_Class::as_Klass(mirror);
 421         loader = Handle(THREAD, fromClass->class_loader());
 422         protection_domain = Handle(THREAD, fromClass->protection_domain());
 423       }
 424     } else {
 425       loader = Handle(THREAD, k->class_loader());
 426     }
 427   }
 428 
 429   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
 430   result = find_class_from_class_loader(env, sym, true, loader,
 431                                         protection_domain, true, thread);
 432 
 433   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
 434     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 435   }
 436 
 437   // If we were the first invocation of jni_FindClass, we enable compilation again
 438   // rather than just allowing invocation counter to overflow and decay.
 439   // Controlled by flag DelayCompilationDuringStartup.
 440   if (first_time && !CompileTheWorld)
 441     CompilationPolicy::completed_vm_startup();
 442 
 443   return result;
 444 JNI_END
 445 
 446 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID
 447                     , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref));
 448 
 449 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method))
 450   JNIWrapper("FromReflectedMethod");
 451 
 452   HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY(env, method);
 453 
 454   jmethodID ret = NULL;
 455   DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret);
 456 
 457   // method is a handle to a java.lang.reflect.Method object
 458   oop reflected  = JNIHandles::resolve_non_null(method);
 459   oop mirror     = NULL;
 460   int slot       = 0;
 461 
 462   if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
 463     mirror = java_lang_reflect_Constructor::clazz(reflected);
 464     slot   = java_lang_reflect_Constructor::slot(reflected);
 465   } else {
 466     assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type");
 467     mirror = java_lang_reflect_Method::clazz(reflected);
 468     slot   = java_lang_reflect_Method::slot(reflected);
 469   }
 470   Klass* k1 = java_lang_Class::as_Klass(mirror);
 471 
 472   // Make sure class is initialized before handing id's out to methods
 473   k1->initialize(CHECK_NULL);
 474   Method* m = InstanceKlass::cast(k1)->method_with_idnum(slot);
 475   ret = m==NULL? NULL : m->jmethod_id();  // return NULL if reflected method deleted
 476   return ret;
 477 JNI_END
 478 
 479 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID
 480                     , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref));
 481 
 482 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field))
 483   JNIWrapper("FromReflectedField");
 484 
 485   HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY(env, field);
 486 
 487   jfieldID ret = NULL;
 488   DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret);
 489 
 490   // field is a handle to a java.lang.reflect.Field object
 491   oop reflected   = JNIHandles::resolve_non_null(field);
 492   oop mirror      = java_lang_reflect_Field::clazz(reflected);
 493   Klass* k1       = java_lang_Class::as_Klass(mirror);
 494   int slot        = java_lang_reflect_Field::slot(reflected);
 495   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
 496 
 497   // Make sure class is initialized before handing id's out to fields
 498   k1->initialize(CHECK_NULL);
 499 
 500   // First check if this is a static field
 501   if (modifiers & JVM_ACC_STATIC) {
 502     intptr_t offset = InstanceKlass::cast(k1)->field_offset( slot );
 503     JNIid* id = InstanceKlass::cast(k1)->jni_id_for(offset);
 504     assert(id != NULL, "corrupt Field object");
 505     debug_only(id->set_is_static_field_id();)
 506     // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
 507     ret = jfieldIDWorkaround::to_static_jfieldID(id);
 508     return ret;
 509   }
 510 
 511   // The slot is the index of the field description in the field-array
 512   // The jfieldID is the offset of the field within the object
 513   // It may also have hash bits for k, if VerifyJNIFields is turned on.
 514   intptr_t offset = InstanceKlass::cast(k1)->field_offset( slot );
 515   assert(InstanceKlass::cast(k1)->contains_field_offset(offset), "stay within object");
 516   ret = jfieldIDWorkaround::to_instance_jfieldID(k1, offset);
 517   return ret;
 518 JNI_END
 519 
 520 
 521 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject
 522                     , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref));
 523 
 524 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic))
 525   JNIWrapper("ToReflectedMethod");
 526 
 527   HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY(env, cls, (uintptr_t) method_id, isStatic);
 528 
 529   jobject ret = NULL;
 530   DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret);
 531 
 532   methodHandle m (THREAD, Method::resolve_jmethod_id(method_id));
 533   assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match");
 534   oop reflection_method;
 535   if (m->is_initializer()) {
 536     reflection_method = Reflection::new_constructor(m, CHECK_NULL);
 537   } else {
 538     reflection_method = Reflection::new_method(m, false, CHECK_NULL);
 539   }
 540   ret = JNIHandles::make_local(env, reflection_method);
 541   return ret;
 542 JNI_END
 543 
 544 DT_RETURN_MARK_DECL(GetSuperclass, jclass
 545                     , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref));
 546 
 547 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub))
 548   JNIWrapper("GetSuperclass");
 549 
 550   HOTSPOT_JNI_GETSUPERCLASS_ENTRY(env, sub);
 551 
 552   jclass obj = NULL;
 553   DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj);
 554 
 555   oop mirror = JNIHandles::resolve_non_null(sub);
 556   // primitive classes return NULL
 557   if (java_lang_Class::is_primitive(mirror)) return NULL;
 558 
 559   // Rules of Class.getSuperClass as implemented by KLass::java_super:
 560   // arrays return Object
 561   // interfaces return NULL
 562   // proper classes return Klass::super()
 563   Klass* k = java_lang_Class::as_Klass(mirror);
 564   if (k->is_interface()) return NULL;
 565 
 566   // return mirror for superclass
 567   Klass* super = k->java_super();
 568   // super2 is the value computed by the compiler's getSuperClass intrinsic:
 569   debug_only(Klass* super2 = ( k->is_array_klass()
 570                                  ? SystemDictionary::Object_klass()
 571                                  : k->super() ) );
 572   assert(super == super2,
 573          "java_super computation depends on interface, array, other super");
 574   obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(super->java_mirror());
 575   return obj;
 576 JNI_END
 577 
 578 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super))
 579   JNIWrapper("IsSubclassOf");
 580 
 581   HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY(env, sub, super);
 582 
 583   oop sub_mirror   = JNIHandles::resolve_non_null(sub);
 584   oop super_mirror = JNIHandles::resolve_non_null(super);
 585   if (java_lang_Class::is_primitive(sub_mirror) ||
 586       java_lang_Class::is_primitive(super_mirror)) {
 587     jboolean ret = oopDesc::equals(sub_mirror, super_mirror);
 588 
 589     HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(ret);
 590     return ret;
 591   }
 592   Klass* sub_klass   = java_lang_Class::as_Klass(sub_mirror);
 593   Klass* super_klass = java_lang_Class::as_Klass(super_mirror);
 594   assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom");
 595   jboolean ret = sub_klass->is_subtype_of(super_klass) ?
 596                    JNI_TRUE : JNI_FALSE;
 597 
 598   HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN(ret);
 599   return ret;
 600 JNI_END
 601 
 602 
 603 DT_RETURN_MARK_DECL(Throw, jint
 604                     , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
 605 
 606 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
 607   JNIWrapper("Throw");
 608 
 609   HOTSPOT_JNI_THROW_ENTRY(env, obj);
 610 
 611   jint ret = JNI_OK;
 612   DT_RETURN_MARK(Throw, jint, (const jint&)ret);
 613 
 614   THROW_OOP_(JNIHandles::resolve(obj), JNI_OK);
 615   ShouldNotReachHere();
 616   return 0;  // Mute compiler.
 617 JNI_END
 618 
 619 
 620 DT_RETURN_MARK_DECL(ThrowNew, jint
 621                     , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
 622 
 623 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
 624   JNIWrapper("ThrowNew");
 625 
 626   HOTSPOT_JNI_THROWNEW_ENTRY(env, clazz, (char *) message);
 627 
 628   jint ret = JNI_OK;
 629   DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
 630 
 631   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
 632   Symbol*  name = k->name();
 633   Handle class_loader (THREAD,  k->class_loader());
 634   Handle protection_domain (THREAD, k->protection_domain());
 635   THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK);
 636   ShouldNotReachHere();
 637   return 0;  // Mute compiler.
 638 JNI_END
 639 
 640 
 641 // JNI functions only transform a pending async exception to a synchronous
 642 // exception in ExceptionOccurred and ExceptionCheck calls, since
 643 // delivering an async exception in other places won't change the native
 644 // code's control flow and would be harmful when native code further calls
 645 // JNI functions with a pending exception. Async exception is also checked
 646 // during the call, so ExceptionOccurred/ExceptionCheck won't return
 647 // false but deliver the async exception at the very end during
 648 // state transition.
 649 
 650 static void jni_check_async_exceptions(JavaThread *thread) {
 651   assert(thread == Thread::current(), "must be itself");
 652   thread->check_and_handle_async_exceptions();
 653 }
 654 
 655 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
 656   JNIWrapper("ExceptionOccurred");
 657 
 658   HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY(env);
 659 
 660   jni_check_async_exceptions(thread);
 661   oop exception = thread->pending_exception();
 662   jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception);
 663 
 664   HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN(ret);
 665   return ret;
 666 JNI_END
 667 
 668 
 669 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env))
 670   JNIWrapper("ExceptionDescribe");
 671 
 672   HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY(env);
 673 
 674   if (thread->has_pending_exception()) {
 675     Handle ex(thread, thread->pending_exception());
 676     thread->clear_pending_exception();
 677     if (ex->is_a(SystemDictionary::ThreadDeath_klass())) {
 678       // Don't print anything if we are being killed.
 679     } else {
 680       jio_fprintf(defaultStream::error_stream(), "Exception ");
 681       if (thread != NULL && thread->threadObj() != NULL) {
 682         ResourceMark rm(THREAD);
 683         jio_fprintf(defaultStream::error_stream(),
 684         "in thread \"%s\" ", thread->get_thread_name());
 685       }
 686       if (ex->is_a(SystemDictionary::Throwable_klass())) {
 687         JavaValue result(T_VOID);
 688         JavaCalls::call_virtual(&result,
 689                                 ex,
 690                                 SystemDictionary::Throwable_klass(),
 691                                 vmSymbols::printStackTrace_name(),
 692                                 vmSymbols::void_method_signature(),
 693                                 THREAD);
 694         // If an exception is thrown in the call it gets thrown away. Not much
 695         // we can do with it. The native code that calls this, does not check
 696         // for the exception - hence, it might still be in the thread when DestroyVM gets
 697         // called, potentially causing a few asserts to trigger - since no pending exception
 698         // is expected.
 699         CLEAR_PENDING_EXCEPTION;
 700       } else {
 701         ResourceMark rm(THREAD);
 702         jio_fprintf(defaultStream::error_stream(),
 703         ". Uncaught exception of type %s.",
 704         ex->klass()->external_name());
 705       }
 706     }
 707   }
 708 
 709   HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN();
 710 JNI_END
 711 
 712 
 713 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env))
 714   JNIWrapper("ExceptionClear");
 715 
 716   HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY(env);
 717 
 718   // The jni code might be using this API to clear java thrown exception.
 719   // So just mark jvmti thread exception state as exception caught.
 720   JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state();
 721   if (state != NULL && state->is_exception_detected()) {
 722     state->set_exception_caught();
 723   }
 724   thread->clear_pending_exception();
 725 
 726   HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN();
 727 JNI_END
 728 
 729 
 730 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg))
 731   JNIWrapper("FatalError");
 732 
 733   HOTSPOT_JNI_FATALERROR_ENTRY(env, (char *) msg);
 734 
 735   tty->print_cr("FATAL ERROR in native method: %s", msg);
 736   thread->print_stack();
 737   os::abort(); // Dump core and abort
 738 JNI_END
 739 
 740 
 741 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity))
 742   JNIWrapper("PushLocalFrame");
 743 
 744   HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY(env, capacity);
 745 
 746   //%note jni_11
 747   if (capacity < 0 ||
 748       ((MaxJNILocalCapacity > 0) && (capacity > MaxJNILocalCapacity))) {
 749     HOTSPOT_JNI_PUSHLOCALFRAME_RETURN((uint32_t)JNI_ERR);
 750     return JNI_ERR;
 751   }
 752   JNIHandleBlock* old_handles = thread->active_handles();
 753   JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
 754   assert(new_handles != NULL, "should not be NULL");
 755   new_handles->set_pop_frame_link(old_handles);
 756   thread->set_active_handles(new_handles);
 757   jint ret = JNI_OK;
 758   HOTSPOT_JNI_PUSHLOCALFRAME_RETURN(ret);
 759   return ret;
 760 JNI_END
 761 
 762 
 763 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result))
 764   JNIWrapper("PopLocalFrame");
 765 
 766   HOTSPOT_JNI_POPLOCALFRAME_ENTRY(env, result);
 767 
 768   //%note jni_11
 769   Handle result_handle(thread, JNIHandles::resolve(result));
 770   JNIHandleBlock* old_handles = thread->active_handles();
 771   JNIHandleBlock* new_handles = old_handles->pop_frame_link();
 772   if (new_handles != NULL) {
 773     // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL.
 774     // This way code will still work if PopLocalFrame is called without a corresponding
 775     // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise
 776     // the release_block call will release the blocks.
 777     thread->set_active_handles(new_handles);
 778     old_handles->set_pop_frame_link(NULL);              // clear link we won't release new_handles below
 779     JNIHandleBlock::release_block(old_handles, thread); // may block
 780     result = JNIHandles::make_local(thread, result_handle());
 781   }
 782   HOTSPOT_JNI_POPLOCALFRAME_RETURN(result);
 783   return result;
 784 JNI_END
 785 
 786 
 787 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref))
 788   JNIWrapper("NewGlobalRef");
 789 
 790   HOTSPOT_JNI_NEWGLOBALREF_ENTRY(env, ref);
 791 
 792   Handle ref_handle(thread, JNIHandles::resolve(ref));
 793   jobject ret = JNIHandles::make_global(ref_handle);
 794 
 795   HOTSPOT_JNI_NEWGLOBALREF_RETURN(ret);
 796   return ret;
 797 JNI_END
 798 
 799 // Must be JNI_ENTRY (with HandleMark)
 800 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref))
 801   JNIWrapper("DeleteGlobalRef");
 802 
 803   HOTSPOT_JNI_DELETEGLOBALREF_ENTRY(env, ref);
 804 
 805   JNIHandles::destroy_global(ref);
 806 
 807   HOTSPOT_JNI_DELETEGLOBALREF_RETURN();
 808 JNI_END
 809 
 810 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj))
 811   JNIWrapper("DeleteLocalRef");
 812 
 813   HOTSPOT_JNI_DELETELOCALREF_ENTRY(env, obj);
 814 
 815   JNIHandles::destroy_local(obj);
 816 
 817   HOTSPOT_JNI_DELETELOCALREF_RETURN();
 818 JNI_END
 819 
 820 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2))
 821   JNIWrapper("IsSameObject");
 822 
 823   HOTSPOT_JNI_ISSAMEOBJECT_ENTRY(env, r1, r2);
 824 
 825   oop a = JNIHandles::resolve(r1);
 826   oop b = JNIHandles::resolve(r2);
 827   jboolean ret = oopDesc::equals(a, b) ? JNI_TRUE : JNI_FALSE;
 828 
 829   HOTSPOT_JNI_ISSAMEOBJECT_RETURN(ret);
 830   return ret;
 831 JNI_END
 832 
 833 
 834 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref))
 835   JNIWrapper("NewLocalRef");
 836 
 837   HOTSPOT_JNI_NEWLOCALREF_ENTRY(env, ref);
 838 
 839   jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref));
 840 
 841   HOTSPOT_JNI_NEWLOCALREF_RETURN(ret);
 842   return ret;
 843 JNI_END
 844 
 845 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity))
 846   JNIWrapper("EnsureLocalCapacity");
 847 
 848   HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY(env, capacity);
 849 
 850   jint ret;
 851   if (capacity >= 0 &&
 852       ((MaxJNILocalCapacity <= 0) || (capacity <= MaxJNILocalCapacity))) {
 853     ret = JNI_OK;
 854   } else {
 855     ret = JNI_ERR;
 856   }
 857 
 858   HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN(ret);
 859   return ret;
 860 JNI_END
 861 
 862 // Return the Handle Type
 863 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj))
 864   JNIWrapper("GetObjectRefType");
 865 
 866   HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY(env, obj);
 867 
 868   jobjectRefType ret = JNIInvalidRefType;
 869   if (obj != NULL) {
 870     ret = JNIHandles::handle_type(thread, obj);
 871   }
 872 
 873   HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN((void *) ret);
 874   return ret;
 875 JNI_END
 876 
 877 
 878 class JNI_ArgumentPusher : public SignatureIterator {
 879  protected:
 880   JavaCallArguments*  _arguments;
 881 
 882   virtual void get_bool   () = 0;
 883   virtual void get_char   () = 0;
 884   virtual void get_short  () = 0;
 885   virtual void get_byte   () = 0;
 886   virtual void get_int    () = 0;
 887   virtual void get_long   () = 0;
 888   virtual void get_float  () = 0;
 889   virtual void get_double () = 0;
 890   virtual void get_object () = 0;
 891 
 892   JNI_ArgumentPusher(Symbol* signature) : SignatureIterator(signature) {
 893     this->_return_type = T_ILLEGAL;
 894     _arguments = NULL;
 895   }
 896 
 897  public:
 898   virtual void iterate( uint64_t fingerprint ) = 0;
 899 
 900   void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; }
 901 
 902   inline void do_bool()                     { if (!is_return_type()) get_bool();   }
 903   inline void do_char()                     { if (!is_return_type()) get_char();   }
 904   inline void do_short()                    { if (!is_return_type()) get_short();  }
 905   inline void do_byte()                     { if (!is_return_type()) get_byte();   }
 906   inline void do_int()                      { if (!is_return_type()) get_int();    }
 907   inline void do_long()                     { if (!is_return_type()) get_long();   }
 908   inline void do_float()                    { if (!is_return_type()) get_float();  }
 909   inline void do_double()                   { if (!is_return_type()) get_double(); }
 910   inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); }
 911   inline void do_array(int begin, int end)  { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array
 912   inline void do_void()                     { }
 913 
 914   JavaCallArguments* arguments()     { return _arguments; }
 915   void push_receiver(Handle h)       { _arguments->push_oop(h); }
 916 };
 917 
 918 
 919 class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher {
 920  protected:
 921   va_list _ap;
 922 
 923   inline void get_bool()   {
 924     // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
 925     // 0 to JNI_FALSE.  Boolean return values from native are normalized the same in
 926     // TemplateInterpreterGenerator::generate_result_handler_for and
 927     // SharedRuntime::generate_native_wrapper.
 928     jboolean b = va_arg(_ap, jint);
 929     _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
 930   }
 931   inline void get_char()   { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg
 932   inline void get_short()  { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg
 933   inline void get_byte()   { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg
 934   inline void get_int()    { _arguments->push_int(va_arg(_ap, jint)); }
 935 
 936   // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
 937 
 938   inline void get_long()   { _arguments->push_long(va_arg(_ap, jlong)); }
 939   inline void get_float()  { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg
 940   inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); }
 941   inline void get_object() { _arguments->push_jobject(va_arg(_ap, jobject)); }
 942 
 943   inline void set_ap(va_list rap) {
 944     va_copy(_ap, rap);
 945   }
 946 
 947  public:
 948   JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap)
 949        : JNI_ArgumentPusher(signature) {
 950     set_ap(rap);
 951   }
 952   JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
 953       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
 954     set_ap(rap);
 955   }
 956 
 957   // Optimized path if we have the bitvector form of signature
 958   void iterate( uint64_t fingerprint ) {
 959     if (fingerprint == (uint64_t)CONST64(-1)) {
 960       SignatureIterator::iterate(); // Must be too many arguments
 961     } else {
 962       _return_type = (BasicType)((fingerprint >> static_feature_size) &
 963                                   result_feature_mask);
 964 
 965       assert(fingerprint, "Fingerprint should not be 0");
 966       fingerprint = fingerprint >> (static_feature_size + result_feature_size);
 967       while ( 1 ) {
 968         switch ( fingerprint & parameter_feature_mask ) {
 969           case bool_parm:
 970             get_bool();
 971             break;
 972           case char_parm:
 973             get_char();
 974             break;
 975           case short_parm:
 976             get_short();
 977             break;
 978           case byte_parm:
 979             get_byte();
 980             break;
 981           case int_parm:
 982             get_int();
 983             break;
 984           case obj_parm:
 985             get_object();
 986             break;
 987           case long_parm:
 988             get_long();
 989             break;
 990           case float_parm:
 991             get_float();
 992             break;
 993           case double_parm:
 994             get_double();
 995             break;
 996           case done_parm:
 997             return;
 998             break;
 999           default:
1000             ShouldNotReachHere();
1001             break;
1002         }
1003         fingerprint >>= parameter_feature_size;
1004       }
1005     }
1006   }
1007 };
1008 
1009 
1010 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher {
1011  protected:
1012   const jvalue *_ap;
1013 
1014   inline void get_bool()   {
1015     // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1016     // 0 to JNI_FALSE.  Boolean return values from native are normalized the same in
1017     // TemplateInterpreterGenerator::generate_result_handler_for and
1018     // SharedRuntime::generate_native_wrapper.
1019     jboolean b = (_ap++)->z;
1020     _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1021   }
1022   inline void get_char()   { _arguments->push_int((jint)(_ap++)->c); }
1023   inline void get_short()  { _arguments->push_int((jint)(_ap++)->s); }
1024   inline void get_byte()   { _arguments->push_int((jint)(_ap++)->b); }
1025   inline void get_int()    { _arguments->push_int((jint)(_ap++)->i); }
1026 
1027   inline void get_long()   { _arguments->push_long((_ap++)->j);  }
1028   inline void get_float()  { _arguments->push_float((_ap++)->f); }
1029   inline void get_double() { _arguments->push_double((_ap++)->d);}
1030   inline void get_object() { _arguments->push_jobject((_ap++)->l); }
1031 
1032   inline void set_ap(const jvalue *rap) { _ap = rap; }
1033 
1034  public:
1035   JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap)
1036        : JNI_ArgumentPusher(signature) {
1037     set_ap(rap);
1038   }
1039   JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap)
1040       : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1041     set_ap(rap);
1042   }
1043 
1044   // Optimized path if we have the bitvector form of signature
1045   void iterate( uint64_t fingerprint ) {
1046     if (fingerprint == (uint64_t)CONST64(-1)) {
1047       SignatureIterator::iterate(); // Must be too many arguments
1048     } else {
1049       _return_type = (BasicType)((fingerprint >> static_feature_size) &
1050                                   result_feature_mask);
1051       assert(fingerprint, "Fingerprint should not be 0");
1052       fingerprint = fingerprint >> (static_feature_size + result_feature_size);
1053       while ( 1 ) {
1054         switch ( fingerprint & parameter_feature_mask ) {
1055           case bool_parm:
1056             get_bool();
1057             break;
1058           case char_parm:
1059             get_char();
1060             break;
1061           case short_parm:
1062             get_short();
1063             break;
1064           case byte_parm:
1065             get_byte();
1066             break;
1067           case int_parm:
1068             get_int();
1069             break;
1070           case obj_parm:
1071             get_object();
1072             break;
1073           case long_parm:
1074             get_long();
1075             break;
1076           case float_parm:
1077             get_float();
1078             break;
1079           case double_parm:
1080             get_double();
1081             break;
1082           case done_parm:
1083             return;
1084             break;
1085           default:
1086             ShouldNotReachHere();
1087             break;
1088         }
1089         fingerprint >>= parameter_feature_size;
1090       }
1091     }
1092   }
1093 };
1094 
1095 
1096 enum JNICallType {
1097   JNI_STATIC,
1098   JNI_VIRTUAL,
1099   JNI_NONVIRTUAL
1100 };
1101 
1102 
1103 
1104 static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) {
1105   methodHandle method(THREAD, Method::resolve_jmethod_id(method_id));
1106 
1107   // Create object to hold arguments for the JavaCall, and associate it with
1108   // the jni parser
1109   ResourceMark rm(THREAD);
1110   int number_of_parameters = method->size_of_parameters();
1111   JavaCallArguments java_args(number_of_parameters);
1112   args->set_java_argument_object(&java_args);
1113 
1114   assert(method->is_static(), "method should be static");
1115 
1116   // Fill out JavaCallArguments object
1117   args->iterate( Fingerprinter(method).fingerprint() );
1118   // Initialize result type
1119   result->set_type(args->get_ret_type());
1120 
1121   // Invoke the method. Result is returned as oop.
1122   JavaCalls::call(result, method, &java_args, CHECK);
1123 
1124   // Convert result
1125   if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) {
1126     result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject()));
1127   }
1128 }
1129 
1130 
1131 static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) {
1132   oop recv = JNIHandles::resolve(receiver);
1133   if (recv == NULL) {
1134     THROW(vmSymbols::java_lang_NullPointerException());
1135   }
1136   Handle h_recv(THREAD, recv);
1137 
1138   int number_of_parameters;
1139   Method* selected_method;
1140   {
1141     Method* m = Method::resolve_jmethod_id(method_id);
1142     number_of_parameters = m->size_of_parameters();
1143     Klass* holder = m->method_holder();
1144     if (call_type != JNI_VIRTUAL) {
1145         selected_method = m;
1146     } else if (!m->has_itable_index()) {
1147       // non-interface call -- for that little speed boost, don't handlize
1148       debug_only(NoSafepointVerifier nosafepoint;)
1149       // jni_GetMethodID makes sure class is linked and initialized
1150       // so m should have a valid vtable index.
1151       assert(m->valid_vtable_index(), "no valid vtable index");
1152       int vtbl_index = m->vtable_index();
1153       if (vtbl_index != Method::nonvirtual_vtable_index) {
1154         selected_method = h_recv->klass()->method_at_vtable(vtbl_index);
1155       } else {
1156         // final method
1157         selected_method = m;
1158       }
1159     } else {
1160       // interface call
1161       int itbl_index = m->itable_index();
1162       Klass* k = h_recv->klass();
1163       selected_method = InstanceKlass::cast(k)->method_at_itable(holder, itbl_index, CHECK);
1164     }
1165   }
1166 
1167   methodHandle method(THREAD, selected_method);
1168 
1169   // Create object to hold arguments for the JavaCall, and associate it with
1170   // the jni parser
1171   ResourceMark rm(THREAD);
1172   JavaCallArguments java_args(number_of_parameters);
1173   args->set_java_argument_object(&java_args);
1174 
1175   // handle arguments
1176   assert(!method->is_static(), "method %s should not be static", method->name_and_sig_as_C_string());
1177   args->push_receiver(h_recv); // Push jobject handle
1178 
1179   // Fill out JavaCallArguments object
1180   args->iterate( Fingerprinter(method).fingerprint() );
1181   // Initialize result type
1182   result->set_type(args->get_ret_type());
1183 
1184   // Invoke the method. Result is returned as oop.
1185   JavaCalls::call(result, method, &java_args, CHECK);
1186 
1187   // Convert result
1188   if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) {
1189     result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject()));
1190   }
1191 }
1192 
1193 
1194 static instanceOop alloc_object(jclass clazz, TRAPS) {
1195   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1196   if (k == NULL) {
1197     ResourceMark rm(THREAD);
1198     THROW_(vmSymbols::java_lang_InstantiationException(), NULL);
1199   }
1200   k->check_valid_for_instantiation(false, CHECK_NULL);
1201   k->initialize(CHECK_NULL);
1202   instanceOop ih = InstanceKlass::cast(k)->allocate_instance(THREAD);
1203   return ih;
1204 }
1205 
1206 DT_RETURN_MARK_DECL(AllocObject, jobject
1207                     , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
1208 
1209 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
1210   JNIWrapper("AllocObject");
1211 
1212   HOTSPOT_JNI_ALLOCOBJECT_ENTRY(env, clazz);
1213 
1214   jobject ret = NULL;
1215   DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
1216 
1217   instanceOop i = alloc_object(clazz, CHECK_NULL);
1218   ret = JNIHandles::make_local(env, i);
1219   return ret;
1220 JNI_END
1221 
1222 DT_RETURN_MARK_DECL(NewObjectA, jobject
1223                     , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref));
1224 
1225 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args))
1226   JNIWrapper("NewObjectA");
1227 
1228   HOTSPOT_JNI_NEWOBJECTA_ENTRY(env, clazz, (uintptr_t) methodID);
1229 
1230   jobject obj = NULL;
1231   DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj);
1232 
1233   instanceOop i = alloc_object(clazz, CHECK_NULL);
1234   obj = JNIHandles::make_local(env, i);
1235   JavaValue jvalue(T_VOID);
1236   JNI_ArgumentPusherArray ap(methodID, args);
1237   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1238   return obj;
1239 JNI_END
1240 
1241 
1242 DT_RETURN_MARK_DECL(NewObjectV, jobject
1243                     , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref));
1244 
1245 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args))
1246   JNIWrapper("NewObjectV");
1247 
1248   HOTSPOT_JNI_NEWOBJECTV_ENTRY(env, clazz, (uintptr_t) methodID);
1249 
1250   jobject obj = NULL;
1251   DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
1252 
1253   instanceOop i = alloc_object(clazz, CHECK_NULL);
1254   obj = JNIHandles::make_local(env, i);
1255   JavaValue jvalue(T_VOID);
1256   JNI_ArgumentPusherVaArg ap(methodID, args);
1257   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1258   return obj;
1259 JNI_END
1260 
1261 
1262 DT_RETURN_MARK_DECL(NewObject, jobject
1263                     , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref));
1264 
1265 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...))
1266   JNIWrapper("NewObject");
1267 
1268   HOTSPOT_JNI_NEWOBJECT_ENTRY(env, clazz, (uintptr_t) methodID);
1269 
1270   jobject obj = NULL;
1271   DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
1272 
1273   instanceOop i = alloc_object(clazz, CHECK_NULL);
1274   obj = JNIHandles::make_local(env, i);
1275   va_list args;
1276   va_start(args, methodID);
1277   JavaValue jvalue(T_VOID);
1278   JNI_ArgumentPusherVaArg ap(methodID, args);
1279   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL);
1280   va_end(args);
1281   return obj;
1282 JNI_END
1283 
1284 
1285 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj))
1286   JNIWrapper("GetObjectClass");
1287 
1288   HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj);
1289 
1290   Klass* k = JNIHandles::resolve_non_null(obj)->klass();
1291   jclass ret =
1292     (jclass) JNIHandles::make_local(env, k->java_mirror());
1293 
1294   HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret);
1295   return ret;
1296 JNI_END
1297 
1298 JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz))
1299   JNIWrapper("IsInstanceOf");
1300 
1301   HOTSPOT_JNI_ISINSTANCEOF_ENTRY(env, obj, clazz);
1302 
1303   jboolean ret = JNI_TRUE;
1304   if (obj != NULL) {
1305     ret = JNI_FALSE;
1306     Klass* k = java_lang_Class::as_Klass(
1307       JNIHandles::resolve_non_null(clazz));
1308     if (k != NULL) {
1309       ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE;
1310     }
1311   }
1312 
1313   HOTSPOT_JNI_ISINSTANCEOF_RETURN(ret);
1314   return ret;
1315 JNI_END
1316 
1317 
1318 static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str,
1319                                const char *sig, bool is_static, TRAPS) {
1320   // %%%% This code should probably just call into a method in the LinkResolver
1321   //
1322   // The class should have been loaded (we have an instance of the class
1323   // passed in) so the method and signature should already be in the symbol
1324   // table.  If they're not there, the method doesn't exist.
1325   const char *name_to_probe = (name_str == NULL)
1326                         ? vmSymbols::object_initializer_name()->as_C_string()
1327                         : name_str;
1328   TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe));
1329   TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig));
1330 
1331   if (name == NULL || signature == NULL) {
1332     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1333   }
1334 
1335   // Throw a NoSuchMethodError exception if we have an instance of a
1336   // primitive java.lang.Class
1337   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) {
1338     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1339   }
1340 
1341   Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1342 
1343   // Make sure class is linked and initialized before handing id's out to
1344   // Method*s.
1345   klass->initialize(CHECK_NULL);
1346 
1347   Method* m;
1348   if (name == vmSymbols::object_initializer_name() ||
1349       name == vmSymbols::class_initializer_name()) {
1350     // Never search superclasses for constructors
1351     if (klass->is_instance_klass()) {
1352       m = InstanceKlass::cast(klass)->find_method(name, signature);
1353     } else {
1354       m = NULL;
1355     }
1356   } else {
1357     m = klass->lookup_method(name, signature);
1358     if (m == NULL &&  klass->is_instance_klass()) {
1359       m = InstanceKlass::cast(klass)->lookup_method_in_ordered_interfaces(name, signature);
1360     }
1361   }
1362   if (m == NULL || (m->is_static() != is_static)) {
1363     THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
1364   }
1365   return m->jmethod_id();
1366 }
1367 
1368 
1369 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz,
1370           const char *name, const char *sig))
1371   JNIWrapper("GetMethodID");
1372   HOTSPOT_JNI_GETMETHODID_ENTRY(env, clazz, (char *) name, (char *) sig);
1373   jmethodID ret = get_method_id(env, clazz, name, sig, false, thread);
1374   HOTSPOT_JNI_GETMETHODID_RETURN((uintptr_t) ret);
1375   return ret;
1376 JNI_END
1377 
1378 
1379 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz,
1380           const char *name, const char *sig))
1381   JNIWrapper("GetStaticMethodID");
1382   HOTSPOT_JNI_GETSTATICMETHODID_ENTRY(env, (char *) clazz, (char *) name, (char *)sig);
1383   jmethodID ret = get_method_id(env, clazz, name, sig, true, thread);
1384   HOTSPOT_JNI_GETSTATICMETHODID_RETURN((uintptr_t) ret);
1385   return ret;
1386 JNI_END
1387 
1388 
1389 
1390 //
1391 // Calling Methods
1392 //
1393 
1394 
1395 #define DEFINE_CALLMETHOD(ResultType, Result, Tag \
1396                           , EntryProbe, ReturnProbe)    \
1397 \
1398   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \
1399                           , ReturnProbe);                          \
1400 \
1401 JNI_ENTRY(ResultType, \
1402           jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \
1403   JNIWrapper("Call" XSTR(Result) "Method"); \
1404 \
1405   EntryProbe; \
1406   ResultType ret = 0;\
1407   DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \
1408                      (const ResultType&)ret);\
1409 \
1410   va_list args; \
1411   va_start(args, methodID); \
1412   JavaValue jvalue(Tag); \
1413   JNI_ArgumentPusherVaArg ap(methodID, args); \
1414   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1415   va_end(args); \
1416   ret = jvalue.get_##ResultType(); \
1417   return ret;\
1418 JNI_END
1419 
1420 // the runtime type of subword integral basic types is integer
1421 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN
1422                   , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1423                   HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref))
1424 DEFINE_CALLMETHOD(jbyte,    Byte,    T_BYTE
1425                   , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1426                   HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref))
1427 DEFINE_CALLMETHOD(jchar,    Char,    T_CHAR
1428                   , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1429                   HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref))
1430 DEFINE_CALLMETHOD(jshort,   Short,   T_SHORT
1431                   , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1432                   HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref))
1433 
1434 DEFINE_CALLMETHOD(jobject,  Object,  T_OBJECT
1435                   , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1436                   HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref))
1437 DEFINE_CALLMETHOD(jint,     Int,     T_INT,
1438                   HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1439                   HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref))
1440 DEFINE_CALLMETHOD(jlong,    Long,    T_LONG
1441                   , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1442                   HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref))
1443 // Float and double probes don't return value because dtrace doesn't currently support it
1444 DEFINE_CALLMETHOD(jfloat,   Float,   T_FLOAT
1445                   , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1446                   HOTSPOT_JNI_CALLFLOATMETHOD_RETURN())
1447 DEFINE_CALLMETHOD(jdouble,  Double,  T_DOUBLE
1448                   , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID),
1449                   HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN())
1450 
1451 #define DEFINE_CALLMETHODV(ResultType, Result, Tag \
1452                           , EntryProbe, ReturnProbe)    \
1453 \
1454   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \
1455                           , ReturnProbe);                          \
1456 \
1457 JNI_ENTRY(ResultType, \
1458           jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \
1459   JNIWrapper("Call" XSTR(Result) "MethodV"); \
1460 \
1461   EntryProbe;\
1462   ResultType ret = 0;\
1463   DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \
1464                      (const ResultType&)ret);\
1465 \
1466   JavaValue jvalue(Tag); \
1467   JNI_ArgumentPusherVaArg ap(methodID, args); \
1468   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1469   ret = jvalue.get_##ResultType(); \
1470   return ret;\
1471 JNI_END
1472 
1473 // the runtime type of subword integral basic types is integer
1474 DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN
1475                   , HOTSPOT_JNI_CALLBOOLEANMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1476                   HOTSPOT_JNI_CALLBOOLEANMETHODV_RETURN(_ret_ref))
1477 DEFINE_CALLMETHODV(jbyte,    Byte,    T_BYTE
1478                   , HOTSPOT_JNI_CALLBYTEMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1479                   HOTSPOT_JNI_CALLBYTEMETHODV_RETURN(_ret_ref))
1480 DEFINE_CALLMETHODV(jchar,    Char,    T_CHAR
1481                   , HOTSPOT_JNI_CALLCHARMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1482                   HOTSPOT_JNI_CALLCHARMETHODV_RETURN(_ret_ref))
1483 DEFINE_CALLMETHODV(jshort,   Short,   T_SHORT
1484                   , HOTSPOT_JNI_CALLSHORTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1485                   HOTSPOT_JNI_CALLSHORTMETHODV_RETURN(_ret_ref))
1486 
1487 DEFINE_CALLMETHODV(jobject,  Object,  T_OBJECT
1488                   , HOTSPOT_JNI_CALLOBJECTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1489                   HOTSPOT_JNI_CALLOBJECTMETHODV_RETURN(_ret_ref))
1490 DEFINE_CALLMETHODV(jint,     Int,     T_INT,
1491                   HOTSPOT_JNI_CALLINTMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1492                   HOTSPOT_JNI_CALLINTMETHODV_RETURN(_ret_ref))
1493 DEFINE_CALLMETHODV(jlong,    Long,    T_LONG
1494                   , HOTSPOT_JNI_CALLLONGMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1495                   HOTSPOT_JNI_CALLLONGMETHODV_RETURN(_ret_ref))
1496 // Float and double probes don't return value because dtrace doesn't currently support it
1497 DEFINE_CALLMETHODV(jfloat,   Float,   T_FLOAT
1498                   , HOTSPOT_JNI_CALLFLOATMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1499                   HOTSPOT_JNI_CALLFLOATMETHODV_RETURN())
1500 DEFINE_CALLMETHODV(jdouble,  Double,  T_DOUBLE
1501                   , HOTSPOT_JNI_CALLDOUBLEMETHODV_ENTRY(env, obj, (uintptr_t)methodID),
1502                   HOTSPOT_JNI_CALLDOUBLEMETHODV_RETURN())
1503 
1504 #define DEFINE_CALLMETHODA(ResultType, Result, Tag \
1505                           , EntryProbe, ReturnProbe)    \
1506 \
1507   DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \
1508                           , ReturnProbe);                          \
1509 \
1510 JNI_ENTRY(ResultType, \
1511           jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \
1512   JNIWrapper("Call" XSTR(Result) "MethodA"); \
1513   EntryProbe; \
1514   ResultType ret = 0;\
1515   DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \
1516                      (const ResultType&)ret);\
1517 \
1518   JavaValue jvalue(Tag); \
1519   JNI_ArgumentPusherArray ap(methodID, args); \
1520   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \
1521   ret = jvalue.get_##ResultType(); \
1522   return ret;\
1523 JNI_END
1524 
1525 // the runtime type of subword integral basic types is integer
1526 DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN
1527                   , HOTSPOT_JNI_CALLBOOLEANMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1528                   HOTSPOT_JNI_CALLBOOLEANMETHODA_RETURN(_ret_ref))
1529 DEFINE_CALLMETHODA(jbyte,    Byte,    T_BYTE
1530                   , HOTSPOT_JNI_CALLBYTEMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1531                   HOTSPOT_JNI_CALLBYTEMETHODA_RETURN(_ret_ref))
1532 DEFINE_CALLMETHODA(jchar,    Char,    T_CHAR
1533                   , HOTSPOT_JNI_CALLCHARMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1534                   HOTSPOT_JNI_CALLCHARMETHODA_RETURN(_ret_ref))
1535 DEFINE_CALLMETHODA(jshort,   Short,   T_SHORT
1536                   , HOTSPOT_JNI_CALLSHORTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1537                   HOTSPOT_JNI_CALLSHORTMETHODA_RETURN(_ret_ref))
1538 
1539 DEFINE_CALLMETHODA(jobject,  Object,  T_OBJECT
1540                   , HOTSPOT_JNI_CALLOBJECTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1541                   HOTSPOT_JNI_CALLOBJECTMETHODA_RETURN(_ret_ref))
1542 DEFINE_CALLMETHODA(jint,     Int,     T_INT,
1543                   HOTSPOT_JNI_CALLINTMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1544                   HOTSPOT_JNI_CALLINTMETHODA_RETURN(_ret_ref))
1545 DEFINE_CALLMETHODA(jlong,    Long,    T_LONG
1546                   , HOTSPOT_JNI_CALLLONGMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1547                   HOTSPOT_JNI_CALLLONGMETHODA_RETURN(_ret_ref))
1548 // Float and double probes don't return value because dtrace doesn't currently support it
1549 DEFINE_CALLMETHODA(jfloat,   Float,   T_FLOAT
1550                   , HOTSPOT_JNI_CALLFLOATMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1551                   HOTSPOT_JNI_CALLFLOATMETHODA_RETURN())
1552 DEFINE_CALLMETHODA(jdouble,  Double,  T_DOUBLE
1553                   , HOTSPOT_JNI_CALLDOUBLEMETHODA_ENTRY(env, obj, (uintptr_t)methodID),
1554                   HOTSPOT_JNI_CALLDOUBLEMETHODA_RETURN())
1555 
1556 DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN());
1557 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN());
1558 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN());
1559 
1560 
1561 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...))
1562   JNIWrapper("CallVoidMethod");
1563   HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY(env, obj, (uintptr_t) methodID);
1564   DT_VOID_RETURN_MARK(CallVoidMethod);
1565 
1566   va_list args;
1567   va_start(args, methodID);
1568   JavaValue jvalue(T_VOID);
1569   JNI_ArgumentPusherVaArg ap(methodID, args);
1570   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1571   va_end(args);
1572 JNI_END
1573 
1574 
1575 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args))
1576   JNIWrapper("CallVoidMethodV");
1577   HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY(env, obj, (uintptr_t) methodID);
1578   DT_VOID_RETURN_MARK(CallVoidMethodV);
1579 
1580   JavaValue jvalue(T_VOID);
1581   JNI_ArgumentPusherVaArg ap(methodID, args);
1582   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1583 JNI_END
1584 
1585 
1586 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args))
1587   JNIWrapper("CallVoidMethodA");
1588   HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY(env, obj, (uintptr_t) methodID);
1589   DT_VOID_RETURN_MARK(CallVoidMethodA);
1590 
1591   JavaValue jvalue(T_VOID);
1592   JNI_ArgumentPusherArray ap(methodID, args);
1593   jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK);
1594 JNI_END
1595 
1596 
1597 
1598 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \
1599                                     , EntryProbe, ReturnProbe)      \
1600 \
1601   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \
1602                           , ReturnProbe);\
1603 \
1604 JNI_ENTRY(ResultType, \
1605           jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \
1606   JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \
1607 \
1608   EntryProbe;\
1609   ResultType ret;\
1610   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \
1611                      (const ResultType&)ret);\
1612 \
1613   va_list args; \
1614   va_start(args, methodID); \
1615   JavaValue jvalue(Tag); \
1616   JNI_ArgumentPusherVaArg ap(methodID, args); \
1617   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
1618   va_end(args); \
1619   ret = jvalue.get_##ResultType(); \
1620   return ret;\
1621 JNI_END
1622 
1623 // the runtime type of subword integral basic types is integer
1624 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN
1625                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1626                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref))
1627 DEFINE_CALLNONVIRTUALMETHOD(jbyte,    Byte,    T_BYTE
1628                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1629                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref))
1630 DEFINE_CALLNONVIRTUALMETHOD(jchar,    Char,    T_CHAR
1631                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1632                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref))
1633 DEFINE_CALLNONVIRTUALMETHOD(jshort,   Short,   T_SHORT
1634                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1635                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref))
1636 
1637 DEFINE_CALLNONVIRTUALMETHOD(jobject,  Object,  T_OBJECT
1638                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1639                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref))
1640 DEFINE_CALLNONVIRTUALMETHOD(jint,     Int,     T_INT
1641                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1642                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref))
1643 DEFINE_CALLNONVIRTUALMETHOD(jlong,    Long,    T_LONG
1644                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1645 // Float and double probes don't return value because dtrace doesn't currently support it
1646                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref))
1647 DEFINE_CALLNONVIRTUALMETHOD(jfloat,   Float,   T_FLOAT
1648                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1649                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN())
1650 DEFINE_CALLNONVIRTUALMETHOD(jdouble,  Double,  T_DOUBLE
1651                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID),
1652                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN())
1653 
1654 #define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \
1655                                     , EntryProbe, ReturnProbe)      \
1656 \
1657   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \
1658                           , ReturnProbe);\
1659 \
1660 JNI_ENTRY(ResultType, \
1661           jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \
1662   JNIWrapper("CallNonvitual" XSTR(Result) "MethodV"); \
1663 \
1664   EntryProbe;\
1665   ResultType ret;\
1666   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \
1667                      (const ResultType&)ret);\
1668 \
1669   JavaValue jvalue(Tag); \
1670   JNI_ArgumentPusherVaArg ap(methodID, args); \
1671   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
1672   ret = jvalue.get_##ResultType(); \
1673   return ret;\
1674 JNI_END
1675 
1676 // the runtime type of subword integral basic types is integer
1677 DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN
1678                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1679                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref))
1680 DEFINE_CALLNONVIRTUALMETHODV(jbyte,    Byte,    T_BYTE
1681                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1682                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref))
1683 DEFINE_CALLNONVIRTUALMETHODV(jchar,    Char,    T_CHAR
1684                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1685                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref))
1686 DEFINE_CALLNONVIRTUALMETHODV(jshort,   Short,   T_SHORT
1687                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1688                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref))
1689 
1690 DEFINE_CALLNONVIRTUALMETHODV(jobject,  Object,  T_OBJECT
1691                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1692                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref))
1693 DEFINE_CALLNONVIRTUALMETHODV(jint,     Int,     T_INT
1694                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1695                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref))
1696 DEFINE_CALLNONVIRTUALMETHODV(jlong,    Long,    T_LONG
1697                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1698 // Float and double probes don't return value because dtrace doesn't currently support it
1699                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref))
1700 DEFINE_CALLNONVIRTUALMETHODV(jfloat,   Float,   T_FLOAT
1701                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1702                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN())
1703 DEFINE_CALLNONVIRTUALMETHODV(jdouble,  Double,  T_DOUBLE
1704                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID),
1705                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN())
1706 
1707 #define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \
1708                                     , EntryProbe, ReturnProbe)      \
1709 \
1710   DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \
1711                           , ReturnProbe);\
1712 \
1713 JNI_ENTRY(ResultType, \
1714           jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \
1715   JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \
1716 \
1717   EntryProbe;\
1718   ResultType ret;\
1719   DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \
1720                      (const ResultType&)ret);\
1721 \
1722   JavaValue jvalue(Tag); \
1723   JNI_ArgumentPusherArray ap(methodID, args); \
1724   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \
1725   ret = jvalue.get_##ResultType(); \
1726   return ret;\
1727 JNI_END
1728 
1729 // the runtime type of subword integral basic types is integer
1730 DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN
1731                             , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1732                             HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref))
1733 DEFINE_CALLNONVIRTUALMETHODA(jbyte,    Byte,    T_BYTE
1734                             , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1735                             HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref))
1736 DEFINE_CALLNONVIRTUALMETHODA(jchar,    Char,    T_CHAR
1737                             , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1738                             HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref))
1739 DEFINE_CALLNONVIRTUALMETHODA(jshort,   Short,   T_SHORT
1740                             , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1741                             HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref))
1742 
1743 DEFINE_CALLNONVIRTUALMETHODA(jobject,  Object,  T_OBJECT
1744                             , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1745                             HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref))
1746 DEFINE_CALLNONVIRTUALMETHODA(jint,     Int,     T_INT
1747                             , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1748                             HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref))
1749 DEFINE_CALLNONVIRTUALMETHODA(jlong,    Long,    T_LONG
1750                             , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1751 // Float and double probes don't return value because dtrace doesn't currently support it
1752                             HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref))
1753 DEFINE_CALLNONVIRTUALMETHODA(jfloat,   Float,   T_FLOAT
1754                             , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1755                             HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN())
1756 DEFINE_CALLNONVIRTUALMETHODA(jdouble,  Double,  T_DOUBLE
1757                             , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID),
1758                             HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN())
1759 
1760 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod
1761                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN());
1762 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV
1763                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN());
1764 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA
1765                          , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN());
1766 
1767 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...))
1768   JNIWrapper("CallNonvirtualVoidMethod");
1769 
1770   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY(env, obj, cls, (uintptr_t) methodID);
1771   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod);
1772 
1773   va_list args;
1774   va_start(args, methodID);
1775   JavaValue jvalue(T_VOID);
1776   JNI_ArgumentPusherVaArg ap(methodID, args);
1777   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
1778   va_end(args);
1779 JNI_END
1780 
1781 
1782 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args))
1783   JNIWrapper("CallNonvirtualVoidMethodV");
1784 
1785   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY(
1786                env, obj, cls, (uintptr_t) methodID);
1787   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV);
1788 
1789   JavaValue jvalue(T_VOID);
1790   JNI_ArgumentPusherVaArg ap(methodID, args);
1791   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
1792 JNI_END
1793 
1794 
1795 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args))
1796   JNIWrapper("CallNonvirtualVoidMethodA");
1797   HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY(
1798                 env, obj, cls, (uintptr_t) methodID);
1799   DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA);
1800   JavaValue jvalue(T_VOID);
1801   JNI_ArgumentPusherArray ap(methodID, args);
1802   jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK);
1803 JNI_END
1804 
1805 
1806 
1807 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \
1808                                 , EntryProbe, ResultProbe) \
1809 \
1810   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \
1811                           , ResultProbe);                               \
1812 \
1813 JNI_ENTRY(ResultType, \
1814           jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \
1815   JNIWrapper("CallStatic" XSTR(Result) "Method"); \
1816 \
1817   EntryProbe; \
1818   ResultType ret = 0;\
1819   DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \
1820                      (const ResultType&)ret);\
1821 \
1822   va_list args; \
1823   va_start(args, methodID); \
1824   JavaValue jvalue(Tag); \
1825   JNI_ArgumentPusherVaArg ap(methodID, args); \
1826   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
1827   va_end(args); \
1828   ret = jvalue.get_##ResultType(); \
1829   return ret;\
1830 JNI_END
1831 
1832 // the runtime type of subword integral basic types is integer
1833 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN
1834                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1835                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref));
1836 DEFINE_CALLSTATICMETHOD(jbyte,    Byte,    T_BYTE
1837                         , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1838                         HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref));
1839 DEFINE_CALLSTATICMETHOD(jchar,    Char,    T_CHAR
1840                         , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1841                         HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref));
1842 DEFINE_CALLSTATICMETHOD(jshort,   Short,   T_SHORT
1843                         , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1844                         HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref));
1845 
1846 DEFINE_CALLSTATICMETHOD(jobject,  Object,  T_OBJECT
1847                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1848                         HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref));
1849 DEFINE_CALLSTATICMETHOD(jint,     Int,     T_INT
1850                         , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1851                         HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref));
1852 DEFINE_CALLSTATICMETHOD(jlong,    Long,    T_LONG
1853                         , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1854                         HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref));
1855 // Float and double probes don't return value because dtrace doesn't currently support it
1856 DEFINE_CALLSTATICMETHOD(jfloat,   Float,   T_FLOAT
1857                         , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1858                         HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN());
1859 DEFINE_CALLSTATICMETHOD(jdouble,  Double,  T_DOUBLE
1860                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID),
1861                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN());
1862 
1863 #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \
1864                                 , EntryProbe, ResultProbe) \
1865 \
1866   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \
1867                           , ResultProbe);                               \
1868 \
1869 JNI_ENTRY(ResultType, \
1870           jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \
1871   JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \
1872 \
1873   EntryProbe; \
1874   ResultType ret = 0;\
1875   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \
1876                      (const ResultType&)ret);\
1877 \
1878   JavaValue jvalue(Tag); \
1879   JNI_ArgumentPusherVaArg ap(methodID, args); \
1880   /* Make sure class is initialized before trying to invoke its method */ \
1881   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); \
1882   k->initialize(CHECK_0); \
1883   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
1884   va_end(args); \
1885   ret = jvalue.get_##ResultType(); \
1886   return ret;\
1887 JNI_END
1888 
1889 // the runtime type of subword integral basic types is integer
1890 DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN
1891                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1892                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref));
1893 DEFINE_CALLSTATICMETHODV(jbyte,    Byte,    T_BYTE
1894                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1895                         HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref));
1896 DEFINE_CALLSTATICMETHODV(jchar,    Char,    T_CHAR
1897                         , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1898                         HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref));
1899 DEFINE_CALLSTATICMETHODV(jshort,   Short,   T_SHORT
1900                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1901                         HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref));
1902 
1903 DEFINE_CALLSTATICMETHODV(jobject,  Object,  T_OBJECT
1904                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1905                         HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref));
1906 DEFINE_CALLSTATICMETHODV(jint,     Int,     T_INT
1907                         , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1908                         HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref));
1909 DEFINE_CALLSTATICMETHODV(jlong,    Long,    T_LONG
1910                         , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1911                         HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref));
1912 // Float and double probes don't return value because dtrace doesn't currently support it
1913 DEFINE_CALLSTATICMETHODV(jfloat,   Float,   T_FLOAT
1914                         , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1915                         HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN());
1916 DEFINE_CALLSTATICMETHODV(jdouble,  Double,  T_DOUBLE
1917                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID),
1918                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN());
1919 
1920 #define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \
1921                                 , EntryProbe, ResultProbe) \
1922 \
1923   DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \
1924                           , ResultProbe);                               \
1925 \
1926 JNI_ENTRY(ResultType, \
1927           jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \
1928   JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \
1929 \
1930   EntryProbe; \
1931   ResultType ret = 0;\
1932   DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \
1933                      (const ResultType&)ret);\
1934 \
1935   JavaValue jvalue(Tag); \
1936   JNI_ArgumentPusherArray ap(methodID, args); \
1937   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \
1938   ret = jvalue.get_##ResultType(); \
1939   return ret;\
1940 JNI_END
1941 
1942 // the runtime type of subword integral basic types is integer
1943 DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN
1944                         , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1945                         HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref));
1946 DEFINE_CALLSTATICMETHODA(jbyte,    Byte,    T_BYTE
1947                         , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1948                         HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref));
1949 DEFINE_CALLSTATICMETHODA(jchar,    Char,    T_CHAR
1950                         , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1951                         HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref));
1952 DEFINE_CALLSTATICMETHODA(jshort,   Short,   T_SHORT
1953                         , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1954                         HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref));
1955 
1956 DEFINE_CALLSTATICMETHODA(jobject,  Object,  T_OBJECT
1957                         , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1958                         HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref));
1959 DEFINE_CALLSTATICMETHODA(jint,     Int,     T_INT
1960                         , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1961                         HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref));
1962 DEFINE_CALLSTATICMETHODA(jlong,    Long,    T_LONG
1963                         , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1964                         HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref));
1965 // Float and double probes don't return value because dtrace doesn't currently support it
1966 DEFINE_CALLSTATICMETHODA(jfloat,   Float,   T_FLOAT
1967                         , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1968                         HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN());
1969 DEFINE_CALLSTATICMETHODA(jdouble,  Double,  T_DOUBLE
1970                         , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID),
1971                         HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN());
1972 
1973 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod
1974                          , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN());
1975 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV
1976                          , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN());
1977 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA
1978                          , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN());
1979 
1980 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...))
1981   JNIWrapper("CallStaticVoidMethod");
1982   HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY(env, cls, (uintptr_t) methodID);
1983   DT_VOID_RETURN_MARK(CallStaticVoidMethod);
1984 
1985   va_list args;
1986   va_start(args, methodID);
1987   JavaValue jvalue(T_VOID);
1988   JNI_ArgumentPusherVaArg ap(methodID, args);
1989   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK);
1990   va_end(args);
1991 JNI_END
1992 
1993 
1994 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args))
1995   JNIWrapper("CallStaticVoidMethodV");
1996   HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY(env, cls, (uintptr_t) methodID);
1997   DT_VOID_RETURN_MARK(CallStaticVoidMethodV);
1998 
1999   JavaValue jvalue(T_VOID);
2000   JNI_ArgumentPusherVaArg ap(methodID, args);
2001   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK);
2002 JNI_END
2003 
2004 
2005 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args))
2006   JNIWrapper("CallStaticVoidMethodA");
2007   HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY(env, cls, (uintptr_t) methodID);
2008   DT_VOID_RETURN_MARK(CallStaticVoidMethodA);
2009 
2010   JavaValue jvalue(T_VOID);
2011   JNI_ArgumentPusherArray ap(methodID, args);
2012   jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK);
2013 JNI_END
2014 
2015 
2016 //
2017 // Accessing Fields
2018 //
2019 
2020 
2021 DT_RETURN_MARK_DECL(GetFieldID, jfieldID
2022                     , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref));
2023 
2024 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz,
2025           const char *name, const char *sig))
2026   JNIWrapper("GetFieldID");
2027   HOTSPOT_JNI_GETFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
2028   jfieldID ret = 0;
2029   DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret);
2030 
2031   // The class should have been loaded (we have an instance of the class
2032   // passed in) so the field and signature should already be in the symbol
2033   // table.  If they're not there, the field doesn't exist.
2034   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
2035   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
2036   if (fieldname == NULL || signame == NULL) {
2037     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2038   }
2039   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2040   // Make sure class is initialized before handing id's out to fields
2041   k->initialize(CHECK_NULL);
2042 
2043   fieldDescriptor fd;
2044   if (!k->is_instance_klass() ||
2045       !InstanceKlass::cast(k)->find_field(fieldname, signame, false, &fd)) {
2046     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2047   }
2048 
2049   // A jfieldID for a non-static field is simply the offset of the field within the instanceOop
2050   // It may also have hash bits for k, if VerifyJNIFields is turned on.
2051   ret = jfieldIDWorkaround::to_instance_jfieldID(k, fd.offset());
2052   return ret;
2053 JNI_END
2054 
2055 
2056 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID))
2057   JNIWrapper("GetObjectField");
2058   HOTSPOT_JNI_GETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID);
2059   oop o = JNIHandles::resolve_non_null(obj);
2060   Klass* k = o->klass();
2061   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2062   // Keep JVMTI addition small and only check enabled flag here.
2063   // jni_GetField_probe() assumes that is okay to create handles.
2064   if (JvmtiExport::should_post_field_access()) {
2065     o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false);
2066   }
2067   oop loaded_obj = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(o, offset);
2068   jobject ret = JNIHandles::make_local(env, loaded_obj);
2069   HOTSPOT_JNI_GETOBJECTFIELD_RETURN(ret);
2070   return ret;
2071 JNI_END
2072 
2073 
2074 
2075 #define DEFINE_GETFIELD(Return,Fieldname,Result \
2076   , EntryProbe, ReturnProbe) \
2077 \
2078   DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \
2079   , ReturnProbe); \
2080 \
2081 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \
2082   JNIWrapper("Get" XSTR(Result) "Field"); \
2083 \
2084   EntryProbe; \
2085   Return ret = 0;\
2086   DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\
2087 \
2088   oop o = JNIHandles::resolve_non_null(obj); \
2089   Klass* k = o->klass(); \
2090   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
2091   /* Keep JVMTI addition small and only check enabled flag here.       */ \
2092   /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \
2093   /* and creates a ResetNoHandleMark.                                   */ \
2094   if (JvmtiExport::should_post_field_access()) { \
2095     o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \
2096   } \
2097   ret = o->Fieldname##_field(offset); \
2098   return ret; \
2099 JNI_END
2100 
2101 DEFINE_GETFIELD(jboolean, bool,   Boolean
2102                 , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2103                 HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref))
2104 DEFINE_GETFIELD(jbyte,    byte,   Byte
2105                 , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2106                 HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref))
2107 DEFINE_GETFIELD(jchar,    char,   Char
2108                 , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2109                 HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref))
2110 DEFINE_GETFIELD(jshort,   short,  Short
2111                 , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2112                 HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref))
2113 DEFINE_GETFIELD(jint,     int,    Int
2114                 , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2115                 HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref))
2116 DEFINE_GETFIELD(jlong,    long,   Long
2117                 , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2118                 HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref))
2119 // Float and double probes don't return value because dtrace doesn't currently support it
2120 DEFINE_GETFIELD(jfloat,   float,  Float
2121                 , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2122                 HOTSPOT_JNI_GETFLOATFIELD_RETURN())
2123 DEFINE_GETFIELD(jdouble,  double, Double
2124                 , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2125                 HOTSPOT_JNI_GETDOUBLEFIELD_RETURN())
2126 
2127 address jni_GetBooleanField_addr() {
2128   return (address)jni_GetBooleanField;
2129 }
2130 address jni_GetByteField_addr() {
2131   return (address)jni_GetByteField;
2132 }
2133 address jni_GetCharField_addr() {
2134   return (address)jni_GetCharField;
2135 }
2136 address jni_GetShortField_addr() {
2137   return (address)jni_GetShortField;
2138 }
2139 address jni_GetIntField_addr() {
2140   return (address)jni_GetIntField;
2141 }
2142 address jni_GetLongField_addr() {
2143   return (address)jni_GetLongField;
2144 }
2145 address jni_GetFloatField_addr() {
2146   return (address)jni_GetFloatField;
2147 }
2148 address jni_GetDoubleField_addr() {
2149   return (address)jni_GetDoubleField;
2150 }
2151 
2152 JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value))
2153   JNIWrapper("SetObjectField");
2154   HOTSPOT_JNI_SETOBJECTFIELD_ENTRY(env, obj, (uintptr_t) fieldID, value);
2155   oop o = JNIHandles::resolve_non_null(obj);
2156   Klass* k = o->klass();
2157   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2158   // Keep JVMTI addition small and only check enabled flag here.
2159   // jni_SetField_probe_nh() assumes that is not okay to create handles
2160   // and creates a ResetNoHandleMark.
2161   if (JvmtiExport::should_post_field_modification()) {
2162     jvalue field_value;
2163     field_value.l = value;
2164     o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value);
2165   }
2166   HeapAccess<ON_UNKNOWN_OOP_REF>::oop_store_at(o, offset, JNIHandles::resolve(value));
2167   HOTSPOT_JNI_SETOBJECTFIELD_RETURN();
2168 JNI_END
2169 
2170 
2171 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \
2172                         , EntryProbe, ReturnProbe) \
2173 \
2174 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \
2175   JNIWrapper("Set" XSTR(Result) "Field"); \
2176 \
2177   EntryProbe; \
2178 \
2179   oop o = JNIHandles::resolve_non_null(obj); \
2180   Klass* k = o->klass(); \
2181   int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);  \
2182   /* Keep JVMTI addition small and only check enabled flag here.       */ \
2183   /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \
2184   /* and creates a ResetNoHandleMark.                                   */ \
2185   if (JvmtiExport::should_post_field_modification()) { \
2186     jvalue field_value; \
2187     field_value.unionType = value; \
2188     o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \
2189   } \
2190   if (SigType == 'Z') { value = ((jboolean)value) & 1; } \
2191   o->Fieldname##_field_put(offset, value); \
2192   ReturnProbe; \
2193 JNI_END
2194 
2195 DEFINE_SETFIELD(jboolean, bool,   Boolean, 'Z', z
2196                 , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2197                 HOTSPOT_JNI_SETBOOLEANFIELD_RETURN())
2198 DEFINE_SETFIELD(jbyte,    byte,   Byte,    'B', b
2199                 , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2200                 HOTSPOT_JNI_SETBYTEFIELD_RETURN())
2201 DEFINE_SETFIELD(jchar,    char,   Char,    'C', c
2202                 , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2203                 HOTSPOT_JNI_SETCHARFIELD_RETURN())
2204 DEFINE_SETFIELD(jshort,   short,  Short,   'S', s
2205                 , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2206                 HOTSPOT_JNI_SETSHORTFIELD_RETURN())
2207 DEFINE_SETFIELD(jint,     int,    Int,     'I', i
2208                 , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2209                 HOTSPOT_JNI_SETINTFIELD_RETURN())
2210 DEFINE_SETFIELD(jlong,    long,   Long,    'J', j
2211                 , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value),
2212                 HOTSPOT_JNI_SETLONGFIELD_RETURN())
2213 // Float and double probes don't return value because dtrace doesn't currently support it
2214 DEFINE_SETFIELD(jfloat,   float,  Float,   'F', f
2215                 , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2216                 HOTSPOT_JNI_SETFLOATFIELD_RETURN())
2217 DEFINE_SETFIELD(jdouble,  double, Double,  'D', d
2218                 , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID),
2219                 HOTSPOT_JNI_SETDOUBLEFIELD_RETURN())
2220 
2221 DT_RETURN_MARK_DECL(ToReflectedField, jobject
2222                     , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref));
2223 
2224 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic))
2225   JNIWrapper("ToReflectedField");
2226   HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY(env, cls, (uintptr_t) fieldID, isStatic);
2227   jobject ret = NULL;
2228   DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret);
2229 
2230   fieldDescriptor fd;
2231   bool found = false;
2232   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2233 
2234   assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID");
2235 
2236   if (isStatic) {
2237     // Static field. The fieldID a JNIid specifying the field holder and the offset within the Klass*.
2238     JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2239     assert(id->is_static_field_id(), "invalid static field id");
2240     found = id->find_local_field(&fd);
2241   } else {
2242     // Non-static field. The fieldID is really the offset of the field within the instanceOop.
2243     int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
2244     found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, &fd);
2245   }
2246   assert(found, "bad fieldID passed into jni_ToReflectedField");
2247   oop reflected = Reflection::new_field(&fd, CHECK_NULL);
2248   ret = JNIHandles::make_local(env, reflected);
2249   return ret;
2250 JNI_END
2251 
2252 
2253 //
2254 // Accessing Static Fields
2255 //
2256 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID
2257                     , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref));
2258 
2259 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz,
2260           const char *name, const char *sig))
2261   JNIWrapper("GetStaticFieldID");
2262   HOTSPOT_JNI_GETSTATICFIELDID_ENTRY(env, clazz, (char *) name, (char *) sig);
2263   jfieldID ret = NULL;
2264   DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret);
2265 
2266   // The class should have been loaded (we have an instance of the class
2267   // passed in) so the field and signature should already be in the symbol
2268   // table.  If they're not there, the field doesn't exist.
2269   TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name));
2270   TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig));
2271   if (fieldname == NULL || signame == NULL) {
2272     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2273   }
2274   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2275   // Make sure class is initialized before handing id's out to static fields
2276   k->initialize(CHECK_NULL);
2277 
2278   fieldDescriptor fd;
2279   if (!k->is_instance_klass() ||
2280       !InstanceKlass::cast(k)->find_field(fieldname, signame, true, &fd)) {
2281     THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name);
2282   }
2283 
2284   // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass*
2285   JNIid* id = fd.field_holder()->jni_id_for(fd.offset());
2286   debug_only(id->set_is_static_field_id();)
2287 
2288   debug_only(id->verify(fd.field_holder()));
2289 
2290   ret = jfieldIDWorkaround::to_static_jfieldID(id);
2291   return ret;
2292 JNI_END
2293 
2294 
2295 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID))
2296   JNIWrapper("GetStaticObjectField");
2297   HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID);
2298 #if INCLUDE_JNI_CHECK
2299   DEBUG_ONLY(Klass* param_k = jniCheck::validate_class(thread, clazz);)
2300 #endif // INCLUDE_JNI_CHECK
2301   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2302   assert(id->is_static_field_id(), "invalid static field id");
2303   // Keep JVMTI addition small and only check enabled flag here.
2304   // jni_GetField_probe() assumes that is okay to create handles.
2305   if (JvmtiExport::should_post_field_access()) {
2306     JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true);
2307   }
2308   jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset()));
2309   HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN(ret);
2310   return ret;
2311 JNI_END
2312 
2313 
2314 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \
2315                               , EntryProbe, ReturnProbe) \
2316 \
2317   DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \
2318                           , ReturnProbe);                                          \
2319 \
2320 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \
2321   JNIWrapper("GetStatic" XSTR(Result) "Field"); \
2322   EntryProbe; \
2323   Return ret = 0;\
2324   DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \
2325                      (const Return&)ret);\
2326   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
2327   assert(id->is_static_field_id(), "invalid static field id"); \
2328   /* Keep JVMTI addition small and only check enabled flag here. */ \
2329   /* jni_GetField_probe() assumes that is okay to create handles. */ \
2330   if (JvmtiExport::should_post_field_access()) { \
2331     JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \
2332   } \
2333   ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \
2334   return ret;\
2335 JNI_END
2336 
2337 DEFINE_GETSTATICFIELD(jboolean, bool,   Boolean
2338                       , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref))
2339 DEFINE_GETSTATICFIELD(jbyte,    byte,   Byte
2340                       , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref)   )
2341 DEFINE_GETSTATICFIELD(jchar,    char,   Char
2342                       , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref)   )
2343 DEFINE_GETSTATICFIELD(jshort,   short,  Short
2344                       , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref)  )
2345 DEFINE_GETSTATICFIELD(jint,     int,    Int
2346                       , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),     HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref)    )
2347 DEFINE_GETSTATICFIELD(jlong,    long,   Long
2348                       , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),    HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref)   )
2349 // Float and double probes don't return value because dtrace doesn't currently support it
2350 DEFINE_GETSTATICFIELD(jfloat,   float,  Float
2351                       , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),   HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN()          )
2352 DEFINE_GETSTATICFIELD(jdouble,  double, Double
2353                       , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),  HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN()         )
2354 
2355 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value))
2356   JNIWrapper("SetStaticObjectField");
2357  HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value);
2358   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
2359   assert(id->is_static_field_id(), "invalid static field id");
2360   // Keep JVMTI addition small and only check enabled flag here.
2361   // jni_SetField_probe() assumes that is okay to create handles.
2362   if (JvmtiExport::should_post_field_modification()) {
2363     jvalue field_value;
2364     field_value.l = value;
2365     JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value);
2366   }
2367   id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value));
2368   HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN();
2369 JNI_END
2370 
2371 
2372 
2373 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \
2374                               , EntryProbe, ReturnProbe) \
2375 \
2376 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \
2377   JNIWrapper("SetStatic" XSTR(Result) "Field"); \
2378   EntryProbe; \
2379 \
2380   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \
2381   assert(id->is_static_field_id(), "invalid static field id"); \
2382   /* Keep JVMTI addition small and only check enabled flag here. */ \
2383   /* jni_SetField_probe() assumes that is okay to create handles. */ \
2384   if (JvmtiExport::should_post_field_modification()) { \
2385     jvalue field_value; \
2386     field_value.unionType = value; \
2387     JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \
2388   } \
2389   if (SigType == 'Z') { value = ((jboolean)value) & 1; } \
2390   id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \
2391   ReturnProbe;\
2392 JNI_END
2393 
2394 DEFINE_SETSTATICFIELD(jboolean, bool,   Boolean, 'Z', z
2395                       , HOTSPOT_JNI_SETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value),
2396                       HOTSPOT_JNI_SETSTATICBOOLEANFIELD_RETURN())
2397 DEFINE_SETSTATICFIELD(jbyte,    byte,   Byte,    'B', b
2398                       , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2399                       HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN())
2400 DEFINE_SETSTATICFIELD(jchar,    char,   Char,    'C', c
2401                       , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2402                       HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN())
2403 DEFINE_SETSTATICFIELD(jshort,   short,  Short,   'S', s
2404                       , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2405                       HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN())
2406 DEFINE_SETSTATICFIELD(jint,     int,    Int,     'I', i
2407                       , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2408                       HOTSPOT_JNI_SETSTATICINTFIELD_RETURN())
2409 DEFINE_SETSTATICFIELD(jlong,    long,   Long,    'J', j
2410                       , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value),
2411                       HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN())
2412 // Float and double probes don't return value because dtrace doesn't currently support it
2413 DEFINE_SETSTATICFIELD(jfloat,   float,  Float,   'F', f
2414                       , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
2415                       HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN())
2416 DEFINE_SETSTATICFIELD(jdouble,  double, Double,  'D', d
2417                       , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID),
2418                       HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN())
2419 
2420 //
2421 // String Operations
2422 //
2423 
2424 // Unicode Interface
2425 
2426 DT_RETURN_MARK_DECL(NewString, jstring
2427                     , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref));
2428 
2429 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len))
2430   JNIWrapper("NewString");
2431  HOTSPOT_JNI_NEWSTRING_ENTRY(env, (uint16_t *) unicodeChars, len);
2432   jstring ret = NULL;
2433   DT_RETURN_MARK(NewString, jstring, (const jstring&)ret);
2434   oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL);
2435   ret = (jstring) JNIHandles::make_local(env, string);
2436   return ret;
2437 JNI_END
2438 
2439 
2440 JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string))
2441   JNIWrapper("GetStringLength");
2442   HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY(env, string);
2443   jsize ret = 0;
2444   oop s = JNIHandles::resolve_non_null(string);
2445   if (java_lang_String::value(s) != NULL) {
2446     ret = java_lang_String::length(s);
2447   }
2448  HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(ret);
2449   return ret;
2450 JNI_END
2451 
2452 
2453 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars(
2454   JNIEnv *env, jstring string, jboolean *isCopy))
2455   JNIWrapper("GetStringChars");
2456  HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(env, string, (uintptr_t *) isCopy);
2457   jchar* buf = NULL;
2458   oop s = JNIHandles::resolve_non_null(string);
2459   typeArrayOop s_value = java_lang_String::value(s);
2460   if (s_value != NULL) {
2461     int s_len = java_lang_String::length(s);
2462     bool is_latin1 = java_lang_String::is_latin1(s);
2463     buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
2464     /* JNI Specification states return NULL on OOM */
2465     if (buf != NULL) {
2466       if (s_len > 0) {
2467         if (!is_latin1) {
2468           HeapAccess<>::arraycopy<jchar>(s_value, (size_t) typeArrayOopDesc::element_offset<jchar>(0), NULL,
2469                                          NULL, 0, buf, s_len);
2470         } else {
2471           for (int i = 0; i < s_len; i++) {
2472             buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
2473           }
2474         }
2475       }
2476       buf[s_len] = 0;
2477       //%note jni_5
2478       if (isCopy != NULL) {
2479         *isCopy = JNI_TRUE;
2480       }
2481     }
2482   }
2483   HOTSPOT_JNI_GETSTRINGCHARS_RETURN(buf);
2484   return buf;
2485 JNI_END
2486 
2487 
2488 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars))
2489   JNIWrapper("ReleaseStringChars");
2490   HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY(env, str, (uint16_t *) chars);
2491   //%note jni_6
2492   if (chars != NULL) {
2493     // Since String objects are supposed to be immutable, don't copy any
2494     // new data back.  A bad user will have to go after the char array.
2495     FreeHeap((void*) chars);
2496   }
2497   HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN();
2498 JNI_END
2499 
2500 
2501 // UTF Interface
2502 
2503 DT_RETURN_MARK_DECL(NewStringUTF, jstring
2504                     , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref));
2505 
2506 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes))
2507   JNIWrapper("NewStringUTF");
2508   HOTSPOT_JNI_NEWSTRINGUTF_ENTRY(env, (char *) bytes);
2509   jstring ret;
2510   DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret);
2511 
2512   oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL);
2513   ret = (jstring) JNIHandles::make_local(env, result);
2514   return ret;
2515 JNI_END
2516 
2517 
2518 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string))
2519   JNIWrapper("GetStringUTFLength");
2520  HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY(env, string);
2521   jsize ret = 0;
2522   oop java_string = JNIHandles::resolve_non_null(string);
2523   if (java_lang_String::value(java_string) != NULL) {
2524     ret = java_lang_String::utf8_length(java_string);
2525   }
2526   HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN(ret);
2527   return ret;
2528 JNI_END
2529 
2530 
2531 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy))
2532   JNIWrapper("GetStringUTFChars");
2533  HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY(env, string, (uintptr_t *) isCopy);
2534   char* result = NULL;
2535   oop java_string = JNIHandles::resolve_non_null(string);
2536   if (java_lang_String::value(java_string) != NULL) {
2537     size_t length = java_lang_String::utf8_length(java_string);
2538     /* JNI Specification states return NULL on OOM */
2539     result = AllocateHeap(length + 1, mtInternal, 0, AllocFailStrategy::RETURN_NULL);
2540     if (result != NULL) {
2541       java_lang_String::as_utf8_string(java_string, result, (int) length + 1);
2542       if (isCopy != NULL) {
2543         *isCopy = JNI_TRUE;
2544       }
2545     }
2546   }
2547  HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN(result);
2548   return result;
2549 JNI_END
2550 
2551 
2552 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars))
2553   JNIWrapper("ReleaseStringUTFChars");
2554  HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY(env, str, (char *) chars);
2555   if (chars != NULL) {
2556     FreeHeap((char*) chars);
2557   }
2558 HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN();
2559 JNI_END
2560 
2561 
2562 JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array))
2563   JNIWrapper("GetArrayLength");
2564  HOTSPOT_JNI_GETARRAYLENGTH_ENTRY(env, array);
2565   arrayOop a = arrayOop(JNIHandles::resolve_non_null(array));
2566   assert(a->is_array(), "must be array");
2567   jsize ret = a->length();
2568  HOTSPOT_JNI_GETARRAYLENGTH_RETURN(ret);
2569   return ret;
2570 JNI_END
2571 
2572 
2573 //
2574 // Object Array Operations
2575 //
2576 
2577 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray
2578                     , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref));
2579 
2580 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement))
2581   JNIWrapper("NewObjectArray");
2582  HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY(env, length, elementClass, initialElement);
2583   jobjectArray ret = NULL;
2584   DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret);
2585   Klass* ek = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(elementClass));
2586   Klass* ak = ek->array_klass(CHECK_NULL);
2587   ObjArrayKlass::cast(ak)->initialize(CHECK_NULL);
2588   objArrayOop result = ObjArrayKlass::cast(ak)->allocate(length, CHECK_NULL);
2589   oop initial_value = JNIHandles::resolve(initialElement);
2590   if (initial_value != NULL) {  // array already initialized with NULL
2591     for (int index = 0; index < length; index++) {
2592       result->obj_at_put(index, initial_value);
2593     }
2594   }
2595   ret = (jobjectArray) JNIHandles::make_local(env, result);
2596   return ret;
2597 JNI_END
2598 
2599 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject
2600                     , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref));
2601 
2602 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index))
2603   JNIWrapper("GetObjectArrayElement");
2604  HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY(env, array, index);
2605   jobject ret = NULL;
2606   DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret);
2607   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2608   if (a->is_within_bounds(index)) {
2609     ret = JNIHandles::make_local(env, a->obj_at(index));
2610     return ret;
2611   } else {
2612     char buf[jintAsStringSize];
2613     sprintf(buf, "%d", index);
2614     THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf);
2615   }
2616 JNI_END
2617 
2618 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement
2619                          , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN());
2620 
2621 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value))
2622   JNIWrapper("SetObjectArrayElement");
2623  HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY(env, array, index, value);
2624   DT_VOID_RETURN_MARK(SetObjectArrayElement);
2625 
2626   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array));
2627   oop v = JNIHandles::resolve(value);
2628   if (a->is_within_bounds(index)) {
2629     if (v == NULL || v->is_a(ObjArrayKlass::cast(a->klass())->element_klass())) {
2630       a->obj_at_put(index, v);
2631     } else {
2632       THROW(vmSymbols::java_lang_ArrayStoreException());
2633     }
2634   } else {
2635     char buf[jintAsStringSize];
2636     sprintf(buf, "%d", index);
2637     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf);
2638   }
2639 JNI_END
2640 
2641 
2642 
2643 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \
2644                               ,EntryProbe,ReturnProbe)  \
2645 \
2646   DT_RETURN_MARK_DECL(New##Result##Array, Return \
2647                       , ReturnProbe); \
2648 \
2649 JNI_ENTRY(Return, \
2650           jni_New##Result##Array(JNIEnv *env, jsize len)) \
2651   JNIWrapper("New" XSTR(Result) "Array"); \
2652   EntryProbe; \
2653   Return ret = NULL;\
2654   DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\
2655 \
2656   oop obj= oopFactory::Allocator(len, CHECK_0); \
2657   ret = (Return) JNIHandles::make_local(env, obj); \
2658   return ret;\
2659 JNI_END
2660 
2661 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray,   Boolean,
2662                       HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len),
2663                       HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref))
2664 DEFINE_NEWSCALARARRAY(jbyteArray,    new_byteArray,   Byte,
2665                       HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len),
2666                       HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref))
2667 DEFINE_NEWSCALARARRAY(jshortArray,   new_shortArray,  Short,
2668                       HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len),
2669                       HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref))
2670 DEFINE_NEWSCALARARRAY(jcharArray,    new_charArray,   Char,
2671                       HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len),
2672                       HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref))
2673 DEFINE_NEWSCALARARRAY(jintArray,     new_intArray,    Int,
2674                       HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len),
2675                       HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref))
2676 DEFINE_NEWSCALARARRAY(jlongArray,    new_longArray,   Long,
2677                       HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len),
2678                       HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref))
2679 DEFINE_NEWSCALARARRAY(jfloatArray,   new_singleArray, Float,
2680                       HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len),
2681                       HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref))
2682 DEFINE_NEWSCALARARRAY(jdoubleArray,  new_doubleArray, Double,
2683                       HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len),
2684                       HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref))
2685 
2686 // Return an address which will fault if the caller writes to it.
2687 
2688 static char* get_bad_address() {
2689   static char* bad_address = NULL;
2690   if (bad_address == NULL) {
2691     size_t size = os::vm_allocation_granularity();
2692     bad_address = os::reserve_memory(size);
2693     if (bad_address != NULL) {
2694       os::protect_memory(bad_address, size, os::MEM_PROT_READ,
2695                          /*is_committed*/false);
2696       MemTracker::record_virtual_memory_type((void*)bad_address, mtInternal);
2697     }
2698   }
2699   return bad_address;
2700 }
2701 
2702 
2703 
2704 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \
2705                                       , EntryProbe, ReturnProbe) \
2706 \
2707 JNI_QUICK_ENTRY(ElementType*, \
2708           jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
2709   JNIWrapper("Get" XSTR(Result) "ArrayElements"); \
2710   EntryProbe; \
2711   /* allocate an chunk of memory in c land */ \
2712   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2713   ElementType* result; \
2714   int len = a->length(); \
2715   if (len == 0) { \
2716     /* Empty array: legal but useless, can't return NULL. \
2717      * Return a pointer to something useless. \
2718      * Avoid asserts in typeArrayOop. */ \
2719     result = (ElementType*)get_bad_address(); \
2720   } else { \
2721     /* JNI Specification states return NULL on OOM */                    \
2722     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
2723     if (result != NULL) {                                                \
2724       /* copy the array to the c chunk */                                \
2725       HeapAccess<>::arraycopy<ElementType>(a, typeArrayOopDesc::element_offset<ElementType>(0), NULL, \
2726                                            NULL, 0, result, len);        \
2727       if (isCopy) {                                                      \
2728         *isCopy = JNI_TRUE;                                              \
2729       }                                                                  \
2730     }                                                                    \
2731   } \
2732   ReturnProbe; \
2733   return result; \
2734 JNI_END
2735 
2736 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2737                               , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2738                               HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result))
2739 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2740                               , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2741                               HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result))
2742 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2743                               , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
2744                               HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result))
2745 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2746                               , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
2747                               HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result))
2748 DEFINE_GETSCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
2749                               , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2750                               HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result))
2751 DEFINE_GETSCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
2752                               , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2753                               HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result)))
2754 // Float and double probes don't return value because dtrace doesn't currently support it
2755 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
2756                               , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2757                               HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result))
2758 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
2759                               , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2760                               HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result))
2761 
2762 
2763 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \
2764                                           , EntryProbe, ReturnProbe);\
2765 \
2766 JNI_QUICK_ENTRY(void, \
2767           jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
2768                                              ElementType *buf, jint mode)) \
2769   JNIWrapper("Release" XSTR(Result) "ArrayElements"); \
2770   EntryProbe; \
2771   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2772   int len = a->length(); \
2773   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
2774     if ((mode == 0) || (mode == JNI_COMMIT)) { \
2775       HeapAccess<>::arraycopy<ElementType>(NULL, 0, buf, a, typeArrayOopDesc::element_offset<ElementType>(0), NULL, len); \
2776     } \
2777     if ((mode == 0) || (mode == JNI_ABORT)) { \
2778       FreeHeap(buf); \
2779     } \
2780   } \
2781   ReturnProbe; \
2782 JNI_END
2783 
2784 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2785                                   , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
2786                                   HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN())
2787 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2788                                   , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode),
2789                                   HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN())
2790 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2791                                   ,  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2792                                   HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN())
2793 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2794                                   ,  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2795                                   HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN())
2796 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT,     jint,     Int,     int
2797                                   , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode),
2798                                   HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN())
2799 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG,    jlong,    Long,    long
2800                                   , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
2801                                   HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN())
2802 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
2803                                   , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode),
2804                                   HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN())
2805 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
2806                                   , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode),
2807                                   HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN())
2808 
2809 
2810 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2811                                     , EntryProbe, ReturnProbe); \
2812   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \
2813                            , ReturnProbe); \
2814 \
2815 JNI_ENTRY(void, \
2816 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2817              jsize len, ElementType *buf)) \
2818   JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \
2819   EntryProbe; \
2820   DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
2821   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2822   if (start < 0 || len < 0 || (start > src->length() - len)) { \
2823     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
2824   } else { \
2825     if (len > 0) { \
2826       HeapAccess<>::arraycopy<ElementType>(src, typeArrayOopDesc::element_offset<ElementType>(start), NULL, NULL, 0, buf, len); \



2827     } \
2828   } \
2829 JNI_END
2830 
2831 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool
2832                             , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2833                             HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN());
2834 DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte
2835                             ,  HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2836                             HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN());
2837 DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short
2838                             , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2839                             HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN());
2840 DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char
2841                             ,  HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf),
2842                             HOTSPOT_JNI_GETCHARARRAYREGION_RETURN());
2843 DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int
2844                             , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf),
2845                             HOTSPOT_JNI_GETINTARRAYREGION_RETURN());
2846 DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long
2847                             ,  HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2848                             HOTSPOT_JNI_GETLONGARRAYREGION_RETURN());
2849 DEFINE_GETSCALARARRAYREGION(T_FLOAT,   jfloat,  Float,   float
2850                             , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
2851                             HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN());
2852 DEFINE_GETSCALARARRAYREGION(T_DOUBLE,  jdouble, Double,  double
2853                             , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2854                             HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN());
2855 
2856 
2857 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2858                                     , EntryProbe, ReturnProbe); \
2859   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \
2860                            ,ReturnProbe);           \
2861 \
2862 JNI_ENTRY(void, \
2863 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2864              jsize len, const ElementType *buf)) \
2865   JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \
2866   EntryProbe; \
2867   DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
2868   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2869   if (start < 0 || len < 0 || (start > dst->length() - len)) { \
2870     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
2871   } else { \
2872     if (len > 0) { \
2873       HeapAccess<>::arraycopy<ElementType>(NULL, 0, buf, dst, typeArrayOopDesc::element_offset<ElementType>(start), NULL, len); \



2874     } \
2875   } \
2876 JNI_END
2877 
2878 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool
2879                             , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf),
2880                             HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN())
2881 DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte
2882                             , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2883                             HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN())
2884 DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short
2885                             , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2886                             HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
2887 DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char
2888                             , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2889                             HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
2890 DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int
2891                             , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
2892                             HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
2893 DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long
2894                             , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2895                             HOTSPOT_JNI_SETLONGARRAYREGION_RETURN())
2896 DEFINE_SETSCALARARRAYREGION(T_FLOAT,   jfloat,   Float,   float
2897                             , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
2898                             HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN())
2899 DEFINE_SETSCALARARRAYREGION(T_DOUBLE,  jdouble,  Double,  double
2900                             , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2901                             HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN())
2902 
2903 
2904 //
2905 // Interception of natives
2906 //
2907 
2908 // The RegisterNatives call being attempted tried to register with a method that
2909 // is not native.  Ask JVM TI what prefixes have been specified.  Then check
2910 // to see if the native method is now wrapped with the prefixes.  See the
2911 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.
2912 static Method* find_prefixed_native(Klass* k, Symbol* name, Symbol* signature, TRAPS) {
2913 #if INCLUDE_JVMTI
2914   ResourceMark rm(THREAD);
2915   Method* method;
2916   int name_len = name->utf8_length();
2917   char* name_str = name->as_utf8();
2918   int prefix_count;
2919   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
2920   for (int i = 0; i < prefix_count; i++) {
2921     char* prefix = prefixes[i];
2922     int prefix_len = (int)strlen(prefix);
2923 
2924     // try adding this prefix to the method name and see if it matches another method name
2925     int trial_len = name_len + prefix_len;
2926     char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
2927     strcpy(trial_name_str, prefix);
2928     strcat(trial_name_str, name_str);
2929     TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len);
2930     if (trial_name == NULL) {
2931       continue; // no such symbol, so this prefix wasn't used, try the next prefix
2932     }
2933     method = k->lookup_method(trial_name, signature);
2934     if (method == NULL) {
2935       continue; // signature doesn't match, try the next prefix
2936     }
2937     if (method->is_native()) {
2938       method->set_is_prefixed_native();
2939       return method; // wahoo, we found a prefixed version of the method, return it
2940     }
2941     // found as non-native, so prefix is good, add it, probably just need more prefixes
2942     name_len = trial_len;
2943     name_str = trial_name_str;
2944   }
2945 #endif // INCLUDE_JVMTI
2946   return NULL; // not found
2947 }
2948 
2949 static bool register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
2950   Method* method = k->lookup_method(name, signature);
2951   if (method == NULL) {
2952     ResourceMark rm;
2953     stringStream st;
2954     st.print("Method %s name or signature does not match",
2955              Method::name_and_sig_as_C_string(k, name, signature));
2956     THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2957   }
2958   if (!method->is_native()) {
2959     // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
2960     method = find_prefixed_native(k, name, signature, THREAD);
2961     if (method == NULL) {
2962       ResourceMark rm;
2963       stringStream st;
2964       st.print("Method %s is not declared as native",
2965                Method::name_and_sig_as_C_string(k, name, signature));
2966       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2967     }
2968   }
2969 
2970   if (entry != NULL) {
2971     method->set_native_function(entry,
2972       Method::native_bind_event_is_interesting);
2973   } else {
2974     method->clear_native_function();
2975   }
2976   if (PrintJNIResolving) {
2977     ResourceMark rm(THREAD);
2978     tty->print_cr("[Registering JNI native method %s.%s]",
2979       method->method_holder()->external_name(),
2980       method->name()->as_C_string());
2981   }
2982   return true;
2983 }
2984 
2985 DT_RETURN_MARK_DECL(RegisterNatives, jint
2986                     , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref));
2987 
2988 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
2989                                     const JNINativeMethod *methods,
2990                                     jint nMethods))
2991   JNIWrapper("RegisterNatives");
2992   HOTSPOT_JNI_REGISTERNATIVES_ENTRY(env, clazz, (void *) methods, nMethods);
2993   jint ret = 0;
2994   DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
2995 
2996   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2997 
2998   for (int index = 0; index < nMethods; index++) {
2999     const char* meth_name = methods[index].name;
3000     const char* meth_sig = methods[index].signature;
3001     int meth_name_len = (int)strlen(meth_name);
3002 
3003     // The class should have been loaded (we have an instance of the class
3004     // passed in) so the method and signature should already be in the symbol
3005     // table.  If they're not there, the method doesn't exist.
3006     TempNewSymbol  name = SymbolTable::probe(meth_name, meth_name_len);
3007     TempNewSymbol  signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig));
3008 
3009     if (name == NULL || signature == NULL) {
3010       ResourceMark rm;
3011       stringStream st;
3012       st.print("Method %s.%s%s not found", k->external_name(), meth_name, meth_sig);
3013       // Must return negative value on failure
3014       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1);
3015     }
3016 
3017     bool res = register_native(k, name, signature,
3018                                (address) methods[index].fnPtr, THREAD);
3019     if (!res) {
3020       ret = -1;
3021       break;
3022     }
3023   }
3024   return ret;
3025 JNI_END
3026 
3027 
3028 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz))
3029   JNIWrapper("UnregisterNatives");
3030  HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(env, clazz);
3031   Klass* k   = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
3032   //%note jni_2
3033   if (k->is_instance_klass()) {
3034     for (int index = 0; index < InstanceKlass::cast(k)->methods()->length(); index++) {
3035       Method* m = InstanceKlass::cast(k)->methods()->at(index);
3036       if (m->is_native()) {
3037         m->clear_native_function();
3038         m->set_signature_handler(NULL);
3039       }
3040     }
3041   }
3042  HOTSPOT_JNI_UNREGISTERNATIVES_RETURN(0);
3043   return 0;
3044 JNI_END
3045 
3046 //
3047 // Monitor functions
3048 //
3049 
3050 DT_RETURN_MARK_DECL(MonitorEnter, jint
3051                     , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref));
3052 
3053 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj))
3054  HOTSPOT_JNI_MONITORENTER_ENTRY(env, jobj);
3055   jint ret = JNI_ERR;
3056   DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret);
3057 
3058   // If the object is null, we can't do anything with it
3059   if (jobj == NULL) {
3060     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
3061   }
3062 
3063   Handle obj(thread, JNIHandles::resolve_non_null(jobj));
3064   ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR));
3065   ret = JNI_OK;
3066   return ret;
3067 JNI_END
3068 
3069 DT_RETURN_MARK_DECL(MonitorExit, jint
3070                     , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref));
3071 
3072 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj))
3073  HOTSPOT_JNI_MONITOREXIT_ENTRY(env, jobj);
3074   jint ret = JNI_ERR;
3075   DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret);
3076 
3077   // Don't do anything with a null object
3078   if (jobj == NULL) {
3079     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR);
3080   }
3081 
3082   Handle obj(THREAD, JNIHandles::resolve_non_null(jobj));
3083   ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR));
3084 
3085   ret = JNI_OK;
3086   return ret;
3087 JNI_END
3088 
3089 //
3090 // Extensions
3091 //
3092 
3093 DT_VOID_RETURN_MARK_DECL(GetStringRegion
3094                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
3095 
3096 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
3097   JNIWrapper("GetStringRegion");
3098  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(env, string, start, len, buf);
3099   DT_VOID_RETURN_MARK(GetStringRegion);
3100   oop s = JNIHandles::resolve_non_null(string);
3101   int s_len = java_lang_String::length(s);
3102   if (start < 0 || len < 0 || start > s_len - len) {
3103     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
3104   } else {
3105     if (len > 0) {
3106       typeArrayOop s_value = java_lang_String::value(s);
3107       bool is_latin1 = java_lang_String::is_latin1(s);
3108       if (!is_latin1) {
3109         HeapAccess<>::arraycopy<jchar>(s_value, typeArrayOopDesc::element_offset<jchar>(start), NULL,
3110                                        NULL, 0, buf, len);
3111       } else {
3112         for (int i = 0; i < len; i++) {
3113           buf[i] = ((jchar) s_value->byte_at(i + start)) & 0xff;
3114         }
3115       }
3116     }
3117   }
3118 JNI_END
3119 
3120 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion
3121                          , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN());
3122 
3123 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf))
3124   JNIWrapper("GetStringUTFRegion");
3125  HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(env, string, start, len, buf);
3126   DT_VOID_RETURN_MARK(GetStringUTFRegion);
3127   oop s = JNIHandles::resolve_non_null(string);
3128   int s_len = java_lang_String::length(s);
3129   if (start < 0 || len < 0 || start > s_len - len) {
3130     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
3131   } else {
3132     //%note jni_7
3133     if (len > 0) {
3134       // Assume the buffer is large enough as the JNI spec. does not require user error checking
3135       java_lang_String::as_utf8_string(s, start, len, buf, INT_MAX);
3136       // as_utf8_string null-terminates the result string
3137     } else {
3138       // JDK null-terminates the buffer even in len is zero
3139       if (buf != NULL) {
3140         buf[0] = 0;
3141       }
3142     }
3143   }
3144 JNI_END
3145 
3146 static oop lock_gc_or_pin_object(JavaThread* thread, jobject obj) {
3147   if (Universe::heap()->supports_object_pinning()) {
3148     const oop o = JNIHandles::resolve_non_null(obj);
3149     return Universe::heap()->pin_object(thread, o);
3150   } else {
3151     GCLocker::lock_critical(thread);
3152     return JNIHandles::resolve_non_null(obj);
3153   }
3154 }
3155 
3156 static void unlock_gc_or_unpin_object(JavaThread* thread, jobject obj) {
3157   if (Universe::heap()->supports_object_pinning()) {
3158     const oop o = JNIHandles::resolve_non_null(obj);
3159     return Universe::heap()->unpin_object(thread, o);
3160   } else {
3161     GCLocker::unlock_critical(thread);
3162   }
3163 }
3164 
3165 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy))
3166   JNIWrapper("GetPrimitiveArrayCritical");
3167  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY(env, array, (uintptr_t *) isCopy);
3168   if (isCopy != NULL) {
3169     *isCopy = JNI_FALSE;
3170   }
3171   oop a = lock_gc_or_pin_object(thread, array);
3172   assert(a->is_array(), "just checking");
3173   BasicType type;
3174   if (a->is_objArray()) {
3175     type = T_OBJECT;
3176   } else {
3177     type = TypeArrayKlass::cast(a->klass())->element_type();
3178   }
3179   void* ret = arrayOop(a)->base(type);
3180  HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN(ret);
3181   return ret;
3182 JNI_END
3183 
3184 
3185 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode))
3186   JNIWrapper("ReleasePrimitiveArrayCritical");
3187   HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY(env, array, carray, mode);
3188   unlock_gc_or_unpin_object(thread, array);
3189 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN();
3190 JNI_END
3191 
3192 
3193 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy))
3194   JNIWrapper("GetStringCritical");
3195   HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY(env, string, (uintptr_t *) isCopy);
3196   oop s = lock_gc_or_pin_object(thread, string);
3197   typeArrayOop s_value = java_lang_String::value(s);
3198   bool is_latin1 = java_lang_String::is_latin1(s);
3199   if (isCopy != NULL) {
3200     *isCopy = is_latin1 ? JNI_TRUE : JNI_FALSE;
3201   }
3202   jchar* ret;
3203   if (!is_latin1) {
3204     ret = (jchar*) s_value->base(T_CHAR);
3205   } else {
3206     // Inflate latin1 encoded string to UTF16
3207     int s_len = java_lang_String::length(s);
3208     ret = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
3209     /* JNI Specification states return NULL on OOM */
3210     if (ret != NULL) {
3211       for (int i = 0; i < s_len; i++) {
3212         ret[i] = ((jchar) s_value->byte_at(i)) & 0xff;
3213       }
3214       ret[s_len] = 0;
3215     }
3216   }
3217  HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN((uint16_t *) ret);
3218   return ret;
3219 JNI_END
3220 
3221 
3222 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars))
3223   JNIWrapper("ReleaseStringCritical");
3224   HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY(env, str, (uint16_t *) chars);
3225   // The str and chars arguments are ignored for UTF16 strings
3226   oop s = JNIHandles::resolve_non_null(str);
3227   bool is_latin1 = java_lang_String::is_latin1(s);
3228   if (is_latin1) {
3229     // For latin1 string, free jchar array allocated by earlier call to GetStringCritical.
3230     // This assumes that ReleaseStringCritical bookends GetStringCritical.
3231     FREE_C_HEAP_ARRAY(jchar, chars);
3232   }
3233   unlock_gc_or_unpin_object(thread, str);
3234 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN();
3235 JNI_END
3236 
3237 
3238 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref))
3239   JNIWrapper("jni_NewWeakGlobalRef");
3240  HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY(env, ref);
3241   Handle ref_handle(thread, JNIHandles::resolve(ref));
3242   jweak ret = JNIHandles::make_weak_global(ref_handle);
3243  HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN(ret);
3244   return ret;
3245 JNI_END
3246 
3247 // Must be JNI_ENTRY (with HandleMark)
3248 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref))
3249   JNIWrapper("jni_DeleteWeakGlobalRef");
3250   HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY(env, ref);
3251   JNIHandles::destroy_weak_global(ref);
3252   HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN();
3253 JNI_END
3254 
3255 
3256 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env))
3257   JNIWrapper("jni_ExceptionCheck");
3258  HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY(env);
3259   jni_check_async_exceptions(thread);
3260   jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE;
3261  HOTSPOT_JNI_EXCEPTIONCHECK_RETURN(ret);
3262   return ret;
3263 JNI_END
3264 
3265 
3266 // Initialization state for three routines below relating to
3267 // java.nio.DirectBuffers
3268 static          int directBufferSupportInitializeStarted = 0;
3269 static volatile int directBufferSupportInitializeEnded   = 0;
3270 static volatile int directBufferSupportInitializeFailed  = 0;
3271 static jclass    bufferClass                 = NULL;
3272 static jclass    directBufferClass           = NULL;
3273 static jclass    directByteBufferClass       = NULL;
3274 static jmethodID directByteBufferConstructor = NULL;
3275 static jfieldID  directBufferAddressField    = NULL;
3276 static jfieldID  bufferCapacityField         = NULL;
3277 
3278 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) {
3279   Handle loader;            // null (bootstrap) loader
3280   Handle protection_domain; // null protection domain
3281 
3282   TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL);
3283   jclass result =  find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL);
3284 
3285   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
3286     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
3287   }
3288   return result;
3289 }
3290 
3291 // These lookups are done with the NULL (bootstrap) ClassLoader to
3292 // circumvent any security checks that would be done by jni_FindClass.
3293 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env))
3294 {
3295   if ((bufferClass           = lookupOne(env, "java/nio/Buffer", thread))           == NULL) { return false; }
3296   if ((directBufferClass     = lookupOne(env, "sun/nio/ch/DirectBuffer", thread))   == NULL) { return false; }
3297   if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; }
3298   return true;
3299 }
3300 JNI_END
3301 
3302 
3303 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
3304   if (directBufferSupportInitializeFailed) {
3305     return false;
3306   }
3307 
3308   if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) {
3309     if (!lookupDirectBufferClasses(env)) {
3310       directBufferSupportInitializeFailed = 1;
3311       return false;
3312     }
3313 
3314     // Make global references for these
3315     bufferClass           = (jclass) env->NewGlobalRef(bufferClass);
3316     directBufferClass     = (jclass) env->NewGlobalRef(directBufferClass);
3317     directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass);
3318 
3319     // Get needed field and method IDs
3320     directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V");
3321     if (env->ExceptionCheck()) {
3322       env->ExceptionClear();
3323       directBufferSupportInitializeFailed = 1;
3324       return false;
3325     }
3326     directBufferAddressField    = env->GetFieldID(bufferClass, "address", "J");
3327     if (env->ExceptionCheck()) {
3328       env->ExceptionClear();
3329       directBufferSupportInitializeFailed = 1;
3330       return false;
3331     }
3332     bufferCapacityField         = env->GetFieldID(bufferClass, "capacity", "I");
3333     if (env->ExceptionCheck()) {
3334       env->ExceptionClear();
3335       directBufferSupportInitializeFailed = 1;
3336       return false;
3337     }
3338 
3339     if ((directByteBufferConstructor == NULL) ||
3340         (directBufferAddressField    == NULL) ||
3341         (bufferCapacityField         == NULL)) {
3342       directBufferSupportInitializeFailed = 1;
3343       return false;
3344     }
3345 
3346     directBufferSupportInitializeEnded = 1;
3347   } else {
3348     while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
3349       os::naked_yield();
3350     }
3351   }
3352 
3353   return !directBufferSupportInitializeFailed;
3354 }
3355 
3356 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity)
3357 {
3358   // thread_from_jni_environment() will block if VM is gone.
3359   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3360 
3361   JNIWrapper("jni_NewDirectByteBuffer");
3362  HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY(env, address, capacity);
3363 
3364   if (!directBufferSupportInitializeEnded) {
3365     if (!initializeDirectBufferSupport(env, thread)) {
3366       HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(NULL);
3367       return NULL;
3368     }
3369   }
3370 
3371   // Being paranoid about accidental sign extension on address
3372   jlong addr = (jlong) ((uintptr_t) address);
3373   // NOTE that package-private DirectByteBuffer constructor currently
3374   // takes int capacity
3375   jint  cap  = (jint)  capacity;
3376   jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap);
3377   HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN(ret);
3378   return ret;
3379 }
3380 
3381 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*
3382                     , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref));
3383 
3384 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
3385 {
3386   // thread_from_jni_environment() will block if VM is gone.
3387   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3388 
3389   JNIWrapper("jni_GetDirectBufferAddress");
3390   HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY(env, buf);
3391   void* ret = NULL;
3392   DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret);
3393 
3394   if (!directBufferSupportInitializeEnded) {
3395     if (!initializeDirectBufferSupport(env, thread)) {
3396       return 0;
3397     }
3398   }
3399 
3400   if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) {
3401     return 0;
3402   }
3403 
3404   ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField);
3405   return ret;
3406 }
3407 
3408 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong
3409                     , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref));
3410 
3411 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf)
3412 {
3413   // thread_from_jni_environment() will block if VM is gone.
3414   JavaThread* thread = JavaThread::thread_from_jni_environment(env);
3415 
3416   JNIWrapper("jni_GetDirectBufferCapacity");
3417   HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY(env, buf);
3418   jlong ret = -1;
3419   DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret);
3420 
3421   if (!directBufferSupportInitializeEnded) {
3422     if (!initializeDirectBufferSupport(env, thread)) {
3423       ret = 0;
3424       return ret;
3425     }
3426   }
3427 
3428   if (buf == NULL) {
3429     return -1;
3430   }
3431 
3432   if (!env->IsInstanceOf(buf, directBufferClass)) {
3433     return -1;
3434   }
3435 
3436   // NOTE that capacity is currently an int in the implementation
3437   ret = env->GetIntField(buf, bufferCapacityField);
3438   return ret;
3439 }
3440 
3441 
3442 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env))
3443   JNIWrapper("GetVersion");
3444   HOTSPOT_JNI_GETVERSION_ENTRY(env);
3445   HOTSPOT_JNI_GETVERSION_RETURN(CurrentVersion);
3446   return CurrentVersion;
3447 JNI_END
3448 
3449 extern struct JavaVM_ main_vm;
3450 
3451 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm))
3452   JNIWrapper("jni_GetJavaVM");
3453   HOTSPOT_JNI_GETJAVAVM_ENTRY(env, (void **) vm);
3454   *vm  = (JavaVM *)(&main_vm);
3455   HOTSPOT_JNI_GETJAVAVM_RETURN(JNI_OK);
3456   return JNI_OK;
3457 JNI_END
3458 
3459 
3460 JNI_ENTRY(jobject, jni_GetModule(JNIEnv* env, jclass clazz))
3461   JNIWrapper("GetModule");
3462   return Modules::get_module(clazz, THREAD);
3463 JNI_END
3464 
3465 
3466 // Structure containing all jni functions
3467 struct JNINativeInterface_ jni_NativeInterface = {
3468     NULL,
3469     NULL,
3470     NULL,
3471 
3472     NULL,
3473 
3474     jni_GetVersion,
3475 
3476     jni_DefineClass,
3477     jni_FindClass,
3478 
3479     jni_FromReflectedMethod,
3480     jni_FromReflectedField,
3481 
3482     jni_ToReflectedMethod,
3483 
3484     jni_GetSuperclass,
3485     jni_IsAssignableFrom,
3486 
3487     jni_ToReflectedField,
3488 
3489     jni_Throw,
3490     jni_ThrowNew,
3491     jni_ExceptionOccurred,
3492     jni_ExceptionDescribe,
3493     jni_ExceptionClear,
3494     jni_FatalError,
3495 
3496     jni_PushLocalFrame,
3497     jni_PopLocalFrame,
3498 
3499     jni_NewGlobalRef,
3500     jni_DeleteGlobalRef,
3501     jni_DeleteLocalRef,
3502     jni_IsSameObject,
3503 
3504     jni_NewLocalRef,
3505     jni_EnsureLocalCapacity,
3506 
3507     jni_AllocObject,
3508     jni_NewObject,
3509     jni_NewObjectV,
3510     jni_NewObjectA,
3511 
3512     jni_GetObjectClass,
3513     jni_IsInstanceOf,
3514 
3515     jni_GetMethodID,
3516 
3517     jni_CallObjectMethod,
3518     jni_CallObjectMethodV,
3519     jni_CallObjectMethodA,
3520     jni_CallBooleanMethod,
3521     jni_CallBooleanMethodV,
3522     jni_CallBooleanMethodA,
3523     jni_CallByteMethod,
3524     jni_CallByteMethodV,
3525     jni_CallByteMethodA,
3526     jni_CallCharMethod,
3527     jni_CallCharMethodV,
3528     jni_CallCharMethodA,
3529     jni_CallShortMethod,
3530     jni_CallShortMethodV,
3531     jni_CallShortMethodA,
3532     jni_CallIntMethod,
3533     jni_CallIntMethodV,
3534     jni_CallIntMethodA,
3535     jni_CallLongMethod,
3536     jni_CallLongMethodV,
3537     jni_CallLongMethodA,
3538     jni_CallFloatMethod,
3539     jni_CallFloatMethodV,
3540     jni_CallFloatMethodA,
3541     jni_CallDoubleMethod,
3542     jni_CallDoubleMethodV,
3543     jni_CallDoubleMethodA,
3544     jni_CallVoidMethod,
3545     jni_CallVoidMethodV,
3546     jni_CallVoidMethodA,
3547 
3548     jni_CallNonvirtualObjectMethod,
3549     jni_CallNonvirtualObjectMethodV,
3550     jni_CallNonvirtualObjectMethodA,
3551     jni_CallNonvirtualBooleanMethod,
3552     jni_CallNonvirtualBooleanMethodV,
3553     jni_CallNonvirtualBooleanMethodA,
3554     jni_CallNonvirtualByteMethod,
3555     jni_CallNonvirtualByteMethodV,
3556     jni_CallNonvirtualByteMethodA,
3557     jni_CallNonvirtualCharMethod,
3558     jni_CallNonvirtualCharMethodV,
3559     jni_CallNonvirtualCharMethodA,
3560     jni_CallNonvirtualShortMethod,
3561     jni_CallNonvirtualShortMethodV,
3562     jni_CallNonvirtualShortMethodA,
3563     jni_CallNonvirtualIntMethod,
3564     jni_CallNonvirtualIntMethodV,
3565     jni_CallNonvirtualIntMethodA,
3566     jni_CallNonvirtualLongMethod,
3567     jni_CallNonvirtualLongMethodV,
3568     jni_CallNonvirtualLongMethodA,
3569     jni_CallNonvirtualFloatMethod,
3570     jni_CallNonvirtualFloatMethodV,
3571     jni_CallNonvirtualFloatMethodA,
3572     jni_CallNonvirtualDoubleMethod,
3573     jni_CallNonvirtualDoubleMethodV,
3574     jni_CallNonvirtualDoubleMethodA,
3575     jni_CallNonvirtualVoidMethod,
3576     jni_CallNonvirtualVoidMethodV,
3577     jni_CallNonvirtualVoidMethodA,
3578 
3579     jni_GetFieldID,
3580 
3581     jni_GetObjectField,
3582     jni_GetBooleanField,
3583     jni_GetByteField,
3584     jni_GetCharField,
3585     jni_GetShortField,
3586     jni_GetIntField,
3587     jni_GetLongField,
3588     jni_GetFloatField,
3589     jni_GetDoubleField,
3590 
3591     jni_SetObjectField,
3592     jni_SetBooleanField,
3593     jni_SetByteField,
3594     jni_SetCharField,
3595     jni_SetShortField,
3596     jni_SetIntField,
3597     jni_SetLongField,
3598     jni_SetFloatField,
3599     jni_SetDoubleField,
3600 
3601     jni_GetStaticMethodID,
3602 
3603     jni_CallStaticObjectMethod,
3604     jni_CallStaticObjectMethodV,
3605     jni_CallStaticObjectMethodA,
3606     jni_CallStaticBooleanMethod,
3607     jni_CallStaticBooleanMethodV,
3608     jni_CallStaticBooleanMethodA,
3609     jni_CallStaticByteMethod,
3610     jni_CallStaticByteMethodV,
3611     jni_CallStaticByteMethodA,
3612     jni_CallStaticCharMethod,
3613     jni_CallStaticCharMethodV,
3614     jni_CallStaticCharMethodA,
3615     jni_CallStaticShortMethod,
3616     jni_CallStaticShortMethodV,
3617     jni_CallStaticShortMethodA,
3618     jni_CallStaticIntMethod,
3619     jni_CallStaticIntMethodV,
3620     jni_CallStaticIntMethodA,
3621     jni_CallStaticLongMethod,
3622     jni_CallStaticLongMethodV,
3623     jni_CallStaticLongMethodA,
3624     jni_CallStaticFloatMethod,
3625     jni_CallStaticFloatMethodV,
3626     jni_CallStaticFloatMethodA,
3627     jni_CallStaticDoubleMethod,
3628     jni_CallStaticDoubleMethodV,
3629     jni_CallStaticDoubleMethodA,
3630     jni_CallStaticVoidMethod,
3631     jni_CallStaticVoidMethodV,
3632     jni_CallStaticVoidMethodA,
3633 
3634     jni_GetStaticFieldID,
3635 
3636     jni_GetStaticObjectField,
3637     jni_GetStaticBooleanField,
3638     jni_GetStaticByteField,
3639     jni_GetStaticCharField,
3640     jni_GetStaticShortField,
3641     jni_GetStaticIntField,
3642     jni_GetStaticLongField,
3643     jni_GetStaticFloatField,
3644     jni_GetStaticDoubleField,
3645 
3646     jni_SetStaticObjectField,
3647     jni_SetStaticBooleanField,
3648     jni_SetStaticByteField,
3649     jni_SetStaticCharField,
3650     jni_SetStaticShortField,
3651     jni_SetStaticIntField,
3652     jni_SetStaticLongField,
3653     jni_SetStaticFloatField,
3654     jni_SetStaticDoubleField,
3655 
3656     jni_NewString,
3657     jni_GetStringLength,
3658     jni_GetStringChars,
3659     jni_ReleaseStringChars,
3660 
3661     jni_NewStringUTF,
3662     jni_GetStringUTFLength,
3663     jni_GetStringUTFChars,
3664     jni_ReleaseStringUTFChars,
3665 
3666     jni_GetArrayLength,
3667 
3668     jni_NewObjectArray,
3669     jni_GetObjectArrayElement,
3670     jni_SetObjectArrayElement,
3671 
3672     jni_NewBooleanArray,
3673     jni_NewByteArray,
3674     jni_NewCharArray,
3675     jni_NewShortArray,
3676     jni_NewIntArray,
3677     jni_NewLongArray,
3678     jni_NewFloatArray,
3679     jni_NewDoubleArray,
3680 
3681     jni_GetBooleanArrayElements,
3682     jni_GetByteArrayElements,
3683     jni_GetCharArrayElements,
3684     jni_GetShortArrayElements,
3685     jni_GetIntArrayElements,
3686     jni_GetLongArrayElements,
3687     jni_GetFloatArrayElements,
3688     jni_GetDoubleArrayElements,
3689 
3690     jni_ReleaseBooleanArrayElements,
3691     jni_ReleaseByteArrayElements,
3692     jni_ReleaseCharArrayElements,
3693     jni_ReleaseShortArrayElements,
3694     jni_ReleaseIntArrayElements,
3695     jni_ReleaseLongArrayElements,
3696     jni_ReleaseFloatArrayElements,
3697     jni_ReleaseDoubleArrayElements,
3698 
3699     jni_GetBooleanArrayRegion,
3700     jni_GetByteArrayRegion,
3701     jni_GetCharArrayRegion,
3702     jni_GetShortArrayRegion,
3703     jni_GetIntArrayRegion,
3704     jni_GetLongArrayRegion,
3705     jni_GetFloatArrayRegion,
3706     jni_GetDoubleArrayRegion,
3707 
3708     jni_SetBooleanArrayRegion,
3709     jni_SetByteArrayRegion,
3710     jni_SetCharArrayRegion,
3711     jni_SetShortArrayRegion,
3712     jni_SetIntArrayRegion,
3713     jni_SetLongArrayRegion,
3714     jni_SetFloatArrayRegion,
3715     jni_SetDoubleArrayRegion,
3716 
3717     jni_RegisterNatives,
3718     jni_UnregisterNatives,
3719 
3720     jni_MonitorEnter,
3721     jni_MonitorExit,
3722 
3723     jni_GetJavaVM,
3724 
3725     jni_GetStringRegion,
3726     jni_GetStringUTFRegion,
3727 
3728     jni_GetPrimitiveArrayCritical,
3729     jni_ReleasePrimitiveArrayCritical,
3730 
3731     jni_GetStringCritical,
3732     jni_ReleaseStringCritical,
3733 
3734     jni_NewWeakGlobalRef,
3735     jni_DeleteWeakGlobalRef,
3736 
3737     jni_ExceptionCheck,
3738 
3739     jni_NewDirectByteBuffer,
3740     jni_GetDirectBufferAddress,
3741     jni_GetDirectBufferCapacity,
3742 
3743     // New 1_6 features
3744 
3745     jni_GetObjectRefType,
3746 
3747     // Module features
3748 
3749     jni_GetModule
3750 };
3751 
3752 
3753 // For jvmti use to modify jni function table.
3754 // Java threads in native contiues to run until it is transitioned
3755 // to VM at safepoint. Before the transition or before it is blocked
3756 // for safepoint it may access jni function table. VM could crash if
3757 // any java thread access the jni function table in the middle of memcpy.
3758 // To avoid this each function pointers are copied automically.
3759 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) {
3760   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
3761   intptr_t *a = (intptr_t *) jni_functions();
3762   intptr_t *b = (intptr_t *) new_jni_NativeInterface;
3763   for (uint i=0; i <  sizeof(struct JNINativeInterface_)/sizeof(void *); i++) {
3764     Atomic::store(*b++, a++);
3765   }
3766 }
3767 
3768 void quicken_jni_functions() {
3769   // Replace Get<Primitive>Field with fast versions
3770   if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access()
3771       && !VerifyJNIFields && !CountJNICalls && !CheckJNICalls
3772 #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2)
3773       // windows x86 currently needs SEH wrapper and the gain of the fast
3774       // versions currently isn't certain for server vm on uniprocessor.
3775       && os::is_MP()
3776 #endif
3777   ) {
3778     address func;
3779     func = JNI_FastGetField::generate_fast_get_boolean_field();
3780     if (func != (address)-1) {
3781       jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func;
3782     }
3783     func = JNI_FastGetField::generate_fast_get_byte_field();
3784     if (func != (address)-1) {
3785       jni_NativeInterface.GetByteField = (GetByteField_t)func;
3786     }
3787     func = JNI_FastGetField::generate_fast_get_char_field();
3788     if (func != (address)-1) {
3789       jni_NativeInterface.GetCharField = (GetCharField_t)func;
3790     }
3791     func = JNI_FastGetField::generate_fast_get_short_field();
3792     if (func != (address)-1) {
3793       jni_NativeInterface.GetShortField = (GetShortField_t)func;
3794     }
3795     func = JNI_FastGetField::generate_fast_get_int_field();
3796     if (func != (address)-1) {
3797       jni_NativeInterface.GetIntField = (GetIntField_t)func;
3798     }
3799     func = JNI_FastGetField::generate_fast_get_long_field();
3800     if (func != (address)-1) {
3801       jni_NativeInterface.GetLongField = (GetLongField_t)func;
3802     }
3803     func = JNI_FastGetField::generate_fast_get_float_field();
3804     if (func != (address)-1) {
3805       jni_NativeInterface.GetFloatField = (GetFloatField_t)func;
3806     }
3807     func = JNI_FastGetField::generate_fast_get_double_field();
3808     if (func != (address)-1) {
3809       jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func;
3810     }
3811   }
3812 }
3813 
3814 // Returns the function structure
3815 struct JNINativeInterface_* jni_functions() {
3816 #if INCLUDE_JNI_CHECK
3817   if (CheckJNICalls) return jni_functions_check();
3818 #endif // INCLUDE_JNI_CHECK
3819   return &jni_NativeInterface;
3820 }
3821 
3822 // Returns the function structure
3823 struct JNINativeInterface_* jni_functions_nocheck() {
3824   return &jni_NativeInterface;
3825 }
3826 
3827 
3828 // Invocation API
3829 
3830 
3831 // Forward declaration
3832 extern const struct JNIInvokeInterface_ jni_InvokeInterface;
3833 
3834 // Global invocation API vars
3835 volatile int vm_created = 0;
3836 // Indicate whether it is safe to recreate VM
3837 volatile int safe_to_recreate_vm = 1;
3838 struct JavaVM_ main_vm = {&jni_InvokeInterface};
3839 
3840 
3841 #define JAVASTACKSIZE (400 * 1024)    /* Default size of a thread java stack */
3842 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL };
3843 
3844 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint
3845                     , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref));
3846 
3847 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) {
3848   HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY(args_);
3849   JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_;
3850   jint ret = JNI_ERR;
3851   DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret);
3852 
3853   if (Threads::is_supported_jni_version(args->version)) {
3854     ret = JNI_OK;
3855   }
3856   // 1.1 style no longer supported in hotspot.
3857   // According the JNI spec, we should update args->version on return.
3858   // We also use the structure to communicate with launcher about default
3859   // stack size.
3860   if (args->version == JNI_VERSION_1_1) {
3861     args->version = JNI_VERSION_1_2;
3862     // javaStackSize is int in arguments structure
3863     assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow");
3864     args->javaStackSize = (jint)(ThreadStackSize * K);
3865   }
3866   return ret;
3867 }
3868 
3869 DT_RETURN_MARK_DECL(CreateJavaVM, jint
3870                     , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref));
3871 
3872 static jint JNI_CreateJavaVM_inner(JavaVM **vm, void **penv, void *args) {
3873   HOTSPOT_JNI_CREATEJAVAVM_ENTRY((void **) vm, penv, args);
3874 
3875   jint result = JNI_ERR;
3876   DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result);
3877 
3878   // We're about to use Atomic::xchg for synchronization.  Some Zero
3879   // platforms use the GCC builtin __sync_lock_test_and_set for this,
3880   // but __sync_lock_test_and_set is not guaranteed to do what we want
3881   // on all architectures.  So we check it works before relying on it.
3882 #if defined(ZERO) && defined(ASSERT)
3883   {
3884     jint a = 0xcafebabe;
3885     jint b = Atomic::xchg((jint) 0xdeadbeef, &a);
3886     void *c = &a;
3887     void *d = Atomic::xchg(&b, &c);
3888     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
3889     assert(c == &b && d == &a, "Atomic::xchg() works");
3890   }
3891 #endif // ZERO && ASSERT
3892 
3893   // At the moment it's only possible to have one Java VM,
3894   // since some of the runtime state is in global variables.
3895 
3896   // We cannot use our mutex locks here, since they only work on
3897   // Threads. We do an atomic compare and exchange to ensure only
3898   // one thread can call this method at a time
3899 
3900   // We use Atomic::xchg rather than Atomic::add/dec since on some platforms
3901   // the add/dec implementations are dependent on whether we are running
3902   // on a multiprocessor, and at this stage of initialization the os::is_MP
3903   // function used to determine this will always return false. Atomic::xchg
3904   // does not have this problem.
3905   if (Atomic::xchg(1, &vm_created) == 1) {
3906     return JNI_EEXIST;   // already created, or create attempt in progress
3907   }
3908   if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) {
3909     return JNI_ERR;  // someone tried and failed and retry not allowed.
3910   }
3911 
3912   assert(vm_created == 1, "vm_created is true during the creation");
3913 
3914   /**
3915    * Certain errors during initialization are recoverable and do not
3916    * prevent this method from being called again at a later time
3917    * (perhaps with different arguments).  However, at a certain
3918    * point during initialization if an error occurs we cannot allow
3919    * this function to be called again (or it will crash).  In those
3920    * situations, the 'canTryAgain' flag is set to false, which atomically
3921    * sets safe_to_recreate_vm to 1, such that any new call to
3922    * JNI_CreateJavaVM will immediately fail using the above logic.
3923    */
3924   bool can_try_again = true;
3925 
3926   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
3927   if (result == JNI_OK) {
3928     JavaThread *thread = JavaThread::current();
3929     assert(!thread->has_pending_exception(), "should have returned not OK");
3930     /* thread is thread_in_vm here */
3931     *vm = (JavaVM *)(&main_vm);
3932     *(JNIEnv**)penv = thread->jni_environment();
3933 
3934 #if INCLUDE_JVMCI
3935     if (EnableJVMCI) {
3936       if (UseJVMCICompiler) {
3937         // JVMCI is initialized on a CompilerThread
3938         if (BootstrapJVMCI) {
3939           JavaThread* THREAD = thread;
3940           JVMCICompiler* compiler = JVMCICompiler::instance(true, CATCH);
3941           compiler->bootstrap(THREAD);
3942           if (HAS_PENDING_EXCEPTION) {
3943             HandleMark hm;
3944             vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3945           }
3946         }
3947       }
3948     }
3949 #endif
3950 
3951     // Tracks the time application was running before GC
3952     RuntimeService::record_application_start();
3953 
3954     // Notify JVMTI
3955     if (JvmtiExport::should_post_thread_life()) {
3956        JvmtiExport::post_thread_start(thread);
3957     }
3958 
3959     EventThreadStart event;
3960     if (event.should_commit()) {
3961       event.set_thread(THREAD_TRACE_ID(thread));
3962       event.commit();
3963     }
3964 
3965 #ifndef PRODUCT
3966     // Check if we should compile all classes on bootclasspath
3967     if (CompileTheWorld) ClassLoader::compile_the_world();
3968     if (ReplayCompiles) ciReplay::replay(thread);
3969 
3970     // Some platforms (like Win*) need a wrapper around these test
3971     // functions in order to properly handle error conditions.
3972     VMError::test_error_handler();
3973     if (ExecuteInternalVMTests) {
3974       InternalVMTests::run();
3975     }
3976 #endif
3977 
3978     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
3979     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
3980   } else {
3981     // If create_vm exits because of a pending exception, exit with that
3982     // exception.  In the future when we figure out how to reclaim memory,
3983     // we may be able to exit with JNI_ERR and allow the calling application
3984     // to continue.
3985     if (Universe::is_fully_initialized()) {
3986       // otherwise no pending exception possible - VM will already have aborted
3987       JavaThread* THREAD = JavaThread::current();
3988       if (HAS_PENDING_EXCEPTION) {
3989         HandleMark hm;
3990         vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3991       }
3992     }
3993 
3994     if (can_try_again) {
3995       // reset safe_to_recreate_vm to 1 so that retrial would be possible
3996       safe_to_recreate_vm = 1;
3997     }
3998 
3999     // Creation failed. We must reset vm_created
4000     *vm = 0;
4001     *(JNIEnv**)penv = 0;
4002     // reset vm_created last to avoid race condition. Use OrderAccess to
4003     // control both compiler and architectural-based reordering.
4004     OrderAccess::release_store(&vm_created, 0);
4005   }
4006 
4007   // Flush stdout and stderr before exit.
4008   fflush(stdout);
4009   fflush(stderr);
4010 
4011   return result;
4012 
4013 }
4014 
4015 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
4016   jint result = JNI_ERR;
4017   // On Windows, let CreateJavaVM run with SEH protection
4018 #ifdef _WIN32
4019   __try {
4020 #endif
4021     result = JNI_CreateJavaVM_inner(vm, penv, args);
4022 #ifdef _WIN32
4023   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
4024     // Nothing to do.
4025   }
4026 #endif
4027   return result;
4028 }
4029 
4030 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) {
4031   // See bug 4367188, the wrapper can sometimes cause VM crashes
4032   // JNIWrapper("GetCreatedJavaVMs");
4033 
4034   HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY((void **) vm_buf, bufLen, (uintptr_t *) numVMs);
4035 
4036   if (vm_created == 1) {
4037     if (numVMs != NULL) *numVMs = 1;
4038     if (bufLen > 0)     *vm_buf = (JavaVM *)(&main_vm);
4039   } else {
4040     if (numVMs != NULL) *numVMs = 0;
4041   }
4042   HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN(JNI_OK);
4043   return JNI_OK;
4044 }
4045 
4046 extern "C" {
4047 
4048 DT_RETURN_MARK_DECL(DestroyJavaVM, jint
4049                     , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref));
4050 
4051 static jint JNICALL jni_DestroyJavaVM_inner(JavaVM *vm) {
4052   HOTSPOT_JNI_DESTROYJAVAVM_ENTRY(vm);
4053   jint res = JNI_ERR;
4054   DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res);
4055 
4056   if (vm_created == 0) {
4057     res = JNI_ERR;
4058     return res;
4059   }
4060 
4061   JNIWrapper("DestroyJavaVM");
4062   JNIEnv *env;
4063   JavaVMAttachArgs destroyargs;
4064   destroyargs.version = CurrentVersion;
4065   destroyargs.name = (char *)"DestroyJavaVM";
4066   destroyargs.group = NULL;
4067   res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs);
4068   if (res != JNI_OK) {
4069     return res;
4070   }
4071 
4072   // Since this is not a JVM_ENTRY we have to set the thread state manually before entering.
4073   JavaThread* thread = JavaThread::current();
4074   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4075   if (Threads::destroy_vm()) {
4076     // Should not change thread state, VM is gone
4077     vm_created = 0;
4078     res = JNI_OK;
4079     return res;
4080   } else {
4081     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
4082     res = JNI_ERR;
4083     return res;
4084   }
4085 }
4086 
4087 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
4088   jint result = JNI_ERR;
4089   // On Windows, we need SEH protection
4090 #ifdef _WIN32
4091   __try {
4092 #endif
4093     result = jni_DestroyJavaVM_inner(vm);
4094 #ifdef _WIN32
4095   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
4096     // Nothing to do.
4097   }
4098 #endif
4099   return result;
4100 }
4101 
4102 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) {
4103   JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args;
4104 
4105   // Check below commented out from JDK1.2fcs as well
4106   /*
4107   if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) {
4108     return JNI_EVERSION;
4109   }
4110   */
4111 
4112   Thread* t = Thread::current_or_null();
4113   if (t != NULL) {
4114     // If the thread has been attached this operation is a no-op
4115     *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
4116     return JNI_OK;
4117   }
4118 
4119   // Create a thread and mark it as attaching so it will be skipped by the
4120   // ThreadsListEnumerator - see CR 6404306
4121   JavaThread* thread = new JavaThread(true);
4122 
4123   // Set correct safepoint info. The thread is going to call into Java when
4124   // initializing the Java level thread object. Hence, the correct state must
4125   // be set in order for the Safepoint code to deal with it correctly.
4126   thread->set_thread_state(_thread_in_vm);
4127   thread->record_stack_base_and_size();
4128   thread->initialize_thread_current();
4129 
4130   if (!os::create_attached_thread(thread)) {
4131     thread->smr_delete();
4132     return JNI_ERR;
4133   }
4134   // Enable stack overflow checks
4135   thread->create_stack_guard_pages();
4136 
4137   thread->initialize_tlab();
4138 
4139   thread->cache_global_variables();
4140 
4141   // Crucial that we do not have a safepoint check for this thread, since it has
4142   // not been added to the Thread list yet.
4143   { Threads_lock->lock_without_safepoint_check();
4144     // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
4145     // avoid this thread trying to do a GC before it is added to the thread-list
4146     thread->set_active_handles(JNIHandleBlock::allocate_block());
4147     Threads::add(thread, daemon);
4148     Threads_lock->unlock();
4149   }
4150   // Create thread group and name info from attach arguments
4151   oop group = NULL;
4152   char* thread_name = NULL;
4153   if (args != NULL && Threads::is_supported_jni_version(args->version)) {
4154     group = JNIHandles::resolve(args->group);
4155     thread_name = args->name; // may be NULL
4156   }
4157   if (group == NULL) group = Universe::main_thread_group();
4158 
4159   // Create Java level thread object and attach it to this thread
4160   bool attach_failed = false;
4161   {
4162     EXCEPTION_MARK;
4163     HandleMark hm(THREAD);
4164     Handle thread_group(THREAD, group);
4165     thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD);
4166     if (HAS_PENDING_EXCEPTION) {
4167       CLEAR_PENDING_EXCEPTION;
4168       // cleanup outside the handle mark.
4169       attach_failed = true;
4170     }
4171   }
4172 
4173   if (attach_failed) {
4174     // Added missing cleanup
4175     thread->cleanup_failed_attach_current_thread();
4176     return JNI_ERR;
4177   }
4178 
4179   // mark the thread as no longer attaching
4180   // this uses a fence to push the change through so we don't have
4181   // to regrab the threads_lock
4182   thread->set_done_attaching_via_jni();
4183 
4184   // Set java thread status.
4185   java_lang_Thread::set_thread_status(thread->threadObj(),
4186               java_lang_Thread::RUNNABLE);
4187 
4188   // Notify the debugger
4189   if (JvmtiExport::should_post_thread_life()) {
4190     JvmtiExport::post_thread_start(thread);
4191   }
4192 
4193   EventThreadStart event;
4194   if (event.should_commit()) {
4195     event.set_thread(THREAD_TRACE_ID(thread));
4196     event.commit();
4197   }
4198 
4199   *(JNIEnv**)penv = thread->jni_environment();
4200 
4201   // Now leaving the VM, so change thread_state. This is normally automatically taken care
4202   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
4203   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
4204   // needed.
4205 
4206   ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
4207 
4208   // Perform any platform dependent FPU setup
4209   os::setup_fpu();
4210 
4211   return JNI_OK;
4212 }
4213 
4214 
4215 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
4216   HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(vm, penv, _args);
4217   if (vm_created == 0) {
4218   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4219     return JNI_ERR;
4220   }
4221 
4222   JNIWrapper("AttachCurrentThread");
4223   jint ret = attach_current_thread(vm, penv, _args, false);
4224   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(ret);
4225   return ret;
4226 }
4227 
4228 
4229 jint JNICALL jni_DetachCurrentThread(JavaVM *vm)  {
4230   HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(vm);
4231 
4232   JNIWrapper("DetachCurrentThread");
4233 
4234   // If the thread has already been detached the operation is a no-op
4235   if (Thread::current_or_null() == NULL) {
4236     HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
4237     return JNI_OK;
4238   }
4239 
4240   VM_Exit::block_if_vm_exited();
4241 
4242   JavaThread* thread = JavaThread::current();
4243   if (thread->has_last_Java_frame()) {
4244     HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4245     // Can't detach a thread that's running java, that can't work.
4246     return JNI_ERR;
4247   }
4248 
4249   // Safepoint support. Have to do call-back to safepoint code, if in the
4250   // middle of a safepoint operation
4251   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4252 
4253   // XXX: Note that JavaThread::exit() call below removes the guards on the
4254   // stack pages set up via enable_stack_{red,yellow}_zone() calls
4255   // above in jni_AttachCurrentThread. Unfortunately, while the setting
4256   // of the guards is visible in jni_AttachCurrentThread above,
4257   // the removal of the guards is buried below in JavaThread::exit()
4258   // here. The abstraction should be more symmetrically either exposed
4259   // or hidden (e.g. it could probably be hidden in the same
4260   // (platform-dependent) methods where we do alternate stack
4261   // maintenance work?)
4262   thread->exit(false, JavaThread::jni_detach);
4263   thread->smr_delete();
4264 
4265   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
4266   return JNI_OK;
4267 }
4268 
4269 DT_RETURN_MARK_DECL(GetEnv, jint
4270                     , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
4271 
4272 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
4273   HOTSPOT_JNI_GETENV_ENTRY(vm, penv, version);
4274   jint ret = JNI_ERR;
4275   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
4276 
4277   if (vm_created == 0) {
4278     *penv = NULL;
4279     ret = JNI_EDETACHED;
4280     return ret;
4281   }
4282 
4283   if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {
4284     return ret;
4285   }
4286 
4287 #ifndef JVMPI_VERSION_1
4288 // need these in order to be polite about older agents
4289 #define JVMPI_VERSION_1   ((jint)0x10000001)
4290 #define JVMPI_VERSION_1_1 ((jint)0x10000002)
4291 #define JVMPI_VERSION_1_2 ((jint)0x10000003)
4292 #endif // !JVMPI_VERSION_1
4293 
4294   Thread* thread = Thread::current_or_null();
4295   if (thread != NULL && thread->is_Java_thread()) {
4296     if (Threads::is_supported_jni_version_including_1_1(version)) {
4297       *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment();
4298       ret = JNI_OK;
4299       return ret;
4300 
4301     } else if (version == JVMPI_VERSION_1 ||
4302                version == JVMPI_VERSION_1_1 ||
4303                version == JVMPI_VERSION_1_2) {
4304       tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported.");
4305       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
4306       ret = JNI_EVERSION;
4307       return ret;
4308     } else if (JvmtiExport::is_jvmdi_version(version)) {
4309       tty->print_cr("FATAL ERROR: JVMDI is no longer supported.");
4310       tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI).");
4311       ret = JNI_EVERSION;
4312       return ret;
4313     } else {
4314       *penv = NULL;
4315       ret = JNI_EVERSION;
4316       return ret;
4317     }
4318   } else {
4319     *penv = NULL;
4320     ret = JNI_EDETACHED;
4321     return ret;
4322   }
4323 }
4324 
4325 
4326 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) {
4327   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY(vm, penv, _args);
4328   if (vm_created == 0) {
4329   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN((uint32_t) JNI_ERR);
4330     return JNI_ERR;
4331   }
4332 
4333   JNIWrapper("AttachCurrentThreadAsDaemon");
4334   jint ret = attach_current_thread(vm, penv, _args, true);
4335   HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN(ret);
4336   return ret;
4337 }
4338 
4339 
4340 } // End extern "C"
4341 
4342 const struct JNIInvokeInterface_ jni_InvokeInterface = {
4343     NULL,
4344     NULL,
4345     NULL,
4346 
4347     jni_DestroyJavaVM,
4348     jni_AttachCurrentThread,
4349     jni_DetachCurrentThread,
4350     jni_GetEnv,
4351     jni_AttachCurrentThreadAsDaemon
4352 };
--- EOF ---