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