1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "memory/guardedMemory.hpp"
  29 #include "oops/instanceKlass.hpp"
  30 #include "oops/oop.inline.hpp"
  31 #include "oops/symbol.hpp"
  32 #include "prims/jni.h"
  33 #include "prims/jniCheck.hpp"
  34 #include "prims/jvm_misc.hpp"
  35 #include "runtime/fieldDescriptor.hpp"
  36 #include "runtime/handles.hpp"
  37 #include "runtime/interfaceSupport.hpp"
  38 #include "runtime/jfieldIDWorkaround.hpp"
  39 #include "runtime/thread.inline.hpp"
  40 #ifdef TARGET_ARCH_x86
  41 # include "jniTypes_x86.hpp"
  42 #endif
  43 #ifdef TARGET_ARCH_sparc
  44 # include "jniTypes_sparc.hpp"
  45 #endif
  46 #ifdef TARGET_ARCH_zero
  47 # include "jniTypes_zero.hpp"
  48 #endif
  49 #ifdef TARGET_ARCH_arm
  50 # include "jniTypes_arm.hpp"
  51 #endif
  52 #ifdef TARGET_ARCH_ppc
  53 # include "jniTypes_ppc.hpp"
  54 #endif
  55 #ifdef TARGET_ARCH_aarch32
  56 # include "jniTypes_aarch32.hpp"
  57 #endif
  58 
  59 // Complain every extra number of unplanned local refs
  60 #define CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD 32
  61 
  62 // Heap objects are allowed to be directly referenced only in VM code,
  63 // not in native code.
  64 
  65 #define ASSERT_OOPS_ALLOWED                                          \
  66     assert(JavaThread::current()->thread_state() == _thread_in_vm,   \
  67            "jniCheck examining oops in bad state.")
  68 
  69 
  70 // Execute the given block of source code with the thread in VM state.
  71 // To do this, transition from the NATIVE state to the VM state, execute
  72 // the code, and transtition back.  The ThreadInVMfromNative constructor
  73 // performs the transition to VM state, its destructor restores the
  74 // NATIVE state.
  75 
  76 #define IN_VM(source_code)   {                                         \
  77     {                                                                  \
  78       ThreadInVMfromNative __tiv(thr);                                 \
  79       source_code                                                      \
  80     }                                                                  \
  81   }
  82 
  83 
  84 /*
  85  * DECLARATIONS
  86  */
  87 
  88 static struct JNINativeInterface_ * unchecked_jni_NativeInterface;
  89 
  90 
  91 /*
  92  * MACRO DEFINITIONS
  93  */
  94 
  95 // All JNI checked functions here use JNI_ENTRY_CHECKED() instead of the
  96 // QUICK_ENTRY or LEAF variants found in jni.cpp.  This allows handles
  97 // to be created if a fatal error should occur.
  98 
  99 // Check for thread not attached to VM;  need to catch this before
 100 // assertions in the wrapper routines might fire
 101 
 102 // Check for env being the one value appropriate for this thread.
 103 
 104 #define JNI_ENTRY_CHECKED(result_type, header)                           \
 105 extern "C" {                                                             \
 106   result_type JNICALL header {                                           \
 107     JavaThread* thr = (JavaThread*)ThreadLocalStorage::get_thread_slow();\
 108     if (thr == NULL || !thr->is_Java_thread()) {                         \
 109       tty->print_cr("%s", fatal_using_jnienv_in_nonjava);                      \
 110       os::abort(true);                                                   \
 111     }                                                                    \
 112     JNIEnv* xenv = thr->jni_environment();                               \
 113     if (env != xenv) {                                                   \
 114       NativeReportJNIFatalError(thr, warn_wrong_jnienv);                 \
 115     }                                                                    \
 116     VM_ENTRY_BASE(result_type, header, thr)
 117 
 118 
 119 #define UNCHECKED() (unchecked_jni_NativeInterface)
 120 
 121 static const char * warn_wrong_jnienv = "Using JNIEnv in the wrong thread";
 122 static const char * warn_bad_class_descriptor = "JNI FindClass received a bad class descriptor \"%s\".  A correct class descriptor " \
 123   "has no leading \"L\" or trailing \";\".  Incorrect descriptors will not be accepted in future releases.";
 124 static const char * fatal_using_jnienv_in_nonjava = "FATAL ERROR in native method: Using JNIEnv in non-Java thread";
 125 static const char * warn_other_function_in_critical = "Warning: Calling other JNI functions in the scope of " \
 126   "Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical";
 127 static const char * fatal_bad_ref_to_jni = "Bad global or local ref passed to JNI";
 128 static const char * fatal_received_null_class = "JNI received a null class";
 129 static const char * fatal_class_not_a_class = "JNI received a class argument that is not a class";
 130 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass";
 131 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call";
 132 static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call";
 133 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations";
 134 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation";
 135 static const char * fatal_prim_type_array_expected = "Primitive type array expected but not received for JNI array operation";
 136 static const char * fatal_non_array  = "Non-array passed to JNI array operations";
 137 static const char * fatal_element_type_mismatch = "Array element type mismatch in JNI";
 138 static const char * fatal_should_be_static = "Non-static field ID passed to JNI";
 139 static const char * fatal_wrong_static_field = "Wrong static field ID passed to JNI";
 140 static const char * fatal_static_field_not_found = "Static field not found in JNI get/set field operations";
 141 static const char * fatal_static_field_mismatch = "Field type (static) mismatch in JNI get/set field operations";
 142 static const char * fatal_should_be_nonstatic = "Static field ID passed to JNI";
 143 static const char * fatal_null_object = "Null object passed to JNI";
 144 static const char * fatal_wrong_field = "Wrong field ID passed to JNI";
 145 static const char * fatal_instance_field_not_found = "Instance field not found in JNI get/set field operations";
 146 static const char * fatal_instance_field_mismatch = "Field type (instance) mismatch in JNI get/set field operations";
 147 static const char * fatal_non_string = "JNI string operation received a non-string";
 148 
 149 
 150 // When in VM state:
 151 static void ReportJNIWarning(JavaThread* thr, const char *msg) {
 152   tty->print_cr("WARNING in native method: %s", msg);
 153   thr->print_stack();
 154 }
 155 
 156 // When in NATIVE state:
 157 static void NativeReportJNIFatalError(JavaThread* thr, const char *msg) {
 158   IN_VM(
 159     ReportJNIFatalError(thr, msg);
 160   )
 161 }
 162 
 163 static void NativeReportJNIWarning(JavaThread* thr, const char *msg) {
 164   IN_VM(
 165     ReportJNIWarning(thr, msg);
 166   )
 167 }
 168 
 169 
 170 
 171 
 172 /*
 173  * SUPPORT FUNCTIONS
 174  */
 175 
 176 /**
 177  * Check whether or not a programmer has actually checked for exceptions. According
 178  * to the JNI Specification ("jni/spec/design.html#java_exceptions"):
 179  *
 180  * There are two cases where the programmer needs to check for exceptions without
 181  * being able to first check an error code:
 182  *
 183  * - The JNI functions that invoke a Java method return the result of the Java method.
 184  * The programmer must call ExceptionOccurred() to check for possible exceptions
 185  * that occurred during the execution of the Java method.
 186  *
 187  * - Some of the JNI array access functions do not return an error code, but may
 188  * throw an ArrayIndexOutOfBoundsException or ArrayStoreException.
 189  *
 190  * In all other cases, a non-error return value guarantees that no exceptions have been thrown.
 191  *
 192  * Programmers often defend against ArrayIndexOutOfBoundsException, so warning
 193  * for these functions would be pedantic.
 194  */
 195 static inline void
 196 check_pending_exception(JavaThread* thr) {
 197   if (thr->has_pending_exception()) {
 198     NativeReportJNIWarning(thr, "JNI call made with exception pending");
 199   }
 200   if (thr->is_pending_jni_exception_check()) {
 201     IN_VM(
 202       tty->print_cr("WARNING in native method: JNI call made without checking exceptions when required to from %s",
 203         thr->get_pending_jni_exception_check());
 204       thr->print_stack();
 205     )
 206     thr->clear_pending_jni_exception_check(); // Just complain once
 207   }
 208 }
 209 
 210 /**
 211  * Add to the planned number of handles. I.e. plus current live & warning threshold
 212  */
 213 static inline void
 214 add_planned_handle_capacity(JNIHandleBlock* handles, size_t capacity) {
 215   handles->set_planned_capacity(capacity +
 216                                 handles->get_number_of_live_handles() +
 217                                 CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
 218 }
 219 
 220 
 221 static inline void
 222 functionEnterCritical(JavaThread* thr)
 223 {
 224   check_pending_exception(thr);
 225 }
 226 
 227 static inline void
 228 functionEnterCriticalExceptionAllowed(JavaThread* thr)
 229 {
 230 }
 231 
 232 static inline void
 233 functionEnter(JavaThread* thr)
 234 {
 235   if (thr->in_critical()) {
 236     tty->print_cr("%s", warn_other_function_in_critical);
 237   }
 238   check_pending_exception(thr);
 239 }
 240 
 241 static inline void
 242 functionEnterExceptionAllowed(JavaThread* thr)
 243 {
 244   if (thr->in_critical()) {
 245     tty->print_cr("%s", warn_other_function_in_critical);
 246   }
 247 }
 248 
 249 static inline void
 250 functionExit(JavaThread* thr)
 251 {
 252   JNIHandleBlock* handles = thr->active_handles();
 253   size_t planned_capacity = handles->get_planned_capacity();
 254   size_t live_handles = handles->get_number_of_live_handles();
 255   if (live_handles > planned_capacity) {
 256     IN_VM(
 257       tty->print_cr("WARNING: JNI local refs: %zu, exceeds capacity: %zu",
 258           live_handles, planned_capacity);
 259       thr->print_stack();
 260     )
 261     // Complain just the once, reset to current + warn threshold
 262     add_planned_handle_capacity(handles, 0);
 263   }
 264 }
 265 
 266 static inline void
 267 checkStaticFieldID(JavaThread* thr, jfieldID fid, jclass cls, int ftype)
 268 {
 269   fieldDescriptor fd;
 270 
 271   /* make sure it is a static field */
 272   if (!jfieldIDWorkaround::is_static_jfieldID(fid))
 273     ReportJNIFatalError(thr, fatal_should_be_static);
 274 
 275   /* validate the class being passed */
 276   ASSERT_OOPS_ALLOWED;
 277   Klass* k_oop = jniCheck::validate_class(thr, cls, false);
 278 
 279   /* check for proper subclass hierarchy */
 280   JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fid);
 281   Klass* f_oop = id->holder();
 282   if (!InstanceKlass::cast(k_oop)->is_subtype_of(f_oop))
 283     ReportJNIFatalError(thr, fatal_wrong_static_field);
 284 
 285   /* check for proper field type */
 286   if (!id->find_local_field(&fd))
 287     ReportJNIFatalError(thr, fatal_static_field_not_found);
 288   if ((fd.field_type() != ftype) &&
 289       !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
 290     ReportJNIFatalError(thr, fatal_static_field_mismatch);
 291   }
 292 }
 293 
 294 static inline void
 295 checkInstanceFieldID(JavaThread* thr, jfieldID fid, jobject obj, int ftype)
 296 {
 297   fieldDescriptor fd;
 298 
 299   /* make sure it is an instance field */
 300   if (jfieldIDWorkaround::is_static_jfieldID(fid))
 301     ReportJNIFatalError(thr, fatal_should_be_nonstatic);
 302 
 303   /* validate the object being passed and then get its class */
 304   ASSERT_OOPS_ALLOWED;
 305   oop oopObj = jniCheck::validate_object(thr, obj);
 306   if (!oopObj) {
 307     ReportJNIFatalError(thr, fatal_null_object);
 308   }
 309   Klass* k_oop = oopObj->klass();
 310 
 311   if (!jfieldIDWorkaround::is_valid_jfieldID(k_oop, fid)) {
 312     ReportJNIFatalError(thr, fatal_wrong_field);
 313   }
 314 
 315   /* make sure the field exists */
 316   int offset = jfieldIDWorkaround::from_instance_jfieldID(k_oop, fid);
 317   if (!InstanceKlass::cast(k_oop)->contains_field_offset(offset))
 318     ReportJNIFatalError(thr, fatal_wrong_field);
 319 
 320   /* check for proper field type */
 321   if (!InstanceKlass::cast(k_oop)->find_field_from_offset(offset,
 322                                                               false, &fd))
 323     ReportJNIFatalError(thr, fatal_instance_field_not_found);
 324 
 325   if ((fd.field_type() != ftype) &&
 326       !(fd.field_type() == T_ARRAY && ftype == T_OBJECT)) {
 327     ReportJNIFatalError(thr, fatal_instance_field_mismatch);
 328   }
 329 }
 330 
 331 static inline void
 332 checkString(JavaThread* thr, jstring js)
 333 {
 334   ASSERT_OOPS_ALLOWED;
 335   oop s = jniCheck::validate_object(thr, js);
 336   if (!s || !java_lang_String::is_instance(s))
 337     ReportJNIFatalError(thr, fatal_non_string);
 338 }
 339 
 340 static inline arrayOop
 341 check_is_array(JavaThread* thr, jarray jArray)
 342 {
 343   ASSERT_OOPS_ALLOWED;
 344   arrayOop aOop;
 345 
 346   aOop = (arrayOop)jniCheck::validate_object(thr, jArray);
 347   if (aOop == NULL || !aOop->is_array()) {
 348     ReportJNIFatalError(thr, fatal_non_array);
 349   }
 350   return aOop;
 351 }
 352 
 353 static inline arrayOop
 354 check_is_primitive_array(JavaThread* thr, jarray jArray) {
 355   arrayOop aOop = check_is_array(thr, jArray);
 356 
 357   if (!aOop->is_typeArray()) {
 358      ReportJNIFatalError(thr, fatal_prim_type_array_expected);
 359   }
 360   return aOop;
 361 }
 362 
 363 static inline void
 364 check_primitive_array_type(JavaThread* thr, jarray jArray, BasicType elementType)
 365 {
 366   BasicType array_type;
 367   arrayOop aOop;
 368 
 369   aOop = check_is_primitive_array(thr, jArray);
 370   array_type = TypeArrayKlass::cast(aOop->klass())->element_type();
 371   if (array_type != elementType) {
 372     ReportJNIFatalError(thr, fatal_element_type_mismatch);
 373   }
 374 }
 375 
 376 static inline void
 377 check_is_obj_array(JavaThread* thr, jarray jArray) {
 378   arrayOop aOop = check_is_array(thr, jArray);
 379   if (!aOop->is_objArray()) {
 380     ReportJNIFatalError(thr, fatal_object_array_expected);
 381   }
 382 }
 383 
 384 /*
 385  * Copy and wrap array elements for bounds checking.
 386  * Remember the original elements (GuardedMemory::get_tag())
 387  */
 388 static void* check_jni_wrap_copy_array(JavaThread* thr, jarray array,
 389     void* orig_elements) {
 390   void* result;
 391   IN_VM(
 392     oop a = JNIHandles::resolve_non_null(array);
 393     size_t len = arrayOop(a)->length() <<
 394         TypeArrayKlass::cast(a->klass())->log2_element_size();
 395     result = GuardedMemory::wrap_copy(orig_elements, len, orig_elements);
 396   )
 397   return result;
 398 }
 399 
 400 static void* check_wrapped_array(JavaThread* thr, const char* fn_name,
 401     void* obj, void* carray, size_t* rsz) {
 402   if (carray == NULL) {
 403     tty->print_cr("%s: elements vector NULL" PTR_FORMAT, fn_name, p2i(obj));
 404     NativeReportJNIFatalError(thr, "Elements vector NULL");
 405   }
 406   GuardedMemory guarded(carray);
 407   void* orig_result = guarded.get_tag();
 408   if (!guarded.verify_guards()) {
 409     tty->print_cr("ReleasePrimitiveArrayCritical: release array failed bounds "
 410         "check, incorrect pointer returned ? array: " PTR_FORMAT " carray: "
 411         PTR_FORMAT, p2i(obj), p2i(carray));
 412     guarded.print_on(tty);
 413     NativeReportJNIFatalError(thr, "ReleasePrimitiveArrayCritical: "
 414         "failed bounds check");
 415   }
 416   if (orig_result == NULL) {
 417     tty->print_cr("ReleasePrimitiveArrayCritical: unrecognized elements. array: "
 418         PTR_FORMAT " carray: " PTR_FORMAT, p2i(obj), p2i(carray));
 419     guarded.print_on(tty);
 420     NativeReportJNIFatalError(thr, "ReleasePrimitiveArrayCritical: "
 421         "unrecognized elements");
 422   }
 423   if (rsz != NULL) {
 424     *rsz = guarded.get_user_size();
 425   }
 426   return orig_result;
 427 }
 428 
 429 static void* check_wrapped_array_release(JavaThread* thr, const char* fn_name,
 430     void* obj, void* carray, jint mode) {
 431   size_t sz;
 432   void* orig_result = check_wrapped_array(thr, fn_name, obj, carray, &sz);
 433   switch (mode) {
 434   case 0:
 435     memcpy(orig_result, carray, sz);
 436     GuardedMemory::free_copy(carray);
 437     break;
 438   case JNI_COMMIT:
 439     memcpy(orig_result, carray, sz);
 440     break;
 441   case JNI_ABORT:
 442     GuardedMemory::free_copy(carray);
 443     break;
 444   default:
 445     tty->print_cr("%s: Unrecognized mode %i releasing array "
 446         PTR_FORMAT " elements " PTR_FORMAT, fn_name, mode, p2i(obj), p2i(carray));
 447     NativeReportJNIFatalError(thr, "Unrecognized array release mode");
 448   }
 449   return orig_result;
 450 }
 451 
 452 oop jniCheck::validate_handle(JavaThread* thr, jobject obj) {
 453   if (JNIHandles::is_frame_handle(thr, obj) ||
 454       JNIHandles::is_local_handle(thr, obj) ||
 455       JNIHandles::is_global_handle(obj) ||
 456       JNIHandles::is_weak_global_handle(obj)) {
 457     ASSERT_OOPS_ALLOWED;
 458     return JNIHandles::resolve_external_guard(obj);
 459   }
 460   ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
 461   return NULL;
 462 }
 463 
 464 
 465 Method* jniCheck::validate_jmethod_id(JavaThread* thr, jmethodID method_id) {
 466   ASSERT_OOPS_ALLOWED;
 467   // Do the jmethodID check
 468   Method* moop = Method::checked_resolve_jmethod_id(method_id);
 469   if (moop == NULL) {
 470     ReportJNIFatalError(thr, fatal_wrong_class_or_method);
 471   }
 472   return moop;
 473 }
 474 
 475 
 476 oop jniCheck::validate_object(JavaThread* thr, jobject obj) {
 477     if (!obj)
 478         return NULL;
 479     ASSERT_OOPS_ALLOWED;
 480     oop oopObj = jniCheck::validate_handle(thr, obj);
 481     if (!oopObj) {
 482       ReportJNIFatalError(thr, fatal_bad_ref_to_jni);
 483     }
 484     return oopObj;
 485 }
 486 
 487 // Warn if a class descriptor is in decorated form; class descriptors
 488 // passed to JNI findClass should not be decorated unless they are
 489 // array descriptors.
 490 void jniCheck::validate_class_descriptor(JavaThread* thr, const char* name) {
 491   if (name == NULL) return;  // implementation accepts NULL so just return
 492 
 493   size_t len = strlen(name);
 494 
 495   if (len >= 2 &&
 496       name[0] == JVM_SIGNATURE_CLASS &&            // 'L'
 497       name[len-1] == JVM_SIGNATURE_ENDCLASS ) {    // ';'
 498     char msg[JVM_MAXPATHLEN];
 499     jio_snprintf(msg, JVM_MAXPATHLEN, warn_bad_class_descriptor, name);
 500     ReportJNIWarning(thr, msg);
 501   }
 502 }
 503 
 504 Klass* jniCheck::validate_class(JavaThread* thr, jclass clazz, bool allow_primitive) {
 505   ASSERT_OOPS_ALLOWED;
 506   oop mirror = jniCheck::validate_handle(thr, clazz);
 507   if (!mirror) {
 508     ReportJNIFatalError(thr, fatal_received_null_class);
 509   }
 510 
 511   if (mirror->klass() != SystemDictionary::Class_klass()) {
 512     ReportJNIFatalError(thr, fatal_class_not_a_class);
 513   }
 514 
 515   Klass* k = java_lang_Class::as_Klass(mirror);
 516   // Make allowances for primitive classes ...
 517   if (!(k != NULL || allow_primitive && java_lang_Class::is_primitive(mirror))) {
 518     ReportJNIFatalError(thr, fatal_class_not_a_class);
 519   }
 520   return k;
 521 }
 522 
 523 void jniCheck::validate_throwable_klass(JavaThread* thr, Klass* klass) {
 524   ASSERT_OOPS_ALLOWED;
 525   assert(klass != NULL, "klass argument must have a value");
 526 
 527   if (!klass->oop_is_instance() ||
 528       !InstanceKlass::cast(klass)->is_subclass_of(SystemDictionary::Throwable_klass())) {
 529     ReportJNIFatalError(thr, fatal_class_not_a_throwable_class);
 530   }
 531 }
 532 
 533 void jniCheck::validate_call_object(JavaThread* thr, jobject obj, jmethodID method_id) {
 534   /* validate the object being passed */
 535   ASSERT_OOPS_ALLOWED;
 536   jniCheck::validate_jmethod_id(thr, method_id);
 537   jniCheck::validate_object(thr, obj);
 538 }
 539 
 540 void jniCheck::validate_call_class(JavaThread* thr, jclass clazz, jmethodID method_id) {
 541   /* validate the class being passed */
 542   ASSERT_OOPS_ALLOWED;
 543   jniCheck::validate_jmethod_id(thr, method_id);
 544   jniCheck::validate_class(thr, clazz, false);
 545 }
 546 
 547 
 548 /*
 549  * IMPLEMENTATION OF FUNCTIONS IN CHECKED TABLE
 550  */
 551 
 552 JNI_ENTRY_CHECKED(jclass,
 553   checked_jni_DefineClass(JNIEnv *env,
 554                           const char *name,
 555                           jobject loader,
 556                           const jbyte *buf,
 557                           jsize len))
 558     functionEnter(thr);
 559     IN_VM(
 560       jniCheck::validate_object(thr, loader);
 561     )
 562     jclass result = UNCHECKED()->DefineClass(env, name, loader, buf, len);
 563     functionExit(thr);
 564     return result;
 565 JNI_END
 566 
 567 JNI_ENTRY_CHECKED(jclass,
 568   checked_jni_FindClass(JNIEnv *env,
 569                         const char *name))
 570     functionEnter(thr);
 571     IN_VM(
 572       jniCheck::validate_class_descriptor(thr, name);
 573     )
 574     jclass result = UNCHECKED()->FindClass(env, name);
 575     functionExit(thr);
 576     return result;
 577 JNI_END
 578 
 579 JNI_ENTRY_CHECKED(jmethodID,
 580   checked_jni_FromReflectedMethod(JNIEnv *env,
 581                                   jobject method))
 582     functionEnter(thr);
 583     IN_VM(
 584       jniCheck::validate_object(thr, method);
 585     )
 586     jmethodID result = UNCHECKED()->FromReflectedMethod(env, method);
 587     functionExit(thr);
 588     return result;
 589 JNI_END
 590 
 591 JNI_ENTRY_CHECKED(jfieldID,
 592   checked_jni_FromReflectedField(JNIEnv *env,
 593                                  jobject field))
 594     functionEnter(thr);
 595     IN_VM(
 596       jniCheck::validate_object(thr, field);
 597     )
 598     jfieldID result = UNCHECKED()->FromReflectedField(env, field);
 599     functionExit(thr);
 600     return result;
 601 JNI_END
 602 
 603 JNI_ENTRY_CHECKED(jobject,
 604   checked_jni_ToReflectedMethod(JNIEnv *env,
 605                                 jclass cls,
 606                                 jmethodID methodID,
 607                                 jboolean isStatic))
 608     functionEnter(thr);
 609     IN_VM(
 610       jniCheck::validate_class(thr, cls, false);
 611       jniCheck::validate_jmethod_id(thr, methodID);
 612     )
 613     jobject result = UNCHECKED()->ToReflectedMethod(env, cls, methodID,
 614                                                     isStatic);
 615     functionExit(thr);
 616     return result;
 617 JNI_END
 618 
 619 JNI_ENTRY_CHECKED(jclass,
 620   checked_jni_GetSuperclass(JNIEnv *env,
 621                             jclass sub))
 622     functionEnter(thr);
 623     IN_VM(
 624       jniCheck::validate_class(thr, sub, true);
 625     )
 626     jclass result = UNCHECKED()->GetSuperclass(env, sub);
 627     functionExit(thr);
 628     return result;
 629 JNI_END
 630 
 631 JNI_ENTRY_CHECKED(jboolean,
 632   checked_jni_IsAssignableFrom(JNIEnv *env,
 633                                jclass sub,
 634                                jclass sup))
 635     functionEnter(thr);
 636     IN_VM(
 637       jniCheck::validate_class(thr, sub, true);
 638       jniCheck::validate_class(thr, sup, true);
 639     )
 640     jboolean result = UNCHECKED()->IsAssignableFrom(env, sub, sup);
 641     functionExit(thr);
 642     return result;
 643 JNI_END
 644 
 645 JNI_ENTRY_CHECKED(jobject,
 646   checked_jni_ToReflectedField(JNIEnv *env,
 647                                jclass cls,
 648                                jfieldID fieldID,
 649                                jboolean isStatic))
 650     functionEnter(thr);
 651     IN_VM(
 652       jniCheck::validate_class(thr, cls, false);
 653     )
 654     jobject result = UNCHECKED()->ToReflectedField(env, cls, fieldID,
 655                                                    isStatic);
 656     functionExit(thr);
 657     return result;
 658 JNI_END
 659 
 660 JNI_ENTRY_CHECKED(jint,
 661   checked_jni_Throw(JNIEnv *env,
 662                     jthrowable obj))
 663     functionEnter(thr);
 664     IN_VM(
 665       oop oopObj = jniCheck::validate_object(thr, obj);
 666       if (oopObj == NULL) {
 667         // Unchecked Throw tolerates a NULL obj, so just warn
 668         ReportJNIWarning(thr, "JNI Throw called with NULL throwable");
 669       } else {
 670         jniCheck::validate_throwable_klass(thr, oopObj->klass());
 671       }
 672     )
 673     jint result = UNCHECKED()->Throw(env, obj);
 674     functionExit(thr);
 675     return result;
 676 JNI_END
 677 
 678 JNI_ENTRY_CHECKED(jint,
 679   checked_jni_ThrowNew(JNIEnv *env,
 680                        jclass clazz,
 681                        const char *msg))
 682     functionEnter(thr);
 683     IN_VM(
 684       Klass* k = jniCheck::validate_class(thr, clazz, false);
 685       assert(k != NULL, "validate_class shouldn't return NULL Klass*");
 686       jniCheck::validate_throwable_klass(thr, k);
 687     )
 688     jint result = UNCHECKED()->ThrowNew(env, clazz, msg);
 689     functionExit(thr);
 690     return result;
 691 JNI_END
 692 
 693 JNI_ENTRY_CHECKED(jthrowable,
 694   checked_jni_ExceptionOccurred(JNIEnv *env))
 695     thr->clear_pending_jni_exception_check();
 696     functionEnterExceptionAllowed(thr);
 697     jthrowable result = UNCHECKED()->ExceptionOccurred(env);
 698     functionExit(thr);
 699     return result;
 700 JNI_END
 701 
 702 JNI_ENTRY_CHECKED(void,
 703   checked_jni_ExceptionDescribe(JNIEnv *env))
 704     functionEnterExceptionAllowed(thr);
 705     UNCHECKED()->ExceptionDescribe(env);
 706     functionExit(thr);
 707 JNI_END
 708 
 709 JNI_ENTRY_CHECKED(void,
 710   checked_jni_ExceptionClear(JNIEnv *env))
 711     thr->clear_pending_jni_exception_check();
 712     functionEnterExceptionAllowed(thr);
 713     UNCHECKED()->ExceptionClear(env);
 714     functionExit(thr);
 715 JNI_END
 716 
 717 JNI_ENTRY_CHECKED(void,
 718   checked_jni_FatalError(JNIEnv *env,
 719                          const char *msg))
 720     thr->clear_pending_jni_exception_check();
 721     functionEnter(thr);
 722     UNCHECKED()->FatalError(env, msg);
 723     functionExit(thr);
 724 JNI_END
 725 
 726 JNI_ENTRY_CHECKED(jint,
 727   checked_jni_PushLocalFrame(JNIEnv *env,
 728                              jint capacity))
 729     functionEnterExceptionAllowed(thr);
 730     if (capacity < 0)
 731       NativeReportJNIFatalError(thr, "negative capacity");
 732     jint result = UNCHECKED()->PushLocalFrame(env, capacity);
 733     if (result == JNI_OK) {
 734       add_planned_handle_capacity(thr->active_handles(), capacity);
 735     }
 736     functionExit(thr);
 737     return result;
 738 JNI_END
 739 
 740 JNI_ENTRY_CHECKED(jobject,
 741   checked_jni_PopLocalFrame(JNIEnv *env,
 742                             jobject result))
 743     functionEnterExceptionAllowed(thr);
 744     jobject res = UNCHECKED()->PopLocalFrame(env, result);
 745     functionExit(thr);
 746     return res;
 747 JNI_END
 748 
 749 JNI_ENTRY_CHECKED(jobject,
 750   checked_jni_NewGlobalRef(JNIEnv *env,
 751                            jobject lobj))
 752     functionEnter(thr);
 753     IN_VM(
 754       if (lobj != NULL) {
 755         jniCheck::validate_handle(thr, lobj);
 756       }
 757     )
 758     jobject result = UNCHECKED()->NewGlobalRef(env,lobj);
 759     functionExit(thr);
 760     return result;
 761 JNI_END
 762 
 763 JNI_ENTRY_CHECKED(void,
 764   checked_jni_DeleteGlobalRef(JNIEnv *env,
 765                               jobject gref))
 766     functionEnterExceptionAllowed(thr);
 767     IN_VM(
 768       jniCheck::validate_object(thr, gref);
 769       if (gref && !JNIHandles::is_global_handle(gref)) {
 770         ReportJNIFatalError(thr,
 771             "Invalid global JNI handle passed to DeleteGlobalRef");
 772       }
 773     )
 774     UNCHECKED()->DeleteGlobalRef(env,gref);
 775     functionExit(thr);
 776 JNI_END
 777 
 778 JNI_ENTRY_CHECKED(void,
 779   checked_jni_DeleteLocalRef(JNIEnv *env,
 780                              jobject obj))
 781     functionEnterExceptionAllowed(thr);
 782     IN_VM(
 783       jniCheck::validate_object(thr, obj);
 784       if (obj && !(JNIHandles::is_local_handle(thr, obj) ||
 785                    JNIHandles::is_frame_handle(thr, obj)))
 786         ReportJNIFatalError(thr,
 787             "Invalid local JNI handle passed to DeleteLocalRef");
 788     )
 789     UNCHECKED()->DeleteLocalRef(env, obj);
 790     functionExit(thr);
 791 JNI_END
 792 
 793 JNI_ENTRY_CHECKED(jboolean,
 794   checked_jni_IsSameObject(JNIEnv *env,
 795                            jobject obj1,
 796                            jobject obj2))
 797     functionEnterExceptionAllowed(thr);
 798     IN_VM(
 799       /* This JNI function can be used to compare weak global references
 800        * to NULL objects. If the handles are valid, but contain NULL,
 801        * then don't attempt to validate the object.
 802        */
 803       if (obj1 != NULL && jniCheck::validate_handle(thr, obj1) != NULL) {
 804         jniCheck::validate_object(thr, obj1);
 805       }
 806       if (obj2 != NULL && jniCheck::validate_handle(thr, obj2) != NULL) {
 807         jniCheck::validate_object(thr, obj2);
 808       }
 809     )
 810     jboolean result = UNCHECKED()->IsSameObject(env,obj1,obj2);
 811     functionExit(thr);
 812     return result;
 813 JNI_END
 814 
 815 JNI_ENTRY_CHECKED(jobject,
 816   checked_jni_NewLocalRef(JNIEnv *env,
 817                           jobject ref))
 818     functionEnter(thr);
 819     IN_VM(
 820       if (ref != NULL) {
 821         jniCheck::validate_handle(thr, ref);
 822       }
 823     )
 824     jobject result = UNCHECKED()->NewLocalRef(env, ref);
 825     functionExit(thr);
 826     return result;
 827 JNI_END
 828 
 829 JNI_ENTRY_CHECKED(jint,
 830   checked_jni_EnsureLocalCapacity(JNIEnv *env,
 831                                   jint capacity))
 832     functionEnter(thr);
 833     if (capacity < 0) {
 834       NativeReportJNIFatalError(thr, "negative capacity");
 835     }
 836     jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity);
 837     if (result == JNI_OK) {
 838       add_planned_handle_capacity(thr->active_handles(), capacity);
 839     }
 840     functionExit(thr);
 841     return result;
 842 JNI_END
 843 
 844 JNI_ENTRY_CHECKED(jobject,
 845   checked_jni_AllocObject(JNIEnv *env,
 846                           jclass clazz))
 847     functionEnter(thr);
 848     IN_VM(
 849       jniCheck::validate_class(thr, clazz, false);
 850     )
 851     jobject result = UNCHECKED()->AllocObject(env,clazz);
 852     functionExit(thr);
 853     return result;
 854 JNI_END
 855 
 856 JNI_ENTRY_CHECKED(jobject,
 857   checked_jni_NewObject(JNIEnv *env,
 858                         jclass clazz,
 859                         jmethodID methodID,
 860                         ...))
 861     functionEnter(thr);
 862     va_list args;
 863     IN_VM(
 864       jniCheck::validate_class(thr, clazz, false);
 865       jniCheck::validate_jmethod_id(thr, methodID);
 866     )
 867     va_start(args, methodID);
 868     jobject result = UNCHECKED()->NewObjectV(env,clazz,methodID,args);
 869     va_end(args);
 870     functionExit(thr);
 871     return result;
 872 JNI_END
 873 
 874 JNI_ENTRY_CHECKED(jobject,
 875   checked_jni_NewObjectV(JNIEnv *env,
 876                          jclass clazz,
 877                          jmethodID methodID,
 878                          va_list args))
 879     functionEnter(thr);
 880     IN_VM(
 881       jniCheck::validate_class(thr, clazz, false);
 882       jniCheck::validate_jmethod_id(thr, methodID);
 883     )
 884     jobject result = UNCHECKED()->NewObjectV(env,clazz,methodID,args);
 885     functionExit(thr);
 886     return result;
 887 JNI_END
 888 
 889 JNI_ENTRY_CHECKED(jobject,
 890   checked_jni_NewObjectA(JNIEnv *env,
 891                          jclass clazz,
 892                          jmethodID methodID,
 893                          const jvalue *args))
 894     functionEnter(thr);
 895     IN_VM(
 896       jniCheck::validate_class(thr, clazz, false);
 897       jniCheck::validate_jmethod_id(thr, methodID);
 898     )
 899     jobject result = UNCHECKED()->NewObjectA(env,clazz,methodID,args);
 900     functionExit(thr);
 901     return result;
 902 JNI_END
 903 
 904 JNI_ENTRY_CHECKED(jclass,
 905   checked_jni_GetObjectClass(JNIEnv *env,
 906                              jobject obj))
 907     functionEnter(thr);
 908     IN_VM(
 909       jniCheck::validate_object(thr, obj);
 910     )
 911     jclass result = UNCHECKED()->GetObjectClass(env,obj);
 912     functionExit(thr);
 913     return result;
 914 JNI_END
 915 
 916 JNI_ENTRY_CHECKED(jboolean,
 917   checked_jni_IsInstanceOf(JNIEnv *env,
 918                            jobject obj,
 919                            jclass clazz))
 920     functionEnter(thr);
 921     IN_VM(
 922       jniCheck::validate_object(thr, obj);
 923       jniCheck::validate_class(thr, clazz, true);
 924     )
 925     jboolean result = UNCHECKED()->IsInstanceOf(env,obj,clazz);
 926     functionExit(thr);
 927     return result;
 928 JNI_END
 929 
 930 JNI_ENTRY_CHECKED(jmethodID,
 931   checked_jni_GetMethodID(JNIEnv *env,
 932                           jclass clazz,
 933                           const char *name,
 934                           const char *sig))
 935     functionEnter(thr);
 936     IN_VM(
 937       jniCheck::validate_class(thr, clazz, false);
 938     )
 939     jmethodID result = UNCHECKED()->GetMethodID(env,clazz,name,sig);
 940     functionExit(thr);
 941     return result;
 942 JNI_END
 943 
 944 #define WRAPPER_CallMethod(ResultType, Result) \
 945 JNI_ENTRY_CHECKED(ResultType,  \
 946   checked_jni_Call##Result##Method(JNIEnv *env, \
 947                                    jobject obj, \
 948                                    jmethodID methodID, \
 949                                    ...)) \
 950     functionEnter(thr); \
 951     va_list args; \
 952     IN_VM( \
 953       jniCheck::validate_call_object(thr, obj, methodID); \
 954     ) \
 955     va_start(args,methodID); \
 956     ResultType result =UNCHECKED()->Call##Result##MethodV(env, obj, methodID, \
 957                                                           args); \
 958     va_end(args); \
 959     thr->set_pending_jni_exception_check("Call"#Result"Method"); \
 960     functionExit(thr); \
 961     return result; \
 962 JNI_END \
 963 \
 964 JNI_ENTRY_CHECKED(ResultType,  \
 965   checked_jni_Call##Result##MethodV(JNIEnv *env, \
 966                                     jobject obj, \
 967                                     jmethodID methodID, \
 968                                     va_list args)) \
 969     functionEnter(thr); \
 970     IN_VM(\
 971       jniCheck::validate_call_object(thr, obj, methodID); \
 972     ) \
 973     ResultType result = UNCHECKED()->Call##Result##MethodV(env, obj, methodID,\
 974                                                            args); \
 975     thr->set_pending_jni_exception_check("Call"#Result"MethodV"); \
 976     functionExit(thr); \
 977     return result; \
 978 JNI_END \
 979 \
 980 JNI_ENTRY_CHECKED(ResultType,  \
 981   checked_jni_Call##Result##MethodA(JNIEnv *env, \
 982                                     jobject obj, \
 983                                     jmethodID methodID, \
 984                                     const jvalue * args)) \
 985     functionEnter(thr); \
 986     IN_VM( \
 987       jniCheck::validate_call_object(thr, obj, methodID); \
 988     ) \
 989     ResultType result = UNCHECKED()->Call##Result##MethodA(env, obj, methodID,\
 990                                                            args); \
 991     thr->set_pending_jni_exception_check("Call"#Result"MethodA"); \
 992     functionExit(thr); \
 993     return result; \
 994 JNI_END
 995 
 996 WRAPPER_CallMethod(jobject,Object)
 997 WRAPPER_CallMethod(jboolean,Boolean)
 998 WRAPPER_CallMethod(jbyte,Byte)
 999 WRAPPER_CallMethod(jshort,Short)
1000 WRAPPER_CallMethod(jchar,Char)
1001 WRAPPER_CallMethod(jint,Int)
1002 WRAPPER_CallMethod(jlong,Long)
1003 WRAPPER_CallMethod(jfloat,Float)
1004 WRAPPER_CallMethod(jdouble,Double)
1005 
1006 JNI_ENTRY_CHECKED(void,
1007   checked_jni_CallVoidMethod(JNIEnv *env, \
1008                              jobject obj, \
1009                              jmethodID methodID, \
1010                              ...))
1011     functionEnter(thr);
1012     va_list args;
1013     IN_VM(
1014       jniCheck::validate_call_object(thr, obj, methodID);
1015     )
1016     va_start(args,methodID);
1017     UNCHECKED()->CallVoidMethodV(env,obj,methodID,args);
1018     va_end(args);
1019     thr->set_pending_jni_exception_check("CallVoidMethod");
1020     functionExit(thr);
1021 JNI_END
1022 
1023 JNI_ENTRY_CHECKED(void,
1024   checked_jni_CallVoidMethodV(JNIEnv *env,
1025                               jobject obj,
1026                               jmethodID methodID,
1027                               va_list args))
1028     functionEnter(thr);
1029     IN_VM(
1030       jniCheck::validate_call_object(thr, obj, methodID);
1031     )
1032     UNCHECKED()->CallVoidMethodV(env,obj,methodID,args);
1033     thr->set_pending_jni_exception_check("CallVoidMethodV");
1034     functionExit(thr);
1035 JNI_END
1036 
1037 JNI_ENTRY_CHECKED(void,
1038   checked_jni_CallVoidMethodA(JNIEnv *env,
1039                               jobject obj,
1040                               jmethodID methodID,
1041                               const jvalue * args))
1042     functionEnter(thr);
1043     IN_VM(
1044       jniCheck::validate_call_object(thr, obj, methodID);
1045     )
1046     UNCHECKED()->CallVoidMethodA(env,obj,methodID,args);
1047     thr->set_pending_jni_exception_check("CallVoidMethodA");
1048     functionExit(thr);
1049 JNI_END
1050 
1051 #define WRAPPER_CallNonvirtualMethod(ResultType, Result) \
1052 JNI_ENTRY_CHECKED(ResultType,  \
1053   checked_jni_CallNonvirtual##Result##Method(JNIEnv *env, \
1054                                              jobject obj, \
1055                                              jclass clazz, \
1056                                              jmethodID methodID, \
1057                                              ...)) \
1058     functionEnter(thr); \
1059     va_list args; \
1060     IN_VM( \
1061       jniCheck::validate_call_object(thr, obj, methodID); \
1062       jniCheck::validate_call_class(thr, clazz, methodID); \
1063     ) \
1064     va_start(args,methodID); \
1065     ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodV(env, \
1066                                                                      obj, \
1067                                                                      clazz, \
1068                                                                      methodID,\
1069                                                                      args); \
1070     va_end(args); \
1071     thr->set_pending_jni_exception_check("CallNonvirtual"#Result"Method"); \
1072     functionExit(thr); \
1073     return result; \
1074 JNI_END \
1075 \
1076 JNI_ENTRY_CHECKED(ResultType,  \
1077   checked_jni_CallNonvirtual##Result##MethodV(JNIEnv *env, \
1078                                               jobject obj, \
1079                                               jclass clazz, \
1080                                               jmethodID methodID, \
1081                                               va_list args)) \
1082     functionEnter(thr); \
1083     IN_VM( \
1084       jniCheck::validate_call_object(thr, obj, methodID); \
1085       jniCheck::validate_call_class(thr, clazz, methodID); \
1086     ) \
1087     ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodV(env, \
1088                                                                      obj, \
1089                                                                      clazz, \
1090                                                                      methodID,\
1091                                                                      args); \
1092     thr->set_pending_jni_exception_check("CallNonvirtual"#Result"MethodV"); \
1093     functionExit(thr); \
1094     return result; \
1095 JNI_END \
1096 \
1097 JNI_ENTRY_CHECKED(ResultType,  \
1098   checked_jni_CallNonvirtual##Result##MethodA(JNIEnv *env, \
1099                                               jobject obj, \
1100                                               jclass clazz, \
1101                                               jmethodID methodID, \
1102                                               const jvalue * args)) \
1103     functionEnter(thr); \
1104     IN_VM( \
1105       jniCheck::validate_call_object(thr, obj, methodID); \
1106       jniCheck::validate_call_class(thr, clazz, methodID); \
1107     ) \
1108     ResultType result = UNCHECKED()->CallNonvirtual##Result##MethodA(env, \
1109                                                                      obj, \
1110                                                                      clazz, \
1111                                                                      methodID,\
1112                                                                      args); \
1113     thr->set_pending_jni_exception_check("CallNonvirtual"#Result"MethodA"); \
1114     functionExit(thr); \
1115     return result; \
1116 JNI_END
1117 
1118 WRAPPER_CallNonvirtualMethod(jobject,Object)
1119 WRAPPER_CallNonvirtualMethod(jboolean,Boolean)
1120 WRAPPER_CallNonvirtualMethod(jbyte,Byte)
1121 WRAPPER_CallNonvirtualMethod(jshort,Short)
1122 WRAPPER_CallNonvirtualMethod(jchar,Char)
1123 WRAPPER_CallNonvirtualMethod(jint,Int)
1124 WRAPPER_CallNonvirtualMethod(jlong,Long)
1125 WRAPPER_CallNonvirtualMethod(jfloat,Float)
1126 WRAPPER_CallNonvirtualMethod(jdouble,Double)
1127 
1128 JNI_ENTRY_CHECKED(void,
1129   checked_jni_CallNonvirtualVoidMethod(JNIEnv *env,
1130                                        jobject obj,
1131                                        jclass clazz,
1132                                        jmethodID methodID,
1133                                        ...))
1134     functionEnter(thr);
1135     va_list args;
1136     IN_VM(
1137       jniCheck::validate_call_object(thr, obj, methodID);
1138       jniCheck::validate_call_class(thr, clazz, methodID);
1139     )
1140     va_start(args,methodID);
1141     UNCHECKED()->CallNonvirtualVoidMethodV(env,obj,clazz,methodID,args);
1142     va_end(args);
1143     thr->set_pending_jni_exception_check("CallNonvirtualVoidMethod");
1144     functionExit(thr);
1145 JNI_END
1146 
1147 JNI_ENTRY_CHECKED(void,
1148   checked_jni_CallNonvirtualVoidMethodV(JNIEnv *env,
1149                                         jobject obj,
1150                                         jclass clazz,
1151                                         jmethodID methodID,
1152                                         va_list args))
1153     functionEnter(thr);
1154     IN_VM(
1155       jniCheck::validate_call_object(thr, obj, methodID);
1156       jniCheck::validate_call_class(thr, clazz, methodID);
1157     )
1158     UNCHECKED()->CallNonvirtualVoidMethodV(env,obj,clazz,methodID,args);
1159     thr->set_pending_jni_exception_check("CallNonvirtualVoidMethodV");
1160     functionExit(thr);
1161 JNI_END
1162 
1163 JNI_ENTRY_CHECKED(void,
1164   checked_jni_CallNonvirtualVoidMethodA(JNIEnv *env,
1165                                         jobject obj,
1166                                         jclass clazz,
1167                                         jmethodID methodID,
1168                                         const jvalue * args))
1169     functionEnter(thr);
1170     IN_VM(
1171       jniCheck::validate_call_object(thr, obj, methodID);
1172       jniCheck::validate_call_class(thr, clazz, methodID);
1173     )
1174     UNCHECKED()->CallNonvirtualVoidMethodA(env,obj,clazz,methodID,args);
1175     thr->set_pending_jni_exception_check("CallNonvirtualVoidMethodA");
1176     functionExit(thr);
1177 JNI_END
1178 
1179 JNI_ENTRY_CHECKED(jfieldID,
1180   checked_jni_GetFieldID(JNIEnv *env,
1181                          jclass clazz,
1182                          const char *name,
1183                          const char *sig))
1184     functionEnter(thr);
1185     IN_VM(
1186       jniCheck::validate_class(thr, clazz, false);
1187     )
1188     jfieldID result = UNCHECKED()->GetFieldID(env,clazz,name,sig);
1189     functionExit(thr);
1190     return result;
1191 JNI_END
1192 
1193 #define WRAPPER_GetField(ReturnType,Result,FieldType) \
1194 JNI_ENTRY_CHECKED(ReturnType,  \
1195   checked_jni_Get##Result##Field(JNIEnv *env, \
1196                                  jobject obj, \
1197                                  jfieldID fieldID)) \
1198     functionEnter(thr); \
1199     IN_VM( \
1200       checkInstanceFieldID(thr, fieldID, obj, FieldType); \
1201     ) \
1202     ReturnType result = UNCHECKED()->Get##Result##Field(env,obj,fieldID); \
1203     functionExit(thr); \
1204     return result; \
1205 JNI_END
1206 
1207 WRAPPER_GetField(jobject,  Object,  T_OBJECT)
1208 WRAPPER_GetField(jboolean, Boolean, T_BOOLEAN)
1209 WRAPPER_GetField(jbyte,    Byte,    T_BYTE)
1210 WRAPPER_GetField(jshort,   Short,   T_SHORT)
1211 WRAPPER_GetField(jchar,    Char,    T_CHAR)
1212 WRAPPER_GetField(jint,     Int,     T_INT)
1213 WRAPPER_GetField(jlong,    Long,    T_LONG)
1214 WRAPPER_GetField(jfloat,   Float,   T_FLOAT)
1215 WRAPPER_GetField(jdouble,  Double,  T_DOUBLE)
1216 
1217 #define WRAPPER_SetField(ValueType,Result,FieldType) \
1218 JNI_ENTRY_CHECKED(void,  \
1219   checked_jni_Set##Result##Field(JNIEnv *env, \
1220                                  jobject obj, \
1221                                  jfieldID fieldID, \
1222                                  ValueType val)) \
1223     functionEnter(thr); \
1224     IN_VM( \
1225       checkInstanceFieldID(thr, fieldID, obj, FieldType); \
1226     ) \
1227     UNCHECKED()->Set##Result##Field(env,obj,fieldID,val); \
1228     functionExit(thr); \
1229 JNI_END
1230 
1231 WRAPPER_SetField(jobject,  Object,  T_OBJECT)
1232 WRAPPER_SetField(jboolean, Boolean, T_BOOLEAN)
1233 WRAPPER_SetField(jbyte,    Byte,    T_BYTE)
1234 WRAPPER_SetField(jshort,   Short,   T_SHORT)
1235 WRAPPER_SetField(jchar,    Char,    T_CHAR)
1236 WRAPPER_SetField(jint,     Int,     T_INT)
1237 WRAPPER_SetField(jlong,    Long,    T_LONG)
1238 WRAPPER_SetField(jfloat,   Float,   T_FLOAT)
1239 WRAPPER_SetField(jdouble,  Double,  T_DOUBLE)
1240 
1241 
1242 JNI_ENTRY_CHECKED(jmethodID,
1243   checked_jni_GetStaticMethodID(JNIEnv *env,
1244                                 jclass clazz,
1245                                 const char *name,
1246                                 const char *sig))
1247     functionEnter(thr);
1248     IN_VM(
1249       jniCheck::validate_class(thr, clazz, false);
1250     )
1251     jmethodID result = UNCHECKED()->GetStaticMethodID(env,clazz,name,sig);
1252     functionExit(thr);
1253     return result;
1254 JNI_END
1255 
1256 #define WRAPPER_CallStaticMethod(ReturnType,Result) \
1257 JNI_ENTRY_CHECKED(ReturnType,  \
1258   checked_jni_CallStatic##Result##Method(JNIEnv *env, \
1259                                          jclass clazz, \
1260                                          jmethodID methodID, \
1261                                          ...)) \
1262     functionEnter(thr); \
1263     va_list args; \
1264     IN_VM( \
1265       jniCheck::validate_jmethod_id(thr, methodID); \
1266       jniCheck::validate_class(thr, clazz, false); \
1267     ) \
1268     va_start(args,methodID); \
1269     ReturnType result = UNCHECKED()->CallStatic##Result##MethodV(env, \
1270                                                                  clazz, \
1271                                                                  methodID, \
1272                                                                  args); \
1273     va_end(args); \
1274     thr->set_pending_jni_exception_check("CallStatic"#Result"Method"); \
1275     functionExit(thr); \
1276     return result; \
1277 JNI_END \
1278 \
1279 JNI_ENTRY_CHECKED(ReturnType,  \
1280   checked_jni_CallStatic##Result##MethodV(JNIEnv *env, \
1281                                           jclass clazz, \
1282                                           jmethodID methodID,\
1283                                           va_list args)) \
1284     functionEnter(thr); \
1285     IN_VM( \
1286       jniCheck::validate_jmethod_id(thr, methodID); \
1287       jniCheck::validate_class(thr, clazz, false); \
1288     ) \
1289     ReturnType result = UNCHECKED()->CallStatic##Result##MethodV(env, \
1290                                                                  clazz, \
1291                                                                  methodID, \
1292                                                                  args); \
1293     thr->set_pending_jni_exception_check("CallStatic"#Result"MethodV"); \
1294     functionExit(thr); \
1295     return result; \
1296 JNI_END \
1297 \
1298 JNI_ENTRY_CHECKED(ReturnType,  \
1299   checked_jni_CallStatic##Result##MethodA(JNIEnv *env, \
1300                                           jclass clazz, \
1301                                           jmethodID methodID, \
1302                                           const jvalue *args)) \
1303     functionEnter(thr); \
1304     IN_VM( \
1305       jniCheck::validate_jmethod_id(thr, methodID); \
1306       jniCheck::validate_class(thr, clazz, false); \
1307     ) \
1308     ReturnType result = UNCHECKED()->CallStatic##Result##MethodA(env, \
1309                                                                  clazz, \
1310                                                                  methodID, \
1311                                                                  args); \
1312     thr->set_pending_jni_exception_check("CallStatic"#Result"MethodA"); \
1313     functionExit(thr); \
1314     return result; \
1315 JNI_END
1316 
1317 WRAPPER_CallStaticMethod(jobject,Object)
1318 WRAPPER_CallStaticMethod(jboolean,Boolean)
1319 WRAPPER_CallStaticMethod(jbyte,Byte)
1320 WRAPPER_CallStaticMethod(jshort,Short)
1321 WRAPPER_CallStaticMethod(jchar,Char)
1322 WRAPPER_CallStaticMethod(jint,Int)
1323 WRAPPER_CallStaticMethod(jlong,Long)
1324 WRAPPER_CallStaticMethod(jfloat,Float)
1325 WRAPPER_CallStaticMethod(jdouble,Double)
1326 
1327 JNI_ENTRY_CHECKED(void,
1328   checked_jni_CallStaticVoidMethod(JNIEnv *env,
1329                                    jclass cls,
1330                                    jmethodID methodID,
1331                                    ...))
1332     functionEnter(thr);
1333     va_list args;
1334     IN_VM(
1335       jniCheck::validate_jmethod_id(thr, methodID);
1336       jniCheck::validate_class(thr, cls, false);
1337     )
1338     va_start(args,methodID);
1339     UNCHECKED()->CallStaticVoidMethodV(env,cls,methodID,args);
1340     va_end(args);
1341     thr->set_pending_jni_exception_check("CallStaticVoidMethod");
1342     functionExit(thr);
1343 JNI_END
1344 
1345 JNI_ENTRY_CHECKED(void,
1346   checked_jni_CallStaticVoidMethodV(JNIEnv *env,
1347                                     jclass cls,
1348                                     jmethodID methodID,
1349                                     va_list args))
1350     functionEnter(thr);
1351     IN_VM(
1352       jniCheck::validate_jmethod_id(thr, methodID);
1353       jniCheck::validate_class(thr, cls, false);
1354     )
1355     UNCHECKED()->CallStaticVoidMethodV(env,cls,methodID,args);
1356     thr->set_pending_jni_exception_check("CallStaticVoidMethodV");
1357     functionExit(thr);
1358 JNI_END
1359 
1360 JNI_ENTRY_CHECKED(void,
1361   checked_jni_CallStaticVoidMethodA(JNIEnv *env,
1362                                     jclass cls,
1363                                     jmethodID methodID,
1364                                     const jvalue * args))
1365     functionEnter(thr);
1366     IN_VM(
1367       jniCheck::validate_jmethod_id(thr, methodID);
1368       jniCheck::validate_class(thr, cls, false);
1369     )
1370     UNCHECKED()->CallStaticVoidMethodA(env,cls,methodID,args);
1371     thr->set_pending_jni_exception_check("CallStaticVoidMethodA");
1372     functionExit(thr);
1373 JNI_END
1374 
1375 JNI_ENTRY_CHECKED(jfieldID,
1376   checked_jni_GetStaticFieldID(JNIEnv *env,
1377                                jclass clazz,
1378                                const char *name,
1379                                const char *sig))
1380     functionEnter(thr);
1381     IN_VM(
1382       jniCheck::validate_class(thr, clazz, false);
1383     )
1384     jfieldID result = UNCHECKED()->GetStaticFieldID(env,clazz,name,sig);
1385     functionExit(thr);
1386     return result;
1387 JNI_END
1388 
1389 #define WRAPPER_GetStaticField(ReturnType,Result,FieldType) \
1390 JNI_ENTRY_CHECKED(ReturnType,  \
1391   checked_jni_GetStatic##Result##Field(JNIEnv *env, \
1392                                        jclass clazz, \
1393                                        jfieldID fieldID)) \
1394     functionEnter(thr); \
1395     IN_VM( \
1396       jniCheck::validate_class(thr, clazz, false); \
1397       checkStaticFieldID(thr, fieldID, clazz, FieldType); \
1398     ) \
1399     ReturnType result = UNCHECKED()->GetStatic##Result##Field(env, \
1400                                                               clazz, \
1401                                                               fieldID); \
1402     functionExit(thr); \
1403     return result; \
1404 JNI_END
1405 
1406 WRAPPER_GetStaticField(jobject,  Object,  T_OBJECT)
1407 WRAPPER_GetStaticField(jboolean, Boolean, T_BOOLEAN)
1408 WRAPPER_GetStaticField(jbyte,    Byte,    T_BYTE)
1409 WRAPPER_GetStaticField(jshort,   Short,   T_SHORT)
1410 WRAPPER_GetStaticField(jchar,    Char,    T_CHAR)
1411 WRAPPER_GetStaticField(jint,     Int,     T_INT)
1412 WRAPPER_GetStaticField(jlong,    Long,    T_LONG)
1413 WRAPPER_GetStaticField(jfloat,   Float,   T_FLOAT)
1414 WRAPPER_GetStaticField(jdouble,  Double,  T_DOUBLE)
1415 
1416 #define WRAPPER_SetStaticField(ValueType,Result,FieldType) \
1417 JNI_ENTRY_CHECKED(void,  \
1418   checked_jni_SetStatic##Result##Field(JNIEnv *env, \
1419                                        jclass clazz, \
1420                                        jfieldID fieldID, \
1421                                        ValueType value)) \
1422     functionEnter(thr); \
1423     IN_VM( \
1424       jniCheck::validate_class(thr, clazz, false); \
1425       checkStaticFieldID(thr, fieldID, clazz, FieldType); \
1426     ) \
1427     UNCHECKED()->SetStatic##Result##Field(env,clazz,fieldID,value); \
1428     functionExit(thr); \
1429 JNI_END
1430 
1431 WRAPPER_SetStaticField(jobject,  Object,  T_OBJECT)
1432 WRAPPER_SetStaticField(jboolean, Boolean, T_BOOLEAN)
1433 WRAPPER_SetStaticField(jbyte,    Byte,    T_BYTE)
1434 WRAPPER_SetStaticField(jshort,   Short,   T_SHORT)
1435 WRAPPER_SetStaticField(jchar,    Char,    T_CHAR)
1436 WRAPPER_SetStaticField(jint,     Int,     T_INT)
1437 WRAPPER_SetStaticField(jlong,    Long,    T_LONG)
1438 WRAPPER_SetStaticField(jfloat,   Float,   T_FLOAT)
1439 WRAPPER_SetStaticField(jdouble,  Double,  T_DOUBLE)
1440 
1441 
1442 JNI_ENTRY_CHECKED(jstring,
1443   checked_jni_NewString(JNIEnv *env,
1444                         const jchar *unicode,
1445                         jsize len))
1446     functionEnter(thr);
1447     jstring result = UNCHECKED()->NewString(env,unicode,len);
1448     functionExit(thr);
1449     return result;
1450 JNI_END
1451 
1452 JNI_ENTRY_CHECKED(jsize,
1453   checked_jni_GetStringLength(JNIEnv *env,
1454                               jstring str))
1455     functionEnter(thr);
1456     IN_VM(
1457       checkString(thr, str);
1458     )
1459     jsize result = UNCHECKED()->GetStringLength(env,str);
1460     functionExit(thr);
1461     return result;
1462 JNI_END
1463 
1464 // Arbitrary (but well-known) tag
1465 const void* STRING_TAG = (void*)0x47114711;
1466 
1467 JNI_ENTRY_CHECKED(const jchar *,
1468   checked_jni_GetStringChars(JNIEnv *env,
1469                              jstring str,
1470                              jboolean *isCopy))
1471     functionEnter(thr);
1472     IN_VM(
1473       checkString(thr, str);
1474     )
1475     jchar* new_result = NULL;
1476     const jchar *result = UNCHECKED()->GetStringChars(env,str,isCopy);
1477     assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringChars didn't return a copy as expected");
1478     if (result != NULL) {
1479       size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination
1480       len *= sizeof(jchar);
1481       new_result = (jchar*) GuardedMemory::wrap_copy(result, len, STRING_TAG);
1482       if (new_result == NULL) {
1483         vm_exit_out_of_memory(len, OOM_MALLOC_ERROR, "checked_jni_GetStringChars");
1484       }
1485       // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes
1486       // Note that the dtrace arguments for the allocated memory will not match up with this solution.
1487       FreeHeap((char*)result);
1488     }
1489     functionExit(thr);
1490     return new_result;
1491 JNI_END
1492 
1493 JNI_ENTRY_CHECKED(void,
1494   checked_jni_ReleaseStringChars(JNIEnv *env,
1495                                  jstring str,
1496                                  const jchar *chars))
1497     functionEnterExceptionAllowed(thr);
1498     IN_VM(
1499       checkString(thr, str);
1500     )
1501     if (chars == NULL) {
1502        // still do the unchecked call to allow dtrace probes
1503        UNCHECKED()->ReleaseStringChars(env,str,chars);
1504     }
1505     else {
1506       GuardedMemory guarded((void*)chars);
1507       if (!guarded.verify_guards()) {
1508         tty->print_cr("ReleaseStringChars: release chars failed bounds check. "
1509             "string: " PTR_FORMAT " chars: " PTR_FORMAT, p2i(str), p2i(chars));
1510         guarded.print_on(tty);
1511         NativeReportJNIFatalError(thr, "ReleaseStringChars: "
1512             "release chars failed bounds check.");
1513       }
1514       if (guarded.get_tag() != STRING_TAG) {
1515         tty->print_cr("ReleaseStringChars: called on something not allocated "
1516             "by GetStringChars. string: " PTR_FORMAT " chars: " PTR_FORMAT,
1517             p2i(str), p2i(chars));
1518         NativeReportJNIFatalError(thr, "ReleaseStringChars called on something "
1519             "not allocated by GetStringChars");
1520       }
1521        UNCHECKED()->ReleaseStringChars(env, str,
1522            (const jchar*) guarded.release_for_freeing());
1523     }
1524     functionExit(thr);
1525 JNI_END
1526 
1527 JNI_ENTRY_CHECKED(jstring,
1528   checked_jni_NewStringUTF(JNIEnv *env,
1529                            const char *utf))
1530     functionEnter(thr);
1531     jstring result = UNCHECKED()->NewStringUTF(env,utf);
1532     functionExit(thr);
1533     return result;
1534 JNI_END
1535 
1536 JNI_ENTRY_CHECKED(jsize,
1537   checked_jni_GetStringUTFLength(JNIEnv *env,
1538                                  jstring str))
1539     functionEnter(thr);
1540     IN_VM(
1541       checkString(thr, str);
1542     )
1543     jsize result = UNCHECKED()->GetStringUTFLength(env,str);
1544     functionExit(thr);
1545     return result;
1546 JNI_END
1547 
1548 // Arbitrary (but well-known) tag - different than GetStringChars
1549 const void* STRING_UTF_TAG = (void*) 0x48124812;
1550 
1551 JNI_ENTRY_CHECKED(const char *,
1552   checked_jni_GetStringUTFChars(JNIEnv *env,
1553                                 jstring str,
1554                                 jboolean *isCopy))
1555     functionEnter(thr);
1556     IN_VM(
1557       checkString(thr, str);
1558     )
1559     char* new_result = NULL;
1560     const char *result = UNCHECKED()->GetStringUTFChars(env,str,isCopy);
1561     assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringUTFChars didn't return a copy as expected");
1562     if (result != NULL) {
1563       size_t len = strlen(result) + 1; // + 1 for NULL termination
1564       new_result = (char*) GuardedMemory::wrap_copy(result, len, STRING_UTF_TAG);
1565       if (new_result == NULL) {
1566         vm_exit_out_of_memory(len, OOM_MALLOC_ERROR, "checked_jni_GetStringUTFChars");
1567       }
1568       // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes
1569       // Note that the dtrace arguments for the allocated memory will not match up with this solution.
1570       FreeHeap((char*)result, mtInternal);
1571     }
1572     functionExit(thr);
1573     return new_result;
1574 JNI_END
1575 
1576 JNI_ENTRY_CHECKED(void,
1577   checked_jni_ReleaseStringUTFChars(JNIEnv *env,
1578                                     jstring str,
1579                                     const char* chars))
1580     functionEnterExceptionAllowed(thr);
1581     IN_VM(
1582       checkString(thr, str);
1583     )
1584     if (chars == NULL) {
1585        // still do the unchecked call to allow dtrace probes
1586        UNCHECKED()->ReleaseStringUTFChars(env,str,chars);
1587     }
1588     else {
1589       GuardedMemory guarded((void*)chars);
1590       if (!guarded.verify_guards()) {
1591         tty->print_cr("ReleaseStringUTFChars: release chars failed bounds check. "
1592             "string: " PTR_FORMAT " chars: " PTR_FORMAT, p2i(str), p2i(chars));
1593         guarded.print_on(tty);
1594         NativeReportJNIFatalError(thr, "ReleaseStringUTFChars: "
1595             "release chars failed bounds check.");
1596       }
1597       if (guarded.get_tag() != STRING_UTF_TAG) {
1598         tty->print_cr("ReleaseStringUTFChars: called on something not "
1599             "allocated by GetStringUTFChars. string: " PTR_FORMAT " chars: "
1600             PTR_FORMAT, p2i(str), p2i(chars));
1601         NativeReportJNIFatalError(thr, "ReleaseStringUTFChars "
1602             "called on something not allocated by GetStringUTFChars");
1603       }
1604       UNCHECKED()->ReleaseStringUTFChars(env, str,
1605           (const char*) guarded.release_for_freeing());
1606     }
1607     functionExit(thr);
1608 JNI_END
1609 
1610 JNI_ENTRY_CHECKED(jsize,
1611   checked_jni_GetArrayLength(JNIEnv *env,
1612                              jarray array))
1613     functionEnter(thr);
1614     IN_VM(
1615       check_is_array(thr, array);
1616     )
1617     jsize result = UNCHECKED()->GetArrayLength(env,array);
1618     functionExit(thr);
1619     return result;
1620 JNI_END
1621 
1622 JNI_ENTRY_CHECKED(jobjectArray,
1623   checked_jni_NewObjectArray(JNIEnv *env,
1624                              jsize len,
1625                              jclass clazz,
1626                              jobject init))
1627     functionEnter(thr);
1628     jobjectArray result = UNCHECKED()->NewObjectArray(env,len,clazz,init);
1629     functionExit(thr);
1630     return result;
1631 JNI_END
1632 
1633 JNI_ENTRY_CHECKED(jobject,
1634   checked_jni_GetObjectArrayElement(JNIEnv *env,
1635                                     jobjectArray array,
1636                                     jsize index))
1637     functionEnter(thr);
1638     IN_VM(
1639       check_is_obj_array(thr, array);
1640     )
1641     jobject result = UNCHECKED()->GetObjectArrayElement(env,array,index);
1642     functionExit(thr);
1643     return result;
1644 JNI_END
1645 
1646 JNI_ENTRY_CHECKED(void,
1647   checked_jni_SetObjectArrayElement(JNIEnv *env,
1648                                     jobjectArray array,
1649                                     jsize index,
1650                                     jobject val))
1651     functionEnter(thr);
1652     IN_VM(
1653       check_is_obj_array(thr, array);
1654     )
1655     UNCHECKED()->SetObjectArrayElement(env,array,index,val);
1656     functionExit(thr);
1657 JNI_END
1658 
1659 #define WRAPPER_NewScalarArray(Return, Result) \
1660 JNI_ENTRY_CHECKED(Return, \
1661   checked_jni_New##Result##Array(JNIEnv *env, \
1662                                  jsize len)) \
1663     functionEnter(thr); \
1664     Return result = UNCHECKED()->New##Result##Array(env,len); \
1665     functionExit(thr); \
1666     return (Return) result; \
1667 JNI_END
1668 
1669 WRAPPER_NewScalarArray(jbooleanArray, Boolean)
1670 WRAPPER_NewScalarArray(jbyteArray, Byte)
1671 WRAPPER_NewScalarArray(jshortArray, Short)
1672 WRAPPER_NewScalarArray(jcharArray, Char)
1673 WRAPPER_NewScalarArray(jintArray, Int)
1674 WRAPPER_NewScalarArray(jlongArray, Long)
1675 WRAPPER_NewScalarArray(jfloatArray, Float)
1676 WRAPPER_NewScalarArray(jdoubleArray, Double)
1677 
1678 #define WRAPPER_GetScalarArrayElements(ElementTag,ElementType,Result) \
1679 JNI_ENTRY_CHECKED(ElementType *,  \
1680   checked_jni_Get##Result##ArrayElements(JNIEnv *env, \
1681                                          ElementType##Array array, \
1682                                          jboolean *isCopy)) \
1683     functionEnter(thr); \
1684     IN_VM( \
1685       check_primitive_array_type(thr, array, ElementTag); \
1686     ) \
1687     ElementType *result = UNCHECKED()->Get##Result##ArrayElements(env, \
1688                                                                   array, \
1689                                                                   isCopy); \
1690     if (result != NULL) { \
1691       result = (ElementType *) check_jni_wrap_copy_array(thr, array, result); \
1692     } \
1693     functionExit(thr); \
1694     return result; \
1695 JNI_END
1696 
1697 WRAPPER_GetScalarArrayElements(T_BOOLEAN, jboolean, Boolean)
1698 WRAPPER_GetScalarArrayElements(T_BYTE,    jbyte,    Byte)
1699 WRAPPER_GetScalarArrayElements(T_SHORT,   jshort,   Short)
1700 WRAPPER_GetScalarArrayElements(T_CHAR,    jchar,    Char)
1701 WRAPPER_GetScalarArrayElements(T_INT,     jint,     Int)
1702 WRAPPER_GetScalarArrayElements(T_LONG,    jlong,    Long)
1703 WRAPPER_GetScalarArrayElements(T_FLOAT,   jfloat,   Float)
1704 WRAPPER_GetScalarArrayElements(T_DOUBLE,  jdouble,  Double)
1705 
1706 #define WRAPPER_ReleaseScalarArrayElements(ElementTag,ElementType,Result,Tag) \
1707 JNI_ENTRY_CHECKED(void,  \
1708   checked_jni_Release##Result##ArrayElements(JNIEnv *env, \
1709                                              ElementType##Array array, \
1710                                              ElementType *elems, \
1711                                              jint mode)) \
1712     functionEnterExceptionAllowed(thr); \
1713     IN_VM( \
1714       check_primitive_array_type(thr, array, ElementTag); \
1715       ASSERT_OOPS_ALLOWED; \
1716       typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
1717     ) \
1718     ElementType* orig_result = (ElementType *) check_wrapped_array_release( \
1719         thr, "checked_jni_Release"#Result"ArrayElements", array, elems, mode); \
1720     UNCHECKED()->Release##Result##ArrayElements(env, array, orig_result, mode); \
1721     functionExit(thr); \
1722 JNI_END
1723 
1724 WRAPPER_ReleaseScalarArrayElements(T_BOOLEAN,jboolean, Boolean, bool)
1725 WRAPPER_ReleaseScalarArrayElements(T_BYTE,   jbyte,    Byte,    byte)
1726 WRAPPER_ReleaseScalarArrayElements(T_SHORT,  jshort,   Short,   short)
1727 WRAPPER_ReleaseScalarArrayElements(T_CHAR,   jchar,    Char,    char)
1728 WRAPPER_ReleaseScalarArrayElements(T_INT,    jint,     Int,     int)
1729 WRAPPER_ReleaseScalarArrayElements(T_LONG,   jlong,    Long,    long)
1730 WRAPPER_ReleaseScalarArrayElements(T_FLOAT,  jfloat,   Float,   float)
1731 WRAPPER_ReleaseScalarArrayElements(T_DOUBLE, jdouble,  Double,  double)
1732 
1733 #define WRAPPER_GetScalarArrayRegion(ElementTag,ElementType,Result) \
1734 JNI_ENTRY_CHECKED(void,  \
1735   checked_jni_Get##Result##ArrayRegion(JNIEnv *env, \
1736                                        ElementType##Array array, \
1737                                        jsize start, \
1738                                        jsize len, \
1739                                        ElementType *buf)) \
1740     functionEnter(thr); \
1741     IN_VM( \
1742       check_primitive_array_type(thr, array, ElementTag); \
1743     ) \
1744     UNCHECKED()->Get##Result##ArrayRegion(env,array,start,len,buf); \
1745     functionExit(thr); \
1746 JNI_END
1747 
1748 WRAPPER_GetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean)
1749 WRAPPER_GetScalarArrayRegion(T_BYTE,    jbyte,    Byte)
1750 WRAPPER_GetScalarArrayRegion(T_SHORT,   jshort,   Short)
1751 WRAPPER_GetScalarArrayRegion(T_CHAR,    jchar,    Char)
1752 WRAPPER_GetScalarArrayRegion(T_INT,     jint,     Int)
1753 WRAPPER_GetScalarArrayRegion(T_LONG,    jlong,    Long)
1754 WRAPPER_GetScalarArrayRegion(T_FLOAT,   jfloat,   Float)
1755 WRAPPER_GetScalarArrayRegion(T_DOUBLE,  jdouble,  Double)
1756 
1757 #define WRAPPER_SetScalarArrayRegion(ElementTag,ElementType,Result) \
1758 JNI_ENTRY_CHECKED(void,  \
1759   checked_jni_Set##Result##ArrayRegion(JNIEnv *env, \
1760                                        ElementType##Array array, \
1761                                        jsize start, \
1762                                        jsize len, \
1763                                        const ElementType *buf)) \
1764     functionEnter(thr); \
1765     IN_VM( \
1766       check_primitive_array_type(thr, array, ElementTag); \
1767     ) \
1768     UNCHECKED()->Set##Result##ArrayRegion(env,array,start,len,buf); \
1769     functionExit(thr); \
1770 JNI_END
1771 
1772 WRAPPER_SetScalarArrayRegion(T_BOOLEAN, jboolean, Boolean)
1773 WRAPPER_SetScalarArrayRegion(T_BYTE,    jbyte,    Byte)
1774 WRAPPER_SetScalarArrayRegion(T_SHORT,   jshort,   Short)
1775 WRAPPER_SetScalarArrayRegion(T_CHAR,    jchar,    Char)
1776 WRAPPER_SetScalarArrayRegion(T_INT,     jint,     Int)
1777 WRAPPER_SetScalarArrayRegion(T_LONG,    jlong,    Long)
1778 WRAPPER_SetScalarArrayRegion(T_FLOAT,   jfloat,   Float)
1779 WRAPPER_SetScalarArrayRegion(T_DOUBLE,  jdouble,  Double)
1780 
1781 JNI_ENTRY_CHECKED(jint,
1782   checked_jni_RegisterNatives(JNIEnv *env,
1783                               jclass clazz,
1784                               const JNINativeMethod *methods,
1785                               jint nMethods))
1786     functionEnter(thr);
1787     jint result = UNCHECKED()->RegisterNatives(env,clazz,methods,nMethods);
1788     functionExit(thr);
1789     return result;
1790 JNI_END
1791 
1792 JNI_ENTRY_CHECKED(jint,
1793   checked_jni_UnregisterNatives(JNIEnv *env,
1794                                 jclass clazz))
1795     functionEnter(thr);
1796     jint result = UNCHECKED()->UnregisterNatives(env,clazz);
1797     functionExit(thr);
1798     return result;
1799 JNI_END
1800 
1801 JNI_ENTRY_CHECKED(jint,
1802   checked_jni_MonitorEnter(JNIEnv *env,
1803                            jobject obj))
1804     functionEnter(thr);
1805     IN_VM(
1806       jniCheck::validate_object(thr, obj);
1807     )
1808     jint result = UNCHECKED()->MonitorEnter(env,obj);
1809     functionExit(thr);
1810     return result;
1811 JNI_END
1812 
1813 JNI_ENTRY_CHECKED(jint,
1814   checked_jni_MonitorExit(JNIEnv *env,
1815                           jobject obj))
1816     functionEnterExceptionAllowed(thr);
1817     IN_VM(
1818       jniCheck::validate_object(thr, obj);
1819     )
1820     jint result = UNCHECKED()->MonitorExit(env,obj);
1821     functionExit(thr);
1822     return result;
1823 JNI_END
1824 
1825 JNI_ENTRY_CHECKED(jint,
1826   checked_jni_GetJavaVM(JNIEnv *env,
1827                         JavaVM **vm))
1828     functionEnter(thr);
1829     jint result = UNCHECKED()->GetJavaVM(env,vm);
1830     functionExit(thr);
1831     return result;
1832 JNI_END
1833 
1834 JNI_ENTRY_CHECKED(void,
1835   checked_jni_GetStringRegion(JNIEnv *env,
1836                               jstring str,
1837                               jsize start,
1838                               jsize len,
1839                               jchar *buf))
1840     functionEnter(thr);
1841     IN_VM(
1842       checkString(thr, str);
1843     )
1844     UNCHECKED()->GetStringRegion(env, str, start, len, buf);
1845     functionExit(thr);
1846 JNI_END
1847 
1848 JNI_ENTRY_CHECKED(void,
1849   checked_jni_GetStringUTFRegion(JNIEnv *env,
1850                                  jstring str,
1851                                  jsize start,
1852                                  jsize len,
1853                                  char *buf))
1854     functionEnter(thr);
1855     IN_VM(
1856       checkString(thr, str);
1857     )
1858     UNCHECKED()->GetStringUTFRegion(env, str, start, len, buf);
1859     functionExit(thr);
1860 JNI_END
1861 
1862 JNI_ENTRY_CHECKED(void *,
1863   checked_jni_GetPrimitiveArrayCritical(JNIEnv *env,
1864                                         jarray array,
1865                                         jboolean *isCopy))
1866     functionEnterCritical(thr);
1867     IN_VM(
1868       check_is_primitive_array(thr, array);
1869     )
1870     void *result = UNCHECKED()->GetPrimitiveArrayCritical(env, array, isCopy);
1871     if (result != NULL) {
1872       result = check_jni_wrap_copy_array(thr, array, result);
1873     }
1874     functionExit(thr);
1875     return result;
1876 JNI_END
1877 
1878 JNI_ENTRY_CHECKED(void,
1879   checked_jni_ReleasePrimitiveArrayCritical(JNIEnv *env,
1880                                             jarray array,
1881                                             void *carray,
1882                                             jint mode))
1883     functionEnterCriticalExceptionAllowed(thr);
1884     IN_VM(
1885       check_is_primitive_array(thr, array);
1886     )
1887     // Check the element array...
1888     void* orig_result = check_wrapped_array_release(thr, "ReleasePrimitiveArrayCritical", array, carray, mode);
1889     UNCHECKED()->ReleasePrimitiveArrayCritical(env, array, orig_result, mode);
1890     functionExit(thr);
1891 JNI_END
1892 
1893 JNI_ENTRY_CHECKED(const jchar*,
1894   checked_jni_GetStringCritical(JNIEnv *env,
1895                                 jstring string,
1896                                 jboolean *isCopy))
1897     functionEnterCritical(thr);
1898     IN_VM(
1899       checkString(thr, string);
1900     )
1901     const jchar *result = UNCHECKED()->GetStringCritical(env, string, isCopy);
1902     functionExit(thr);
1903     return result;
1904 JNI_END
1905 
1906 JNI_ENTRY_CHECKED(void,
1907   checked_jni_ReleaseStringCritical(JNIEnv *env,
1908                                     jstring str,
1909                                     const jchar *chars))
1910     functionEnterCriticalExceptionAllowed(thr);
1911     IN_VM(
1912       checkString(thr, str);
1913     )
1914     /* The Hotspot JNI code does not use the parameters, so just check the
1915      * string parameter as a minor sanity check
1916      */
1917     UNCHECKED()->ReleaseStringCritical(env, str, chars);
1918     functionExit(thr);
1919 JNI_END
1920 
1921 JNI_ENTRY_CHECKED(jweak,
1922   checked_jni_NewWeakGlobalRef(JNIEnv *env,
1923                                jobject obj))
1924     functionEnter(thr);
1925     IN_VM(
1926       if (obj != NULL) {
1927         jniCheck::validate_handle(thr, obj);
1928       }
1929     )
1930     jweak result = UNCHECKED()->NewWeakGlobalRef(env, obj);
1931     functionExit(thr);
1932     return result;
1933 JNI_END
1934 
1935 JNI_ENTRY_CHECKED(void,
1936   checked_jni_DeleteWeakGlobalRef(JNIEnv *env,
1937                                   jweak ref))
1938     functionEnterExceptionAllowed(thr);
1939     UNCHECKED()->DeleteWeakGlobalRef(env, ref);
1940     functionExit(thr);
1941 JNI_END
1942 
1943 JNI_ENTRY_CHECKED(jboolean,
1944   checked_jni_ExceptionCheck(JNIEnv *env))
1945     thr->clear_pending_jni_exception_check();
1946     functionEnterExceptionAllowed(thr);
1947     jboolean result = UNCHECKED()->ExceptionCheck(env);
1948     functionExit(thr);
1949     return result;
1950 JNI_END
1951 
1952 JNI_ENTRY_CHECKED(jobject,
1953   checked_jni_NewDirectByteBuffer(JNIEnv *env,
1954                                   void *address,
1955                                   jlong capacity))
1956     functionEnter(thr);
1957     jobject result = UNCHECKED()->NewDirectByteBuffer(env, address, capacity);
1958     functionExit(thr);
1959     return result;
1960 JNI_END
1961 
1962 JNI_ENTRY_CHECKED(void *,
1963   checked_jni_GetDirectBufferAddress(JNIEnv *env,
1964                                      jobject buf))
1965     functionEnter(thr);
1966     void* result = UNCHECKED()->GetDirectBufferAddress(env, buf);
1967     functionExit(thr);
1968     return result;
1969 JNI_END
1970 
1971 JNI_ENTRY_CHECKED(jlong,
1972   checked_jni_GetDirectBufferCapacity(JNIEnv *env,
1973                                       jobject buf))
1974     functionEnter(thr);
1975     jlong result = UNCHECKED()->GetDirectBufferCapacity(env, buf);
1976     functionExit(thr);
1977     return result;
1978 JNI_END
1979 
1980 JNI_ENTRY_CHECKED(jobjectRefType,
1981   checked_jni_GetObjectRefType(JNIEnv *env,
1982                                jobject obj))
1983     functionEnter(thr);
1984     /* validate the object being passed */
1985     IN_VM(
1986       jniCheck::validate_object(thr, obj);
1987     )
1988     jobjectRefType result = UNCHECKED()->GetObjectRefType(env, obj);
1989     functionExit(thr);
1990     return result;
1991 JNI_END
1992 
1993 
1994 JNI_ENTRY_CHECKED(jint,
1995   checked_jni_GetVersion(JNIEnv *env))
1996     functionEnter(thr);
1997     jint result = UNCHECKED()->GetVersion(env);
1998     functionExit(thr);
1999     return result;
2000 JNI_END
2001 
2002 
2003 
2004 /*
2005  * Structure containing all checked jni functions
2006  */
2007 struct JNINativeInterface_  checked_jni_NativeInterface = {
2008     NULL,
2009     NULL,
2010     NULL,
2011 
2012     NULL,
2013 
2014     checked_jni_GetVersion,
2015 
2016     checked_jni_DefineClass,
2017     checked_jni_FindClass,
2018 
2019     checked_jni_FromReflectedMethod,
2020     checked_jni_FromReflectedField,
2021 
2022     checked_jni_ToReflectedMethod,
2023 
2024     checked_jni_GetSuperclass,
2025     checked_jni_IsAssignableFrom,
2026 
2027     checked_jni_ToReflectedField,
2028 
2029     checked_jni_Throw,
2030     checked_jni_ThrowNew,
2031     checked_jni_ExceptionOccurred,
2032     checked_jni_ExceptionDescribe,
2033     checked_jni_ExceptionClear,
2034     checked_jni_FatalError,
2035 
2036     checked_jni_PushLocalFrame,
2037     checked_jni_PopLocalFrame,
2038 
2039     checked_jni_NewGlobalRef,
2040     checked_jni_DeleteGlobalRef,
2041     checked_jni_DeleteLocalRef,
2042     checked_jni_IsSameObject,
2043 
2044     checked_jni_NewLocalRef,
2045     checked_jni_EnsureLocalCapacity,
2046 
2047     checked_jni_AllocObject,
2048     checked_jni_NewObject,
2049     checked_jni_NewObjectV,
2050     checked_jni_NewObjectA,
2051 
2052     checked_jni_GetObjectClass,
2053     checked_jni_IsInstanceOf,
2054 
2055     checked_jni_GetMethodID,
2056 
2057     checked_jni_CallObjectMethod,
2058     checked_jni_CallObjectMethodV,
2059     checked_jni_CallObjectMethodA,
2060     checked_jni_CallBooleanMethod,
2061     checked_jni_CallBooleanMethodV,
2062     checked_jni_CallBooleanMethodA,
2063     checked_jni_CallByteMethod,
2064     checked_jni_CallByteMethodV,
2065     checked_jni_CallByteMethodA,
2066     checked_jni_CallCharMethod,
2067     checked_jni_CallCharMethodV,
2068     checked_jni_CallCharMethodA,
2069     checked_jni_CallShortMethod,
2070     checked_jni_CallShortMethodV,
2071     checked_jni_CallShortMethodA,
2072     checked_jni_CallIntMethod,
2073     checked_jni_CallIntMethodV,
2074     checked_jni_CallIntMethodA,
2075     checked_jni_CallLongMethod,
2076     checked_jni_CallLongMethodV,
2077     checked_jni_CallLongMethodA,
2078     checked_jni_CallFloatMethod,
2079     checked_jni_CallFloatMethodV,
2080     checked_jni_CallFloatMethodA,
2081     checked_jni_CallDoubleMethod,
2082     checked_jni_CallDoubleMethodV,
2083     checked_jni_CallDoubleMethodA,
2084     checked_jni_CallVoidMethod,
2085     checked_jni_CallVoidMethodV,
2086     checked_jni_CallVoidMethodA,
2087 
2088     checked_jni_CallNonvirtualObjectMethod,
2089     checked_jni_CallNonvirtualObjectMethodV,
2090     checked_jni_CallNonvirtualObjectMethodA,
2091     checked_jni_CallNonvirtualBooleanMethod,
2092     checked_jni_CallNonvirtualBooleanMethodV,
2093     checked_jni_CallNonvirtualBooleanMethodA,
2094     checked_jni_CallNonvirtualByteMethod,
2095     checked_jni_CallNonvirtualByteMethodV,
2096     checked_jni_CallNonvirtualByteMethodA,
2097     checked_jni_CallNonvirtualCharMethod,
2098     checked_jni_CallNonvirtualCharMethodV,
2099     checked_jni_CallNonvirtualCharMethodA,
2100     checked_jni_CallNonvirtualShortMethod,
2101     checked_jni_CallNonvirtualShortMethodV,
2102     checked_jni_CallNonvirtualShortMethodA,
2103     checked_jni_CallNonvirtualIntMethod,
2104     checked_jni_CallNonvirtualIntMethodV,
2105     checked_jni_CallNonvirtualIntMethodA,
2106     checked_jni_CallNonvirtualLongMethod,
2107     checked_jni_CallNonvirtualLongMethodV,
2108     checked_jni_CallNonvirtualLongMethodA,
2109     checked_jni_CallNonvirtualFloatMethod,
2110     checked_jni_CallNonvirtualFloatMethodV,
2111     checked_jni_CallNonvirtualFloatMethodA,
2112     checked_jni_CallNonvirtualDoubleMethod,
2113     checked_jni_CallNonvirtualDoubleMethodV,
2114     checked_jni_CallNonvirtualDoubleMethodA,
2115     checked_jni_CallNonvirtualVoidMethod,
2116     checked_jni_CallNonvirtualVoidMethodV,
2117     checked_jni_CallNonvirtualVoidMethodA,
2118 
2119     checked_jni_GetFieldID,
2120 
2121     checked_jni_GetObjectField,
2122     checked_jni_GetBooleanField,
2123     checked_jni_GetByteField,
2124     checked_jni_GetCharField,
2125     checked_jni_GetShortField,
2126     checked_jni_GetIntField,
2127     checked_jni_GetLongField,
2128     checked_jni_GetFloatField,
2129     checked_jni_GetDoubleField,
2130 
2131     checked_jni_SetObjectField,
2132     checked_jni_SetBooleanField,
2133     checked_jni_SetByteField,
2134     checked_jni_SetCharField,
2135     checked_jni_SetShortField,
2136     checked_jni_SetIntField,
2137     checked_jni_SetLongField,
2138     checked_jni_SetFloatField,
2139     checked_jni_SetDoubleField,
2140 
2141     checked_jni_GetStaticMethodID,
2142 
2143     checked_jni_CallStaticObjectMethod,
2144     checked_jni_CallStaticObjectMethodV,
2145     checked_jni_CallStaticObjectMethodA,
2146     checked_jni_CallStaticBooleanMethod,
2147     checked_jni_CallStaticBooleanMethodV,
2148     checked_jni_CallStaticBooleanMethodA,
2149     checked_jni_CallStaticByteMethod,
2150     checked_jni_CallStaticByteMethodV,
2151     checked_jni_CallStaticByteMethodA,
2152     checked_jni_CallStaticCharMethod,
2153     checked_jni_CallStaticCharMethodV,
2154     checked_jni_CallStaticCharMethodA,
2155     checked_jni_CallStaticShortMethod,
2156     checked_jni_CallStaticShortMethodV,
2157     checked_jni_CallStaticShortMethodA,
2158     checked_jni_CallStaticIntMethod,
2159     checked_jni_CallStaticIntMethodV,
2160     checked_jni_CallStaticIntMethodA,
2161     checked_jni_CallStaticLongMethod,
2162     checked_jni_CallStaticLongMethodV,
2163     checked_jni_CallStaticLongMethodA,
2164     checked_jni_CallStaticFloatMethod,
2165     checked_jni_CallStaticFloatMethodV,
2166     checked_jni_CallStaticFloatMethodA,
2167     checked_jni_CallStaticDoubleMethod,
2168     checked_jni_CallStaticDoubleMethodV,
2169     checked_jni_CallStaticDoubleMethodA,
2170     checked_jni_CallStaticVoidMethod,
2171     checked_jni_CallStaticVoidMethodV,
2172     checked_jni_CallStaticVoidMethodA,
2173 
2174     checked_jni_GetStaticFieldID,
2175 
2176     checked_jni_GetStaticObjectField,
2177     checked_jni_GetStaticBooleanField,
2178     checked_jni_GetStaticByteField,
2179     checked_jni_GetStaticCharField,
2180     checked_jni_GetStaticShortField,
2181     checked_jni_GetStaticIntField,
2182     checked_jni_GetStaticLongField,
2183     checked_jni_GetStaticFloatField,
2184     checked_jni_GetStaticDoubleField,
2185 
2186     checked_jni_SetStaticObjectField,
2187     checked_jni_SetStaticBooleanField,
2188     checked_jni_SetStaticByteField,
2189     checked_jni_SetStaticCharField,
2190     checked_jni_SetStaticShortField,
2191     checked_jni_SetStaticIntField,
2192     checked_jni_SetStaticLongField,
2193     checked_jni_SetStaticFloatField,
2194     checked_jni_SetStaticDoubleField,
2195 
2196     checked_jni_NewString,
2197     checked_jni_GetStringLength,
2198     checked_jni_GetStringChars,
2199     checked_jni_ReleaseStringChars,
2200 
2201     checked_jni_NewStringUTF,
2202     checked_jni_GetStringUTFLength,
2203     checked_jni_GetStringUTFChars,
2204     checked_jni_ReleaseStringUTFChars,
2205 
2206     checked_jni_GetArrayLength,
2207 
2208     checked_jni_NewObjectArray,
2209     checked_jni_GetObjectArrayElement,
2210     checked_jni_SetObjectArrayElement,
2211 
2212     checked_jni_NewBooleanArray,
2213     checked_jni_NewByteArray,
2214     checked_jni_NewCharArray,
2215     checked_jni_NewShortArray,
2216     checked_jni_NewIntArray,
2217     checked_jni_NewLongArray,
2218     checked_jni_NewFloatArray,
2219     checked_jni_NewDoubleArray,
2220 
2221     checked_jni_GetBooleanArrayElements,
2222     checked_jni_GetByteArrayElements,
2223     checked_jni_GetCharArrayElements,
2224     checked_jni_GetShortArrayElements,
2225     checked_jni_GetIntArrayElements,
2226     checked_jni_GetLongArrayElements,
2227     checked_jni_GetFloatArrayElements,
2228     checked_jni_GetDoubleArrayElements,
2229 
2230     checked_jni_ReleaseBooleanArrayElements,
2231     checked_jni_ReleaseByteArrayElements,
2232     checked_jni_ReleaseCharArrayElements,
2233     checked_jni_ReleaseShortArrayElements,
2234     checked_jni_ReleaseIntArrayElements,
2235     checked_jni_ReleaseLongArrayElements,
2236     checked_jni_ReleaseFloatArrayElements,
2237     checked_jni_ReleaseDoubleArrayElements,
2238 
2239     checked_jni_GetBooleanArrayRegion,
2240     checked_jni_GetByteArrayRegion,
2241     checked_jni_GetCharArrayRegion,
2242     checked_jni_GetShortArrayRegion,
2243     checked_jni_GetIntArrayRegion,
2244     checked_jni_GetLongArrayRegion,
2245     checked_jni_GetFloatArrayRegion,
2246     checked_jni_GetDoubleArrayRegion,
2247 
2248     checked_jni_SetBooleanArrayRegion,
2249     checked_jni_SetByteArrayRegion,
2250     checked_jni_SetCharArrayRegion,
2251     checked_jni_SetShortArrayRegion,
2252     checked_jni_SetIntArrayRegion,
2253     checked_jni_SetLongArrayRegion,
2254     checked_jni_SetFloatArrayRegion,
2255     checked_jni_SetDoubleArrayRegion,
2256 
2257     checked_jni_RegisterNatives,
2258     checked_jni_UnregisterNatives,
2259 
2260     checked_jni_MonitorEnter,
2261     checked_jni_MonitorExit,
2262 
2263     checked_jni_GetJavaVM,
2264 
2265     checked_jni_GetStringRegion,
2266     checked_jni_GetStringUTFRegion,
2267 
2268     checked_jni_GetPrimitiveArrayCritical,
2269     checked_jni_ReleasePrimitiveArrayCritical,
2270 
2271     checked_jni_GetStringCritical,
2272     checked_jni_ReleaseStringCritical,
2273 
2274     checked_jni_NewWeakGlobalRef,
2275     checked_jni_DeleteWeakGlobalRef,
2276 
2277     checked_jni_ExceptionCheck,
2278 
2279     checked_jni_NewDirectByteBuffer,
2280     checked_jni_GetDirectBufferAddress,
2281     checked_jni_GetDirectBufferCapacity,
2282 
2283     // New 1.6 Features
2284 
2285     checked_jni_GetObjectRefType
2286 };
2287 
2288 
2289 // Returns the function structure
2290 struct JNINativeInterface_* jni_functions_check() {
2291 
2292   unchecked_jni_NativeInterface = jni_functions_nocheck();
2293 
2294   // make sure the last pointer in the checked table is not null, indicating
2295   // an addition to the JNINativeInterface_ structure without initializing
2296   // it in the checked table.
2297   debug_only(int *lastPtr = (int *)((char *)&checked_jni_NativeInterface + \
2298              sizeof(*unchecked_jni_NativeInterface) - sizeof(char *));)
2299   assert(*lastPtr != 0,
2300          "Mismatched JNINativeInterface tables, check for new entries");
2301 
2302   // with -verbose:jni this message will print
2303   if (PrintJNIResolving) {
2304     tty->print_cr("Checked JNI functions are being used to " \
2305                   "validate JNI usage");
2306   }
2307 
2308   return &checked_jni_NativeInterface;
2309 }